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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#pragma once
#include <library/cpp/unified_agent_client/f_maybe.h>
#include <util/generic/deque.h>
#include <util/generic/string.h>
namespace NUnifiedAgent::NPW {
class TLengthDelimited;
class TFieldLink {
public:
TFieldLink(TLengthDelimited* container, bool repeated = false, size_t keySize = 1);
void SetValueSize(bool empty, size_t size);
private:
TLengthDelimited* Container;
int OuterSize;
bool Repeated;
size_t KeySize;
};
class TLengthDelimited {
public:
explicit TLengthDelimited(const TFMaybe<TFieldLink>& link = Nothing());
void IncSize(int sizeDelta);
size_t ByteSizeLong() const {
return static_cast<size_t>(ByteSize);
}
private:
TFMaybe<TFieldLink> Link;
int ByteSize;
};
using TMessage = TLengthDelimited;
template <typename T>
class TRepeatedField: public TLengthDelimited {
public:
static_assert(std::is_same_v<T, ui32> ||
std::is_same_v<T, ui64> ||
std::is_same_v<T, i64>,
"type is not supported");
using TLengthDelimited::TLengthDelimited;
void Add(T value);
};
template <typename T>
class TRepeatedPtrField {
public:
explicit TRepeatedPtrField(TMessage* message, size_t keySize = 1)
: Message(message)
, Children()
, KeySize(keySize)
{
}
size_t GetSize() const {
return Children.size();
}
T& Get(size_t index) {
return Children[index];
}
T& Add() {
if constexpr (std::is_constructible<T, TFieldLink>::value) {
Children.emplace_back(TFieldLink(Message, true, KeySize));
} else {
Children.emplace_back(Message);
}
return Children.back();
}
private:
TMessage* Message;
TDeque<T> Children;
size_t KeySize;
};
template <typename T>
class TNumberField {
public:
static_assert(std::is_same_v<T, ui32> ||
std::is_same_v<T, ui64> ||
std::is_same_v<T, i64>,
"type is not supported");
explicit TNumberField(const TFieldLink& link);
void SetValue(T value);
private:
TFieldLink Link;
};
template <typename T>
class TFixedNumberField {
public:
static_assert(std::is_same_v<T, ui32> ||
std::is_same_v<T, ui64> ||
std::is_same_v<T, i64>,
"type is not supported");
explicit TFixedNumberField(const TFieldLink& link);
void SetValue();
private:
TFieldLink Link;
};
class TStringField {
public:
explicit TStringField(const TFieldLink& link);
void SetValue(const TString& value);
private:
TFieldLink Link;
};
extern template class TNumberField<ui64>;
extern template class TNumberField<ui32>;
extern template class TNumberField<i64>;
extern template class TFixedNumberField<ui64>;
extern template class TFixedNumberField<ui32>;
extern template class TFixedNumberField<i64>;
extern template class TRepeatedField<ui64>;
extern template class TRepeatedField<ui32>;
extern template class TRepeatedField<i64>;
}
|