0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Macros
serialization-c.h File Reference

Macros to serialize/deserialize primitives to/from a memory buffer. More...

#include "endian-c.h"
#include <cstdio>
Include dependency graph for serialization-c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HT_THROW_INPUT_OVERRUN(_s_)
 
#define HT_THROW_BAD_VSTR(_s_)
 
#define HT_THROW_BAD_VINT(_s_)
 
#define HT_THROW_UNPOSSIBLE(_s_)
 
#define HT_DECODE_NEED(_r_, _l_)
 
#define HT_ENCODE_BOOL(_op_, _v_)   *(_op_)++ = (_v_) ? 1 : 0
 
#define HT_ENCODE_I8(_op_, _v_)   *(_op_)++ = _v_
 
#define HT_DECODE_I8(_ip_, _r_, _v_)
 
#define HT_ENCODE_I16(_op_, _v_)
 
#define HT_DECODE_I16(_ip_, _r_, _v_)
 
#define HT_ENCODE_I32(_op_, _v_)
 
#define HT_DECODE_I32(_ip_, _r_, _v_)
 
#define HT_ENCODE_I64(_op_, _v_)
 
#define HT_DECODE_I64(_ip_, _r_, _v_)
 
#define HT_MAX_V1B   0x7f
 
#define HT_MAX_V2B   0x3fff
 
#define HT_MAX_V3B   0x1fffff
 
#define HT_MAX_V4B   0xfffffff
 
#define HT_MAX_V5B   0x7ffffffffull
 
#define HT_MAX_V6B   0x3ffffffffffull
 
#define HT_MAX_V7B   0x1ffffffffffffull
 
#define HT_MAX_V8B   0xffffffffffffffull
 
#define HT_MAX_V9B   0x7fffffffffffffffull
 
#define HT_MAX_LEN_VINT32   5
 
#define HT_MAX_LEN_VINT64   10
 
#define HT_ENCODED_LEN_VI32(_v_)
 
#define HT_ENCODED_LEN_VI64(_v_)
 
#define HT_ENCODE_VINT0(_op_, _v_, _done_)
 
#define HT_ENCODE_VINT_(_op_, _v_, _done_)
 
#define HT_ENCODE_VINT4(_op_, _v_, _done_)
 
#define HT_ENCODE_VI32(_op_, _v_, _done_)
 
#define HT_ENCODE_VI64(_op_, _v_, _done_)
 
#define HT_DECODE_VINT0(_type_, _v_, _ip_, _r_)
 
#define HT_DECODE_VINT_(_type_, _v_, _ip_, _r_, _done_)
 
#define HT_DECODE_VINT4(_type_, _v_, _ip_, _r_, _done_)
 
#define HT_DECODE_VI32(_ip_, _r_, _v_, _done_)
 
#define HT_DECODE_VI64(_ip_, _r_, _v_, _done_)
 
#define HT_ENCODE_BYTES32(_op_, _ip_, _len_)
 
#define HT_DECODE_BYTES32(_ip_, _r_, _out_, _len_)
 
#define HT_ENCODE_STR16(_op_, _s_, _len_)
 
#define HT_DECODE_STR16(_ip_, _r_, _s_, _len_)
 
#define HT_ENCODE_VSTR(_op_, _s_, _len_)
 
#define HT_DECODE_VSTR(_ip_, _r_, _out_, _len_)
 

Detailed Description

Macros to serialize/deserialize primitives to/from a memory buffer.

Do not use directly; use the functions from Common/Serialization.h instead.

Definition in file serialization-c.h.

Macro Definition Documentation

#define HT_DECODE_BYTES32 (   _ip_,
  _r_,
  _out_,
  _len_ 
)
Value:
do { \
uint32_t _tmp_; \
HT_DECODE_I32(_ip_, _r_, _tmp_); \
HT_DECODE_NEED(_r_, _tmp_); \
_out_ = (uint8_t *)(_ip_); \
_ip_ += _tmp_; \
_len_ = _tmp_; \
} while (0)
#define HT_DECODE_NEED(_r_, _l_)
#define HT_DECODE_I32(_ip_, _r_, _v_)

Definition at line 395 of file serialization-c.h.

#define HT_DECODE_I16 (   _ip_,
  _r_,
  _v_ 
)
Value:
do { \
HT_DECODE_NEED(_r_, 2); \
_v_ = *(_ip_)++; \
_v_ |= (*(_ip_)++ << 8); \
} while (0)
#define HT_DECODE_NEED(_r_, _l_)

Definition at line 145 of file serialization-c.h.

#define HT_DECODE_I32 (   _ip_,
  _r_,
  _v_ 
)
Value:
do { \
HT_DECODE_NEED(_r_, 4); \
_v_ = *(_ip_)++; \
_v_ |= (*(_ip_)++ << 8); \
_v_ |= (*(_ip_)++ << 16); \
_v_ |= (*(_ip_)++ << 24); \
} while (0)
#define HT_DECODE_NEED(_r_, _l_)

Definition at line 180 of file serialization-c.h.

#define HT_DECODE_I64 (   _ip_,
  _r_,
  _v_ 
)
Value:
do { \
HT_DECODE_NEED(_r_, 8); \
_v_ = *(_ip_)++; \
_v_ |= (*(_ip_)++ << 8); \
_v_ |= (*(_ip_)++ << 16); \
_v_ |= ((uint64_t)(*(_ip_)++) << 24); \
_v_ |= ((uint64_t)(*(_ip_)++) << 32); \
_v_ |= ((uint64_t)(*(_ip_)++) << 40); \
_v_ |= ((uint64_t)(*(_ip_)++) << 48); \
_v_ |= ((uint64_t)(*(_ip_)++) << 56); \
} while (0)
#define HT_DECODE_NEED(_r_, _l_)

Definition at line 221 of file serialization-c.h.

#define HT_DECODE_I8 (   _ip_,
  _r_,
  _v_ 
)
Value:
do { \
HT_DECODE_NEED(_r_, 1); \
_v_ = *(_ip_)++; \
} while (0)
#define HT_DECODE_NEED(_r_, _l_)

Definition at line 115 of file serialization-c.h.

#define HT_DECODE_NEED (   _r_,
  _l_ 
)
Value:
do { \
if (_r_ < _l_) \
_r_ -= _l_; \
} while (0)
#define HT_THROW_INPUT_OVERRUN(_s_)

Definition at line 94 of file serialization-c.h.

#define HT_DECODE_STR16 (   _ip_,
  _r_,
  _s_,
  _len_ 
)
Value:
do { \
HT_DECODE_I16(_ip_, _r_, _len_); \
_s_ = (char *)(_ip_); \
_r_ -= (size_t)(_len_) + 1; \
_ip_ += (size_t)(_len_) + 1; \
} while (0)
#define HT_DECODE_I16(_ip_, _r_, _v_)

Definition at line 429 of file serialization-c.h.

#define HT_DECODE_VI32 (   _ip_,
  _r_,
  _v_,
  _done_ 
)
Value:
do { \
HT_DECODE_VINT0(uint32_t, _v_, _ip_, _r_) \
HT_DECODE_VINT4(uint32_t, _v_, _ip_, _r_, _done_) \
HT_DECODE_VINT_(uint32_t, _v_, _ip_, _r_, _done_) \
HT_THROW_BAD_VINT("vint32"); \
} while (0)
#define HT_THROW_BAD_VINT(_s_)
#define HT_DECODE_VINT_(_type_, _v_, _ip_, _r_, _done_)
#define HT_DECODE_VINT4(_type_, _v_, _ip_, _r_, _done_)
#define HT_DECODE_VINT0(_type_, _v_, _ip_, _r_)

Definition at line 349 of file serialization-c.h.

#define HT_DECODE_VI64 (   _ip_,
  _r_,
  _v_,
  _done_ 
)
Value:
do { \
HT_DECODE_VINT0(uint64_t, _v_, _ip_, _r_) \
HT_DECODE_VINT4(uint64_t, _v_, _ip_, _r_, _done_) \
HT_DECODE_VINT4(uint64_t, _v_, _ip_, _r_, _done_) \
HT_DECODE_VINT_(uint64_t, _v_, _ip_, _r_, _done_) \
HT_DECODE_VINT_(uint64_t, _v_, _ip_, _r_, _done_) \
HT_THROW_BAD_VINT("vint64"); \
} while (0)
#define HT_THROW_BAD_VINT(_s_)
#define HT_DECODE_VINT_(_type_, _v_, _ip_, _r_, _done_)
#define HT_DECODE_VINT4(_type_, _v_, _ip_, _r_, _done_)
#define HT_DECODE_VINT0(_type_, _v_, _ip_, _r_)

Definition at line 364 of file serialization-c.h.

#define HT_DECODE_VINT0 (   _type_,
  _v_,
  _ip_,
  _r_ 
)
Value:
uint32_t _shift_ = 0; \
HT_DECODE_NEED(_r_, 1); \
_v_ = (*(_ip_)++ & 0x7f);
#define HT_DECODE_NEED(_r_, _l_)

Definition at line 323 of file serialization-c.h.

#define HT_DECODE_VINT4 (   _type_,
  _v_,
  _ip_,
  _r_,
  _done_ 
)
Value:
HT_DECODE_VINT_(_type_, _v_, _ip_, _r_, _done_) \
HT_DECODE_VINT_(_type_, _v_, _ip_, _r_, _done_) \
HT_DECODE_VINT_(_type_, _v_, _ip_, _r_, _done_) \
HT_DECODE_VINT_(_type_, _v_, _ip_, _r_, _done_)
#define HT_DECODE_VINT_(_type_, _v_, _ip_, _r_, _done_)

Definition at line 335 of file serialization-c.h.

#define HT_DECODE_VINT_ (   _type_,
  _v_,
  _ip_,
  _r_,
  _done_ 
)
Value:
_shift_ += 7; \
if ((_ip_)[-1] & 0x80) { \
HT_DECODE_NEED(_r_, 1); \
_v_ |= ((_type_)(*(_ip_)++ & 0x7f) << _shift_); \
} else _done_;
#define HT_DECODE_NEED(_r_, _l_)

Definition at line 328 of file serialization-c.h.

#define HT_DECODE_VSTR (   _ip_,
  _r_,
  _out_,
  _len_ 
)
Value:
do { \
uint64_t _tmp_; \
HT_DECODE_VI64(_ip_, _r_, _tmp_, break); \
if (_tmp_ > (uint64_t)(SIZE_MAX)) \
HT_THROW_BAD_VSTR("long vstr on 32-bit platform"); \
_out_ = (char *)(_ip_); \
_len_ = _tmp_++; \
HT_DECODE_NEED(_r_, _tmp_); \
_ip_ += _tmp_; \
if ((_ip_)[-1]) /* should be null */ \
} while (0)
#define HT_DECODE_NEED(_r_, _l_)
#define HT_THROW_BAD_VSTR(_s_)
#define HT_DECODE_VI64(_ip_, _r_, _v_, _done_)

Definition at line 457 of file serialization-c.h.

#define HT_ENCODE_BOOL (   _op_,
  _v_ 
)    *(_op_)++ = (_v_) ? 1 : 0

Definition at line 104 of file serialization-c.h.

#define HT_ENCODE_BYTES32 (   _op_,
  _ip_,
  _len_ 
)
Value:
do { \
HT_ENCODE_I32(_op_, _len_); \
memcpy(_op_, _ip_, _len_); \
_op_ += _len_; \
} while (0)
#define HT_ENCODE_I32(_op_, _v_)

Definition at line 381 of file serialization-c.h.

#define HT_ENCODE_I16 (   _op_,
  _v_ 
)
Value:
do { \
*(_op_)++ = (uint8_t)(_v_); \
*(_op_)++ = (uint8_t)((_v_) >> 8); \
} while (0)

Definition at line 129 of file serialization-c.h.

#define HT_ENCODE_I32 (   _op_,
  _v_ 
)
Value:
do { \
*(_op_)++ = (uint8_t)(_v_); \
*(_op_)++ = (uint8_t)((_v_) >> 8); \
*(_op_)++ = (uint8_t)((_v_) >> 16); \
*(_op_)++ = (uint8_t)((_v_) >> 24); \
} while (0)

Definition at line 162 of file serialization-c.h.

#define HT_ENCODE_I64 (   _op_,
  _v_ 
)
Value:
do { \
*(_op_)++ = (uint8_t)(_v_); \
*(_op_)++ = (uint8_t)((_v_) >> 8); \
*(_op_)++ = (uint8_t)((_v_) >> 16); \
*(_op_)++ = (uint8_t)((_v_) >> 24); \
*(_op_)++ = (uint8_t)((_v_) >> 32); \
*(_op_)++ = (uint8_t)((_v_) >> 40); \
*(_op_)++ = (uint8_t)((_v_) >> 48); \
*(_op_)++ = (uint8_t)((_v_) >> 56); \
} while (0)

Definition at line 199 of file serialization-c.h.

#define HT_ENCODE_I8 (   _op_,
  _v_ 
)    *(_op_)++ = _v_

Definition at line 110 of file serialization-c.h.

#define HT_ENCODE_STR16 (   _op_,
  _s_,
  _len_ 
)
Value:
do { \
uint16_t _s16tmp_ = _len_; /* just to be cautious */ \
HT_ENCODE_I16(_op_, _s16tmp_); /* length */ \
if (_s16tmp_ > 0) { \
memcpy(_op_, _s_, _s16tmp_); /* data */ \
_op_ += len; \
} \
*(*bufp)++ = 0; /* null */ \
} while (0)
#define HT_ENCODE_I16(_op_, _v_)

Definition at line 411 of file serialization-c.h.

#define HT_ENCODE_VI32 (   _op_,
  _v_,
  _done_ 
)
Value:
do { \
uint32_t _evtmp32_ = _v_; /* make sure these var names are not the same */ \
HT_ENCODE_VINT0(_op_, _evtmp32_, _done_) \
HT_ENCODE_VINT4(_op_, _evtmp32_, _done_) \
HT_ENCODE_VINT_(_op_, _evtmp32_, _done_) \
HT_THROW_UNPOSSIBLE("reach here encoding vint32"); \
} while (0)
#define HT_ENCODE_VINT_(_op_, _v_, _done_)
#define HT_ENCODE_VINT0(_op_, _v_, _done_)
#define HT_THROW_UNPOSSIBLE(_s_)
#define HT_ENCODE_VINT4(_op_, _v_, _done_)

Definition at line 297 of file serialization-c.h.

#define HT_ENCODE_VI64 (   _op_,
  _v_,
  _done_ 
)
Value:
do { \
uint64_t _evtmp64_ = _v_; /* ditto */ \
HT_ENCODE_VINT0(_op_, _evtmp64_, _done_) \
HT_ENCODE_VINT4(_op_, _evtmp64_, _done_) \
HT_ENCODE_VINT4(_op_, _evtmp64_, _done_) \
HT_ENCODE_VINT_(_op_, _evtmp64_, _done_) \
HT_ENCODE_VINT_(_op_, _evtmp64_, _done_) \
HT_THROW_UNPOSSIBLE("reach here encoding vint64"); \
} while (0)
#define HT_ENCODE_VINT_(_op_, _v_, _done_)
#define HT_ENCODE_VINT0(_op_, _v_, _done_)
#define HT_THROW_UNPOSSIBLE(_s_)
#define HT_ENCODE_VINT4(_op_, _v_, _done_)

Definition at line 312 of file serialization-c.h.

#define HT_ENCODE_VINT0 (   _op_,
  _v_,
  _done_ 
)
Value:
if (_v_ <= HT_MAX_V1B) { \
*(_op_)++ = (uint8_t)((_v_) & 0x7f); \
_done_; \
}
#define HT_MAX_V1B

Definition at line 273 of file serialization-c.h.

#define HT_ENCODE_VINT4 (   _op_,
  _v_,
  _done_ 
)
Value:
HT_ENCODE_VINT_(_op_, _v_, _done_) \
HT_ENCODE_VINT_(_op_, _v_, _done_) \
HT_ENCODE_VINT_(_op_, _v_, _done_) \
HT_ENCODE_VINT_(_op_, _v_, _done_)
#define HT_ENCODE_VINT_(_op_, _v_, _done_)

Definition at line 284 of file serialization-c.h.

#define HT_ENCODE_VINT_ (   _op_,
  _v_,
  _done_ 
)
Value:
*(_op_)++ = (uint8_t)((_v_) | 0x80); \
_v_ >>= 7; \
HT_ENCODE_VINT0(_op_, _v_, _done_)
#define HT_ENCODE_VINT0(_op_, _v_, _done_)

Definition at line 279 of file serialization-c.h.

#define HT_ENCODE_VSTR (   _op_,
  _s_,
  _len_ 
)
Value:
do { \
size_t _vs64tmp_ = _len_; /* ditto */ \
HT_ENCODE_VI64(_op_, _vs64tmp_, break); \
if (_vs64tmp_) { \
memcpy((_op_), _s_, _vs64tmp_); \
(_op_) += _vs64tmp_; \
} \
*(_op_)++ = 0; \
} while (0)
#define HT_ENCODE_VI64(_op_, _v_, _done_)

Definition at line 444 of file serialization-c.h.

#define HT_ENCODED_LEN_VI32 (   _v_)
Value:
(_v_ <= HT_MAX_V1B ? 1 : \
(_v_ <= HT_MAX_V2B ? 2 : \
(_v_ <= HT_MAX_V3B ? 3 : \
(_v_ <= HT_MAX_V4B ? 4 : 5))))
#define HT_MAX_V2B
#define HT_MAX_V1B
#define HT_MAX_V4B
#define HT_MAX_V3B

Definition at line 252 of file serialization-c.h.

#define HT_ENCODED_LEN_VI64 (   _v_)
Value:
(val <= HT_MAX_V1B ? 1 : \
(val <= HT_MAX_V2B ? 2 : \
(val <= HT_MAX_V3B ? 3 : \
(val <= HT_MAX_V4B ? 4 : \
(val <= HT_MAX_V5B ? 5 : \
(val <= HT_MAX_V6B ? 6 : \
(val <= HT_MAX_V7B ? 7 : \
(val <= HT_MAX_V8B ? 8 : \
(val <= HT_MAX_V9B ? 9 : 10)))))))))
#define HT_MAX_V6B
#define HT_MAX_V8B
#define HT_MAX_V2B
#define HT_MAX_V5B
#define HT_MAX_V7B
#define HT_MAX_V1B
#define HT_MAX_V9B
#define HT_MAX_V4B
#define HT_MAX_V3B

Definition at line 261 of file serialization-c.h.

#define HT_MAX_LEN_VINT32   5

Definition at line 246 of file serialization-c.h.

#define HT_MAX_LEN_VINT64   10

Definition at line 247 of file serialization-c.h.

#define HT_MAX_V1B   0x7f

Definition at line 236 of file serialization-c.h.

#define HT_MAX_V2B   0x3fff

Definition at line 237 of file serialization-c.h.

#define HT_MAX_V3B   0x1fffff

Definition at line 238 of file serialization-c.h.

#define HT_MAX_V4B   0xfffffff

Definition at line 239 of file serialization-c.h.

#define HT_MAX_V5B   0x7ffffffffull

Definition at line 240 of file serialization-c.h.

#define HT_MAX_V6B   0x3ffffffffffull

Definition at line 241 of file serialization-c.h.

#define HT_MAX_V7B   0x1ffffffffffffull

Definition at line 242 of file serialization-c.h.

#define HT_MAX_V8B   0xffffffffffffffull

Definition at line 243 of file serialization-c.h.

#define HT_MAX_V9B   0x7fffffffffffffffull

Definition at line 244 of file serialization-c.h.

#define HT_THROW_BAD_VINT (   _s_)
Value:
do { \
std::fprintf(stderr, "Error: %s (%s:%d): malformed input decoding %s", \
HT_FUNC, __FILE__, __LINE__, _s_); \
abort(); \
} while (0)
#define HT_FUNC
Definition: compat-c.h:65

Definition at line 79 of file serialization-c.h.

#define HT_THROW_BAD_VSTR (   _s_)
Value:
do { \
std::fprintf(stderr, "Error: %s (%s:%d): malformed input decoding %s", \
HT_FUNC, __FILE__, __LINE__, _s_); \
abort(); \
} while (0)
#define HT_FUNC
Definition: compat-c.h:65

Definition at line 72 of file serialization-c.h.

#define HT_THROW_INPUT_OVERRUN (   _s_)
Value:
do { \
std::fprintf(stderr, "Error: %s (%s:%d): input overrun deocding %s", \
HT_FUNC, __FILE__, __LINE__, _s_); \
abort(); \
} while (0)
#define HT_FUNC
Definition: compat-c.h:65

Definition at line 65 of file serialization-c.h.

#define HT_THROW_UNPOSSIBLE (   _s_)
Value:
do { \
std::fprintf(stderr, "Error: %s (%s:%d): unpossible!: %s", \
HT_FUNC, __FILE__, __LINE__, _s_); \
abort(); \
} while (0)
#define HT_FUNC
Definition: compat-c.h:65

Definition at line 86 of file serialization-c.h.