SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Serialization.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
7 
8 #ifndef swcdb_core_Serialization_h
9 #define swcdb_core_Serialization_h
10 
11 
12 #include "swcdb/core/Exception.h"
13 
14 
15 
16 namespace SWC {
17 
18 
24 namespace Serialization {
25 
26 
27 #define SWC_THROW_OVERRUN(_s_) \
28  SWC_THROWF(Error::SERIALIZATION_INPUT_OVERRUN, "Error decoding %s", _s_)
29 
30 #define SWC_THROW_UNPOSSIBLE(_s_) \
31  SWC_THROWF(Error::UNPOSSIBLE, "%s", _s_)
32 
33 
34 constexpr const uint64_t MAX_V1B = 0x7f;
35 constexpr const uint64_t MAX_V2B = 0x3fff;
36 constexpr const uint64_t MAX_V3B = 0x1fffff;
37 constexpr const uint64_t MAX_V4B = 0x0fffffff;
38 constexpr const uint64_t MAX_V5B = 0x07ffffffff;
39 constexpr const uint64_t MAX_V6B = 0x03ffffffffff;
40 constexpr const uint64_t MAX_V7B = 0x01ffffffffffff;
41 constexpr const uint64_t MAX_V8B = 0x00ffffffffffffff;
42 constexpr const uint64_t MAX_V9B = 0x7fffffffffffffff;
43 
44 constexpr const uint8_t MAX_LEN_VINT24 = 4;
45 constexpr const uint8_t MAX_LEN_VINT32 = 5;
46 constexpr const uint8_t MAX_LEN_VINT64 = 10;
47 
48 
49 extern SWC_CAN_INLINE
50 void memcopy(void* dest, const uint8_t** bufp, size_t len) noexcept {
51  memcpy(dest, *bufp, len);
52  *bufp += len;
53 
54  //for(auto ptr=static_cast<uint8_t*>(dest); len; --len, ++ptr, ++*bufp)
55  // *ptr = **bufp;
56 }
57 
58 extern SWC_CAN_INLINE
59 void memcopy(uint8_t** bufp, const void* src, size_t len) noexcept {
60  memcpy(*bufp, src, len);
61  *bufp += len;
62 
63  //for(auto ptr=static_cast<const uint8_t*>(src); len; --len, ++*bufp, ++ptr)
64  // **bufp = *ptr;
65 }
66 
67 extern constexpr SWC_CAN_INLINE
68 void decode_needed_one(size_t* remainp) {
69  if(!*remainp)
71  "Zero byte remain need 1 byte");
72  --*remainp;
73 }
74 
75 extern constexpr SWC_CAN_INLINE
76 void decode_needed(size_t* remainp, size_t len) {
77  if(*remainp < len)
79  "Need " SWC_FMT_LU " bytes but only " SWC_FMT_LU " remain",
80  len, *remainp);
81  *remainp -= len;
82 }
83 
84 extern constexpr SWC_CAN_INLINE
85 void encode_i8(uint8_t** bufp, uint8_t val) noexcept {
86  **bufp = val;
87  ++*bufp;
88 }
89 
90 extern constexpr SWC_CAN_INLINE
91 uint8_t decode_i8(const uint8_t** bufp, size_t* remainp) {
92  decode_needed_one(remainp);
93  return *(*bufp)++;
94 }
95 
96 extern constexpr SWC_CAN_INLINE
97 uint8_t decode_byte(const uint8_t** bufp, size_t* remainp) {
98  return decode_i8(bufp, remainp);
99 }
100 
101 extern constexpr SWC_CAN_INLINE
102 void encode_bool(uint8_t** bufp, bool bval) noexcept {
103  encode_i8(bufp, bval);
104 }
105 
106 extern constexpr SWC_CAN_INLINE
107 bool decode_bool(const uint8_t** bufp, size_t* remainp) {
108  return decode_i8(bufp, remainp);
109 }
110 
111 extern SWC_CAN_INLINE
112 void encode_i16(uint8_t** bufp , uint16_t val) noexcept {
113  memcopy(bufp, &val, 2);
114 }
115 
116 extern SWC_CAN_INLINE
117 uint16_t decode_i16(const uint8_t** bufp, size_t* remainp) {
118  decode_needed(remainp, 2);
119  uint16_t val;
120  memcopy(&val, bufp, 2);
121  return val;
122 }
123 
124 extern SWC_CAN_INLINE
125 void encode_i24(uint8_t** bufp , uint24_t val) noexcept {
126  memcopy(bufp, &val, 3);
127 }
128 
129 extern SWC_CAN_INLINE
130 uint24_t decode_i24(const uint8_t** bufp, size_t* remainp) {
131  decode_needed(remainp, 3);
132  uint24_t val;
133  memcopy(&val, bufp, 3);
134  return val;
135 }
136 
137 extern SWC_CAN_INLINE
138 void encode_i32(uint8_t** bufp, uint32_t val) noexcept {
139  memcopy(bufp, &val, 4);
140 }
141 
142 extern SWC_CAN_INLINE
143 uint32_t decode_i32(const uint8_t** bufp, size_t* remainp) {
144  decode_needed(remainp, 4);
145  uint32_t val;
146  memcopy(&val, bufp, 4);
147  return val;
148 }
149 
150 extern SWC_CAN_INLINE
151 void encode_i64(uint8_t** bufp, uint64_t val) noexcept {
152  memcopy(bufp, &val, 8);
153 }
154 
155 extern SWC_CAN_INLINE
156 uint64_t decode_i64(const uint8_t** bufp, size_t* remainp) {
157  decode_needed(remainp, 8);
158  uint64_t val;
159  memcopy(&val, bufp, 8);
160  return val;
161 }
162 
163 #define SWC_ENCODE_VI_0(_p_, _v_) \
164  if(_v_ <= MAX_V1B) { **_p_ = _v_; ++*_p_; return; }
165 
166 #define SWC_ENCODE_VI_1(_p_, _v_) \
167  **_p_ = _v_ | 0x80; ++*_p_; _v_ >>= 7; \
168  SWC_ENCODE_VI_0(_p_, _v_);
169 
170 #define SWC_ENCODE_VI(_p_, _v_, _shifts_) \
171  SWC_ENCODE_VI_0(_p_, _v_); \
172  for(uint8_t n=0; n < _shifts_; ++n) { SWC_ENCODE_VI_1(_p_, _v_); } \
173  SWC_THROW_UNPOSSIBLE("breached encoding length");
174 
175 
176 #define SWC_DECODE_NEED_BYTE(_r_) \
177  if(!*_r_) SWC_THROW(Error::SERIALIZATION_INPUT_OVERRUN, \
178  "Zero byte remain need 1 byte"); \
179  --*_r_;
180 
181 #define SWC_DECODE_VI_(_v_, _tmp_, _p_, _shift_) \
182  _v_ |= (_tmp_ = **_p_ & 0x7f) <<= _shift_; \
183  _tmp_ = **_p_ & 0x80; ++*_p_; if(!tmp) return _v_;
184 
185 #define SWC_DECODE_VI_1(_v_, _tmp_, _p_, _r_, _shift_) \
186  SWC_DECODE_NEED_BYTE(_r_); \
187  SWC_DECODE_VI_(_v_, _tmp_, _p_, _shift_);
188 
189 #define SWC_DECODE_VI(_t_, _p_, _r_, _bits_, _name_) \
190  _t_ n = 0; _t_ tmp; for(uint8_t shift=0; *_r_ ; shift+=7) { \
191  --*_r_; SWC_DECODE_VI_(n, tmp, _p_, shift); \
192  if(shift == _bits_) SWC_THROW_OVERRUN(_name_); \
193  } \
194  SWC_THROW(Error::SERIALIZATION_INPUT_OVERRUN, \
195  "Zero byte remain need 1 byte");
196 
197 
198 extern constexpr SWC_CAN_INLINE
199 uint8_t encoded_length_vi24(uint24_t val) noexcept {
200  return
201  (val <= MAX_V1B ? 1 :
202  (val <= MAX_V2B ? 2 :
203  (val <= MAX_V3B ? 3 : 4)));
204 }
205 
206 extern constexpr SWC_CAN_INLINE
207 void encode_vi24(uint8_t** bufp, uint24_t val) {
208  //SWC_ENCODE_VI(bufp, val, 3);
209  SWC_ENCODE_VI_0(bufp, val);
210  SWC_ENCODE_VI_1(bufp, val);
211  SWC_ENCODE_VI_1(bufp, val);
212  SWC_ENCODE_VI_1(bufp, val);
213  SWC_THROW_UNPOSSIBLE("breached encoding length");
214 }
215 
216 extern constexpr SWC_CAN_INLINE
217 uint24_t decode_vi24(const uint8_t** bufp, size_t* remainp) {
218  //SWC_DECODE_VI(uint24_t, bufp, remainp, 21, "vint24");
219  uint24_t n = 0; uint24_t tmp = 0;
220  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 0);
221  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 7);
222  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 14);
223  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 21);
224  SWC_THROW_OVERRUN("vint24");
225 }
226 extern constexpr SWC_CAN_INLINE
227 uint24_t decode_vi24(const uint8_t** bufp) {
228  size_t remain = 4;
229  return decode_vi24(bufp, &remain);
230 }
231 
232 
233 extern constexpr SWC_CAN_INLINE
234 uint8_t encoded_length_vi32(uint32_t val) noexcept {
235  return
236  (val <= MAX_V1B ? 1 :
237  (val <= MAX_V2B ? 2 :
238  (val <= MAX_V3B ? 3 :
239  (val <= MAX_V4B ? 4 : 5))));
240 }
241 
242 extern constexpr SWC_CAN_INLINE
243 void encode_vi32(uint8_t** bufp, uint32_t val) {
244  //SWC_ENCODE_VI(bufp, val, 4);
245  SWC_ENCODE_VI_0(bufp, val);
246  SWC_ENCODE_VI_1(bufp, val);
247  SWC_ENCODE_VI_1(bufp, val);
248  SWC_ENCODE_VI_1(bufp, val);
249  SWC_ENCODE_VI_1(bufp, val);
250  SWC_THROW_UNPOSSIBLE("breached encoding length");
251 }
252 
253 extern constexpr SWC_CAN_INLINE
254 uint32_t decode_vi32(const uint8_t** bufp, size_t* remainp) {
255  //SWC_DECODE_VI(uint32_t, bufp, remainp, 28, "vint32");
256  uint32_t n = 0; uint32_t tmp = 0;
257  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 0);
258  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 7);
259  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 14);
260  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 21);
261  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 28);
262  SWC_THROW_OVERRUN("vint32");
263 }
264 
265 extern constexpr SWC_CAN_INLINE
266 uint32_t decode_vi32(const uint8_t** bufp) {
267  size_t remain = 5;
268  return decode_vi32(bufp, &remain);
269 }
270 
271 extern constexpr SWC_CAN_INLINE
272 uint8_t encoded_length_vi64(uint64_t val) noexcept {
273  return
274  (val <= MAX_V1B ? 1 :
275  (val <= MAX_V2B ? 2 :
276  (val <= MAX_V3B ? 3 :
277  (val <= MAX_V4B ? 4 :
278  (val <= MAX_V5B ? 5 :
279  (val <= MAX_V6B ? 6 :
280  (val <= MAX_V7B ? 7 :
281  (val <= MAX_V8B ? 8 :
282  (val <= MAX_V9B ? 9 : 10)))))))));
283 }
284 
285 extern constexpr SWC_CAN_INLINE
286 void encode_vi64(uint8_t** bufp, uint64_t val) {
287  //SWC_ENCODE_VI(bufp, val, 9);
288  SWC_ENCODE_VI_0(bufp, val);
289  SWC_ENCODE_VI_1(bufp, val);
290  SWC_ENCODE_VI_1(bufp, val);
291  SWC_ENCODE_VI_1(bufp, val);
292  SWC_ENCODE_VI_1(bufp, val);
293  SWC_ENCODE_VI_1(bufp, val);
294  SWC_ENCODE_VI_1(bufp, val);
295  SWC_ENCODE_VI_1(bufp, val);
296  SWC_ENCODE_VI_1(bufp, val);
297  SWC_ENCODE_VI_1(bufp, val);
298  SWC_THROW_UNPOSSIBLE("breached encoding length");
299 }
300 
301 extern constexpr SWC_CAN_INLINE
302 uint64_t decode_vi64(const uint8_t** bufp, size_t* remainp) {
303  //SWC_DECODE_VI(uint64_t, bufp, remainp, 63, "vint64");
304  uint64_t n = 0; uint64_t tmp = 0;
305  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 0);
306  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 7);
307  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 14);
308  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 21);
309  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 28);
310  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 35);
311  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 42);
312  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 49);
313  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 56);
314  SWC_DECODE_VI_1(n, tmp, bufp, remainp, 63);
315  SWC_THROW_OVERRUN("vint64");
316 }
317 
318 extern constexpr SWC_CAN_INLINE
319 uint64_t decode_vi64(const uint8_t** bufp) {
320  size_t remain = 10;
321  return decode_vi64(bufp, &remain);
322 }
323 
324 
325 template<uint8_t BITS, uint8_t SZ, typename T>
326 extern SWC_CAN_INLINE
327 void encode_fixed_vi(uint8_t** bufp, T val) noexcept {
328  **bufp = SZ;
329  Core::BitFieldInt<T, BITS> _val = val;
330  memcpy(++*bufp, reinterpret_cast<const uint8_t*>(&_val), SZ);
331  *bufp += SZ;
332 }
333 
334 template<uint8_t BITS, uint8_t SZ, typename T>
335 extern SWC_CAN_INLINE
336 T decode_fixed_vi(const uint8_t** bufp) noexcept {
338  memcpy(reinterpret_cast<uint8_t*>(&val), *bufp, SZ);
339  *bufp += SZ;
340  return val;
341 }
342 
343 
344 extern constexpr SWC_CAN_INLINE
345 uint8_t encoded_length_fixed_vi24(uint24_t val) noexcept {
346  if(val <= 0xFB)
347  return 1;
348  if(val <= 0xFF)
349  return 2;
350  if(val <= 0xFFFF)
351  return 3;
352  return 4;
353 }
354 
355 extern SWC_CAN_INLINE
356 void encode_fixed_vi24(uint8_t** bufp, uint24_t val) noexcept {
357  if(val <= 0xFB)
358  return encode_i8(bufp, val + 4);
359  if(val <= 0xFF)
360  return encode_fixed_vi<8, 1, uint32_t>(bufp, val);
361  if(val <= 0xFFFF)
362  return encode_fixed_vi<16, 2, uint32_t>(bufp, val);
363  return encode_fixed_vi<24, 3, uint32_t>(bufp, val);
364 }
365 
366 extern SWC_CAN_INLINE
367 uint24_t decode_fixed_vi24(const uint8_t** bufp, size_t* remainp) {
368  uint8_t b = decode_i8(bufp, remainp);
369  if(b > 3)
370  return b - 4;
371  decode_needed(remainp, b);
372  switch(b) {
373  case 1:
374  return decode_fixed_vi<8, 1, uint32_t>(bufp);
375  case 2:
376  return decode_fixed_vi<16, 2, uint32_t>(bufp);
377  default:
378  return decode_fixed_vi<24, 3, uint32_t>(bufp);
379  }
380 }
381 
382 extern SWC_CAN_INLINE
383 uint24_t decode_fixed_vi24(const uint8_t** bufp) {
384  size_t remain = 4;
385  return decode_fixed_vi24(bufp, &remain);
386 }
387 
388 
389 extern constexpr SWC_CAN_INLINE
390 uint8_t encoded_length_fixed_vi32(uint32_t val) noexcept {
391  if(val <= 0xFA)
392  return 1;
393  if(val <= 0xFF)
394  return 2;
395  if(val <= 0xFFFF)
396  return 3;
397  if(val <= 0xFFFFFF)
398  return 4;
399  return 5;
400 }
401 
402 extern SWC_CAN_INLINE
403 void encode_fixed_vi32(uint8_t** bufp, uint32_t val) noexcept {
404  if(val <= 0xFA)
405  return encode_i8(bufp, val + 5);
406  if(val <= 0xFF)
407  return encode_fixed_vi<8, 1, uint32_t>(bufp, val);
408  if(val <= 0xFFFF)
409  return encode_fixed_vi<16, 2, uint32_t>(bufp, val);
410  if(val <= 0xFFFFFF)
411  return encode_fixed_vi<24, 3, uint32_t>(bufp, val);
412  return encode_fixed_vi<32, 4, uint32_t>(bufp, val);
413 }
414 
415 extern SWC_CAN_INLINE
416 uint32_t decode_fixed_vi32(const uint8_t** bufp, size_t* remainp) {
417  uint8_t b = decode_i8(bufp, remainp);
418  if(b > 4)
419  return b - 5;
420  decode_needed(remainp, b);
421  switch(b) {
422  case 1:
423  return decode_fixed_vi<8, 1, uint32_t>(bufp);
424  case 2:
425  return decode_fixed_vi<16, 2, uint32_t>(bufp);
426  case 3:
427  return decode_fixed_vi<24, 3, uint32_t>(bufp);
428  default:
429  return decode_fixed_vi<32, 4, uint32_t>(bufp);
430  }
431 }
432 
433 extern SWC_CAN_INLINE
434 uint32_t decode_fixed_vi32(const uint8_t** bufp) {
435  size_t remain = 5;
436  return decode_fixed_vi32(bufp, &remain);
437 }
438 
439 
440 extern constexpr SWC_CAN_INLINE
441 uint8_t encoded_length_fixed_vi64(uint64_t val) noexcept {
442  if(val <= 0xF6)
443  return 1;
444  if(val <= 0xFF)
445  return 2;
446  if(val <= 0xFFFF)
447  return 3;
448  if(val <= 0xFFFFFF)
449  return 4;
450  if(val <= 0xFFFFFFFF)
451  return 5;
452  if(val <= 0xFFFFFFFFFF)
453  return 6;
454  if(val <= 0xFFFFFFFFFFFF)
455  return 7;
456  if(val <= 0xFFFFFFFFFFFFFF)
457  return 8;
458  return 9;
459 }
460 
461 extern SWC_CAN_INLINE
462 void encode_fixed_vi64(uint8_t** bufp, uint64_t val) noexcept {
463  if(val <= 0xF6)
464  return encode_i8(bufp, val + 9);
465  if(val <= 0xFF)
466  return encode_fixed_vi<8, 1, uint64_t>(bufp, val);
467  if(val <= 0xFFFF)
468  return encode_fixed_vi<16, 2, uint64_t>(bufp, val);
469  if(val <= 0xFFFFFF)
470  return encode_fixed_vi<24, 3, uint64_t>(bufp, val);
471  if(val <= 0xFFFFFFFF)
472  return encode_fixed_vi<32, 4, uint64_t>(bufp, val);
473  if(val < 0xFFFFFFFFFF)
474  return encode_fixed_vi<40, 5, uint64_t>(bufp, val);
475  if(val < 0xFFFFFFFFFFFF)
476  return encode_fixed_vi<48, 6, uint64_t>(bufp, val);
477  if(val < 0xFFFFFFFFFFFFFF)
478  return encode_fixed_vi<56, 7, uint64_t>(bufp, val);
479  return encode_fixed_vi<64, 8, uint64_t>(bufp, val);
480 }
481 
482 extern SWC_CAN_INLINE
483 uint64_t decode_fixed_vi64(const uint8_t** bufp, size_t* remainp) {
484  uint8_t b = decode_i8(bufp, remainp);
485  if(b > 8)
486  return b - 9;
487  decode_needed(remainp, b);
488  switch(b) {
489  case 1:
490  return decode_fixed_vi<8, 1, uint64_t>(bufp);
491  case 2:
492  return decode_fixed_vi<16, 2, uint64_t>(bufp);
493  case 3:
494  return decode_fixed_vi<24, 3, uint64_t>(bufp);
495  case 4:
496  return decode_fixed_vi<32, 4, uint64_t>(bufp);
497  case 5:
498  return decode_fixed_vi<40, 5, uint64_t>(bufp);
499  case 6:
500  return decode_fixed_vi<48, 6, uint64_t>(bufp);
501  case 7:
502  return decode_fixed_vi<56, 7, uint64_t>(bufp);
503  default:
504  return decode_fixed_vi<64, 8, uint64_t>(bufp);
505  }
506 }
507 
508 extern SWC_CAN_INLINE
509 uint64_t decode_fixed_vi64(const uint8_t** bufp) {
510  size_t remain = 9;
511  return decode_fixed_vi64(bufp, &remain);
512 }
513 
514 
515 
516 extern constexpr SWC_CAN_INLINE
517 uint8_t encoded_length_double() noexcept {
518  return sizeof(long double);
519 }
520 
521 extern SWC_CAN_INLINE
522 void encode_double(uint8_t** bufp, long double val) noexcept {
523  memcopy(bufp, &val, encoded_length_double());
524 }
525 
526 extern SWC_CAN_INLINE
527 long double decode_double(const uint8_t** bufp, size_t* remainp) {
528  decode_needed(remainp, sizeof(long double));
529  long double v;
530  memcopy(&v, bufp, encoded_length_double());
531  return v;
532 }
533 
534 
535 
536 extern constexpr SWC_CAN_INLINE
537 size_t encoded_length_bytes(size_t len) noexcept {
538  return encoded_length_vi64(len) + len;
539 }
540 
541 extern SWC_CAN_INLINE
542 void encode_bytes(uint8_t** bufp, const void* data, size_t len) {
543  encode_vi64(bufp, len);
544  memcopy(bufp, data, len);
545 }
546 
547 extern constexpr SWC_CAN_INLINE
548 const uint8_t* decode_bytes(const uint8_t** bufp, size_t* remainp,
549  size_t* lenp) {
550  *lenp = decode_vi64(bufp, remainp);
551  decode_needed(remainp, *lenp);
552  const uint8_t* out = *bufp;
553  *bufp += *lenp;
554  return out;
555 }
556 
557 extern SWC_CAN_INLINE
558 std::string decode_bytes_string(const uint8_t** bufp, size_t* remainp) {
559  size_t len;
560  const char* s = reinterpret_cast<const char*>(
561  decode_bytes(bufp, remainp, &len));
562  return std::string(s, len);
563 }
564 
565 
566 
567 extern SWC_CAN_INLINE
568 void encode_bytes_fixed(uint8_t** bufp, const void* data,
569  uint32_t len) noexcept {
570  memcopy(bufp, data, len);
571 }
572 
573 extern constexpr SWC_CAN_INLINE
574 const uint8_t* decode_bytes_fixed(const uint8_t** bufp, size_t* remainp,
575  uint32_t len) {
576  decode_needed(remainp, len);
577  const uint8_t* out = *bufp;
578  *bufp += len;
579  return out;
580 }
581 
582 
583 
584 }}
585 
586 #endif // swcdb_core_Serialization_h
SWC::Serialization::encode_vi24
constexpr SWC_CAN_INLINE void encode_vi24(uint8_t **bufp, uint24_t val)
Definition: Serialization.h:207
SWC::Serialization::decode_fixed_vi32
SWC_CAN_INLINE uint32_t decode_fixed_vi32(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:416
SWC::Serialization::encoded_length_double
constexpr SWC_CAN_INLINE uint8_t encoded_length_double() noexcept
Definition: Serialization.h:517
SWC::Serialization::encoded_length_vi24
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi24(uint24_t val) noexcept
Definition: Serialization.h:199
SWC::Serialization::encode_i64
SWC_CAN_INLINE void encode_i64(uint8_t **bufp, uint64_t val) noexcept
Definition: Serialization.h:151
SWC::Serialization::encoded_length_bytes
constexpr SWC_CAN_INLINE size_t encoded_length_bytes(size_t len) noexcept
Definition: Serialization.h:537
data
T data
Definition: BitFieldInt.h:1
SWC::Serialization::decode_i24
SWC_CAN_INLINE uint24_t decode_i24(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:130
SWC::Serialization::decode_bytes
constexpr SWC_CAN_INLINE const uint8_t * decode_bytes(const uint8_t **bufp, size_t *remainp, size_t *lenp)
Definition: Serialization.h:548
SWC::Serialization::encoded_length_vi32
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi32(uint32_t val) noexcept
Definition: Serialization.h:234
SWC_THROW
#define SWC_THROW(_code_, _msg_)
Definition: Exception.h:134
SWC::Serialization::encode_i32
SWC_CAN_INLINE void encode_i32(uint8_t **bufp, uint32_t val) noexcept
Definition: Serialization.h:138
SWC::Serialization::encode_fixed_vi24
SWC_CAN_INLINE void encode_fixed_vi24(uint8_t **bufp, uint24_t val) noexcept
Definition: Serialization.h:356
SWC::Serialization::encode_double
SWC_CAN_INLINE void encode_double(uint8_t **bufp, long double val) noexcept
Definition: Serialization.h:522
SWC::Serialization::encode_fixed_vi
SWC_CAN_INLINE void encode_fixed_vi(uint8_t **bufp, T val) noexcept
Definition: Serialization.h:327
SWC::Serialization::memcopy
SWC_CAN_INLINE void memcopy(void *dest, const uint8_t **bufp, size_t len) noexcept
Definition: Serialization.h:50
SWC::Serialization::decode_fixed_vi
SWC_CAN_INLINE T decode_fixed_vi(const uint8_t **bufp) noexcept
Definition: Serialization.h:336
SWC::Serialization::MAX_V2B
constexpr const uint64_t MAX_V2B
Definition: Serialization.h:35
SWC::Serialization::encode_i16
SWC_CAN_INLINE void encode_i16(uint8_t **bufp, uint16_t val) noexcept
Definition: Serialization.h:112
SWC::Error::SERIALIZATION_INPUT_OVERRUN
@ SERIALIZATION_INPUT_OVERRUN
Definition: Error.h:61
SWC::Serialization::decode_fixed_vi64
SWC_CAN_INLINE uint64_t decode_fixed_vi64(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:483
SWC::Serialization::encode_i8
constexpr SWC_CAN_INLINE void encode_i8(uint8_t **bufp, uint8_t val) noexcept
Definition: Serialization.h:85
SWC::Serialization::encode_bytes
SWC_CAN_INLINE void encode_bytes(uint8_t **bufp, const void *data, size_t len)
Definition: Serialization.h:542
SWC::Serialization::encode_bool
constexpr SWC_CAN_INLINE void encode_bool(uint8_t **bufp, bool bval) noexcept
Definition: Serialization.h:102
SWC::Serialization::MAX_V4B
constexpr const uint64_t MAX_V4B
Definition: Serialization.h:37
SWC::Core::BitFieldInt
Definition: BitFieldInt.h:14
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Serialization::encode_bytes_fixed
SWC_CAN_INLINE void encode_bytes_fixed(uint8_t **bufp, const void *data, uint32_t len) noexcept
Definition: Serialization.h:568
SWC::Serialization::encoded_length_fixed_vi24
constexpr SWC_CAN_INLINE uint8_t encoded_length_fixed_vi24(uint24_t val) noexcept
Definition: Serialization.h:345
SWC::Serialization::MAX_LEN_VINT24
constexpr const uint8_t MAX_LEN_VINT24
Definition: Serialization.h:44
Exception.h
SWC::Serialization::decode_i16
SWC_CAN_INLINE uint16_t decode_i16(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:117
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Serialization::decode_vi24
constexpr SWC_CAN_INLINE uint24_t decode_vi24(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:217
SWC_ENCODE_VI_1
#define SWC_ENCODE_VI_1(_p_, _v_)
Definition: Serialization.h:166
SWC::Serialization::decode_fixed_vi24
SWC_CAN_INLINE uint24_t decode_fixed_vi24(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:367
SWC::Serialization::decode_byte
constexpr SWC_CAN_INLINE uint8_t decode_byte(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:97
SWC::Serialization::decode_bool
constexpr SWC_CAN_INLINE bool decode_bool(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:107
SWC_ENCODE_VI_0
#define SWC_ENCODE_VI_0(_p_, _v_)
Definition: Serialization.h:163
SWC_THROWF
#define SWC_THROWF(_code_, _fmt_,...)
Definition: Exception.h:136
SWC::Serialization::decode_needed
constexpr SWC_CAN_INLINE void decode_needed(size_t *remainp, size_t len)
Definition: Serialization.h:76
SWC::Serialization::encode_i24
SWC_CAN_INLINE void encode_i24(uint8_t **bufp, uint24_t val) noexcept
Definition: Serialization.h:125
SWC::Serialization::encode_fixed_vi64
SWC_CAN_INLINE void encode_fixed_vi64(uint8_t **bufp, uint64_t val) noexcept
Definition: Serialization.h:462
SWC::Serialization::encoded_length_vi64
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi64(uint64_t val) noexcept
Definition: Serialization.h:272
SWC::Serialization::decode_needed_one
constexpr SWC_CAN_INLINE void decode_needed_one(size_t *remainp)
Definition: Serialization.h:68
SWC_THROW_UNPOSSIBLE
#define SWC_THROW_UNPOSSIBLE(_s_)
Definition: Serialization.h:30
SWC_FMT_LU
#define SWC_FMT_LU
Definition: Compat.h:98
SWC::Serialization::encoded_length_fixed_vi32
constexpr SWC_CAN_INLINE uint8_t encoded_length_fixed_vi32(uint32_t val) noexcept
Definition: Serialization.h:390
SWC::Serialization::MAX_V8B
constexpr const uint64_t MAX_V8B
Definition: Serialization.h:41
SWC_THROW_OVERRUN
#define SWC_THROW_OVERRUN(_s_)
Definition: Serialization.h:27
SWC::Serialization::MAX_LEN_VINT32
constexpr const uint8_t MAX_LEN_VINT32
Definition: Serialization.h:45
SWC::uint24_t
Core::uint24_t uint24_t
Definition: BitFieldInt.h:401
SWC::Config::T
const uint64_t T
Definition: Property.h:27
SWC::Serialization::decode_bytes_string
SWC_CAN_INLINE std::string decode_bytes_string(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:558
SWC::Serialization::MAX_V5B
constexpr const uint64_t MAX_V5B
Definition: Serialization.h:38
SWC::Serialization::MAX_V9B
constexpr const uint64_t MAX_V9B
Definition: Serialization.h:42
SWC_DECODE_VI_1
#define SWC_DECODE_VI_1(_v_, _tmp_, _p_, _r_, _shift_)
Definition: Serialization.h:185
SWC::Serialization::decode_vi64
constexpr SWC_CAN_INLINE uint64_t decode_vi64(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:302
SWC::Serialization::encoded_length_fixed_vi64
constexpr SWC_CAN_INLINE uint8_t encoded_length_fixed_vi64(uint64_t val) noexcept
Definition: Serialization.h:441
SWC::Serialization::encode_vi32
constexpr SWC_CAN_INLINE void encode_vi32(uint8_t **bufp, uint32_t val)
Definition: Serialization.h:243
SWC::Serialization::MAX_V3B
constexpr const uint64_t MAX_V3B
Definition: Serialization.h:36
SWC::Serialization::MAX_V6B
constexpr const uint64_t MAX_V6B
Definition: Serialization.h:39
SWC::Serialization::MAX_V7B
constexpr const uint64_t MAX_V7B
Definition: Serialization.h:40
SWC::Serialization::encode_vi64
constexpr SWC_CAN_INLINE void encode_vi64(uint8_t **bufp, uint64_t val)
Definition: Serialization.h:286
SWC::Serialization::MAX_V1B
constexpr const uint64_t MAX_V1B
Definition: Serialization.h:34
SWC::Serialization::decode_bytes_fixed
constexpr SWC_CAN_INLINE const uint8_t * decode_bytes_fixed(const uint8_t **bufp, size_t *remainp, uint32_t len)
Definition: Serialization.h:574
SWC::Serialization::encode_fixed_vi32
SWC_CAN_INLINE void encode_fixed_vi32(uint8_t **bufp, uint32_t val) noexcept
Definition: Serialization.h:403
SWC::Serialization::decode_double
SWC_CAN_INLINE long double decode_double(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:527
SWC::Serialization::MAX_LEN_VINT64
constexpr const uint8_t MAX_LEN_VINT64
Definition: Serialization.h:46
SWC::Serialization::decode_i8
constexpr SWC_CAN_INLINE uint8_t decode_i8(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:91
SWC::Serialization::decode_i64
SWC_CAN_INLINE uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:156
SWC::Serialization::decode_i32
SWC_CAN_INLINE uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:143
SWC::Serialization::decode_vi32
constexpr SWC_CAN_INLINE uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:254