16 #ifndef THRILL_COMMON_ITEM_SERIALIZATION_TOOLS_HEADER 17 #define THRILL_COMMON_ITEM_SERIALIZATION_TOOLS_HEADER 30 template <
typename Writer>
36 Writer& w = *
static_cast<Writer*
>(
this);
39 w.PutByte(uint8_t(v));
41 else if (v < 128 * 128) {
42 w.PutByte(uint8_t(((v >> 0) & 0x7F) | 0x80));
43 w.PutByte(uint8_t((v >> 7) & 0x7F));
45 else if (v < 128 * 128 * 128) {
46 w.PutByte(uint8_t(((v >> 0) & 0x7F) | 0x80));
47 w.PutByte(uint8_t(((v >> 7) & 0x7F) | 0x80));
48 w.PutByte(uint8_t((v >> 14) & 0x7F));
50 else if (v < 128 * 128 * 128 * 128) {
51 w.PutByte(uint8_t(((v >> 0) & 0x7F) | 0x80));
52 w.PutByte(uint8_t(((v >> 7) & 0x7F) | 0x80));
53 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
54 w.PutByte(uint8_t((v >> 21) & 0x7F));
57 w.PutByte(uint8_t(((v >> 0) & 0x7F) | 0x80));
58 w.PutByte(uint8_t(((v >> 7) & 0x7F) | 0x80));
59 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
60 w.PutByte(uint8_t(((v >> 21) & 0x7F) | 0x80));
61 w.PutByte(uint8_t((v >> 28) & 0x7F));
69 Writer& w = *
static_cast<Writer*
>(
this);
72 w.PutByte(uint8_t(v));
74 else if (v < 128 * 128) {
75 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
76 w.PutByte(uint8_t((v >> 07) & 0x7F));
78 else if (v < 128 * 128 * 128) {
79 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
80 w.PutByte(uint8_t(((v >> 07) & 0x7F) | 0x80));
81 w.PutByte(uint8_t((v >> 14) & 0x7F));
83 else if (v < 128 * 128 * 128 * 128) {
84 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
85 w.PutByte(uint8_t(((v >> 07) & 0x7F) | 0x80));
86 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
87 w.PutByte(uint8_t((v >> 21) & 0x7F));
89 else if (v < 128llu * 128 * 128 * 128 * 128) {
90 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
91 w.PutByte(uint8_t(((v >> 07) & 0x7F) | 0x80));
92 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
93 w.PutByte(uint8_t(((v >> 21) & 0x7F) | 0x80));
94 w.PutByte(uint8_t((v >> 28) & 0x7F));
96 else if (v < 128llu * 128 * 128 * 128 * 128 * 128) {
97 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
98 w.PutByte(uint8_t(((v >> 07) & 0x7F) | 0x80));
99 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
100 w.PutByte(uint8_t(((v >> 21) & 0x7F) | 0x80));
101 w.PutByte(uint8_t(((v >> 28) & 0x7F) | 0x80));
102 w.PutByte(uint8_t((v >> 35) & 0x7F));
104 else if (v < 128llu * 128 * 128 * 128 * 128 * 128 * 128) {
105 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
106 w.PutByte(uint8_t(((v >> 07) & 0x7F) | 0x80));
107 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
108 w.PutByte(uint8_t(((v >> 21) & 0x7F) | 0x80));
109 w.PutByte(uint8_t(((v >> 28) & 0x7F) | 0x80));
110 w.PutByte(uint8_t(((v >> 35) & 0x7F) | 0x80));
111 w.PutByte(uint8_t((v >> 42) & 0x7F));
113 else if (v < 128llu * 128 * 128 * 128 * 128 * 128 * 128 * 128) {
114 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
115 w.PutByte(uint8_t(((v >> 07) & 0x7F) | 0x80));
116 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
117 w.PutByte(uint8_t(((v >> 21) & 0x7F) | 0x80));
118 w.PutByte(uint8_t(((v >> 28) & 0x7F) | 0x80));
119 w.PutByte(uint8_t(((v >> 35) & 0x7F) | 0x80));
120 w.PutByte(uint8_t(((v >> 42) & 0x7F) | 0x80));
121 w.PutByte(uint8_t((v >> 49) & 0x7F));
123 else if (v < 128llu * 128 * 128 * 128 * 128 * 128 * 128 * 128 * 128) {
124 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
125 w.PutByte(uint8_t(((v >> 07) & 0x7F) | 0x80));
126 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
127 w.PutByte(uint8_t(((v >> 21) & 0x7F) | 0x80));
128 w.PutByte(uint8_t(((v >> 28) & 0x7F) | 0x80));
129 w.PutByte(uint8_t(((v >> 35) & 0x7F) | 0x80));
130 w.PutByte(uint8_t(((v >> 42) & 0x7F) | 0x80));
131 w.PutByte(uint8_t(((v >> 49) & 0x7F) | 0x80));
132 w.PutByte(uint8_t((v >> 56) & 0x7F));
135 w.PutByte(uint8_t(((v >> 00) & 0x7F) | 0x80));
136 w.PutByte(uint8_t(((v >> 07) & 0x7F) | 0x80));
137 w.PutByte(uint8_t(((v >> 14) & 0x7F) | 0x80));
138 w.PutByte(uint8_t(((v >> 21) & 0x7F) | 0x80));
139 w.PutByte(uint8_t(((v >> 28) & 0x7F) | 0x80));
140 w.PutByte(uint8_t(((v >> 35) & 0x7F) | 0x80));
141 w.PutByte(uint8_t(((v >> 42) & 0x7F) | 0x80));
142 w.PutByte(uint8_t(((v >> 49) & 0x7F) | 0x80));
143 w.PutByte(uint8_t(((v >> 56) & 0x7F) | 0x80));
144 w.PutByte(uint8_t((v >> 63) & 0x7F));
162 return PutString(str.data(), str.size());
170 template <
typename Reader>
176 Reader& r = *
static_cast<Reader*
>(
this);
178 uint32_t u, v = r.GetByte();
179 if (!(v & 0x80))
return v;
181 u = r.GetByte(), v |= (u & 0x7F) << 7;
182 if (!(u & 0x80))
return v;
183 u = r.GetByte(), v |= (u & 0x7F) << 14;
184 if (!(u & 0x80))
return v;
185 u = r.GetByte(), v |= (u & 0x7F) << 21;
186 if (!(u & 0x80))
return v;
189 throw std::overflow_error(
"Overflow during varint decoding.");
190 v |= (u & 0x7F) << 28;
196 const Reader& r = *
static_cast<const Reader*
>(
this);
198 uint32_t u, v = r.PeekByte(0);
199 if (!(v & 0x80))
return v;
201 u = r.PeekByte(1), v |= (u & 0x7F) << 7;
202 if (!(u & 0x80))
return v;
203 u = r.PeekByte(2), v |= (u & 0x7F) << 14;
204 if (!(u & 0x80))
return v;
205 u = r.PeekByte(3), v |= (u & 0x7F) << 21;
206 if (!(u & 0x80))
return v;
209 throw std::overflow_error(
"Overflow during varint decoding.");
210 v |= (u & 0x7F) << 28;
216 Reader& r = *
static_cast<Reader*
>(
this);
218 uint64_t u, v = r.GetByte();
219 if (!(v & 0x80))
return v;
221 u = r.GetByte(), v |= (u & 0x7F) << 7;
222 if (!(u & 0x80))
return v;
223 u = r.GetByte(), v |= (u & 0x7F) << 14;
224 if (!(u & 0x80))
return v;
225 u = r.GetByte(), v |= (u & 0x7F) << 21;
226 if (!(u & 0x80))
return v;
227 u = r.GetByte(), v |= (u & 0x7F) << 28;
228 if (!(u & 0x80))
return v;
229 u = r.GetByte(), v |= (u & 0x7F) << 35;
230 if (!(u & 0x80))
return v;
231 u = r.GetByte(), v |= (u & 0x7F) << 42;
232 if (!(u & 0x80))
return v;
233 u = r.GetByte(), v |= (u & 0x7F) << 49;
234 if (!(u & 0x80))
return v;
235 u = r.GetByte(), v |= (u & 0x7F) << 56;
236 if (!(u & 0x80))
return v;
239 throw std::overflow_error(
"Overflow during varint64 decoding.");
240 v |= (u & 0x7F) << 63;
246 Reader& r = *
static_cast<Reader*
>(
this);
247 return r.Read(GetVarint());
254 #endif // !THRILL_COMMON_ITEM_SERIALIZATION_TOOLS_HEADER
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking