aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/error/error_attributes.cpp
blob: 2c1b54231463c733a30c24a534254fb0c9f59240 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "error_attributes.h"

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

TErrorAttributes::TErrorAttributes(void* attributes)
    : Attributes_(attributes)
{ }

void TErrorAttributes::Clear()
{
    for (const auto& key : ListKeys()) {
        Remove(key);
    }
}

NYson::TYsonString TErrorAttributes::GetYsonAndRemove(const TString& key)
{
    auto result = GetYson(key);
    Remove(key);
    return result;
}

bool TErrorAttributes::Contains(TStringBuf key) const
{
    return FindYson(key).operator bool();
}

bool operator == (const TErrorAttributes& lhs, const TErrorAttributes& rhs)
{
    auto lhsPairs = lhs.ListPairs();
    auto rhsPairs = rhs.ListPairs();
    if (lhsPairs.size() != rhsPairs.size()) {
        return false;
    }

    std::sort(lhsPairs.begin(), lhsPairs.end(), [] (const auto& lhs, const auto& rhs) {
        return lhs.first < rhs.first;
    });
    std::sort(rhsPairs.begin(), rhsPairs.end(), [] (const auto& lhs, const auto& rhs) {
        return lhs.first < rhs.first;
    });

    for (auto index = 0; index < std::ssize(lhsPairs); ++index) {
        if (lhsPairs[index].first != rhsPairs[index].first) {
            return false;
        }
    }

    for (auto index = 0; index < std::ssize(lhsPairs); ++index) {
        if (lhsPairs[index].second != rhsPairs[index].second) {
            return false;
        }
    }

    return true;
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT