28 #ifndef HYPERTABLE_SERIALIZATION_H
29 #define HYPERTABLE_SERIALIZATION_H
49 inline void encode_i8(uint8_t **bufp, uint8_t val) {
60 inline uint8_t
decode_i8(
const uint8_t **bufp,
size_t *remainp) {
73 inline uint8_t
decode_byte(
const uint8_t **bufp,
size_t *remainp) {
96 inline bool decode_bool(
const uint8_t **bufp,
size_t *remainp) {
117 inline uint16_t
decode_i16(
const uint8_t **bufp,
size_t *remainp) {
140 inline uint32_t
decode_i32(
const uint8_t **bufp,
size_t *remainp) {
163 inline uint64_t
decode_i64(
const uint8_t **bufp,
size_t *remainp) {
216 inline uint32_t
decode_vi32(
const uint8_t **bufp,
size_t *remainp) {
228 inline uint64_t
decode_vi64(
const uint8_t **bufp,
size_t *remainp) {
301 return 2 + ((str == 0) ? 0 : strlen(str)) + 1;
311 return 2 + str.length() + 1;
340 uint16_t len = (str == 0) ? 0 : strlen(str);
354 template <
class StringT>
370 inline const char *
decode_str16(
const uint8_t **bufp,
size_t *remainp) {
406 template <
class StringT>
407 inline StringT
decode_str16(
const uint8_t **bufp,
size_t *remainp) {
411 return StringT(str, len);
453 inline void encode_vstr(uint8_t **bufp,
const void *buf,
size_t len) {
473 template <
class StringT>
502 template <
class StringT>
507 return StringT(buf, len);
563 int64_t lod = (int64_t)val;
564 int64_t rod = (int64_t)((val - (
double)lod) * (
double)1000000000000000000.00);
581 return (
double)lod + ((double)rod / (
double)1000000000000000000.00);
602 inline bool equal(
double a,
double b) {
603 int64_t lod_a = (int64_t)a;
604 int64_t rod_a = (int64_t)((a - (
double)lod_a) * (
double)1000000000000000000.00);
605 double aprime = (double)lod_a + ((
double)rod_a / (double)1000000000000000000.00);
606 int64_t lod_b = (int64_t)b;
607 int64_t rod_b = (int64_t)((b - (
double)lod_b) * (
double)1000000000000000000.00);
608 double bprime = (double)lod_b + ((
double)rod_b / (double)1000000000000000000.00);
609 return aprime == bprime;
616 #endif // HYPERTABLE_SERIALIZATION_H
#define HT_DECODE_NEED(_r_, _l_)
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
#define HT_ENCODE_STR16(_op_, _s_, _len_)
int encoded_length_double()
Length of an encoded double (16 bytes)
#define HT_ENCODE_VSTR(_op_, _s_, _len_)
#define HT_ENCODE_BYTES32(_op_, _ip_, _len_)
std::string String
A String is simply a typedef to std::string.
#define HT_DECODE_VSTR(_ip_, _r_, _out_, _len_)
#define HT_DECODE_I32(_ip_, _r_, _v_)
Po::typed_value< String > * str(String *v=0)
#define HT_ENCODE_I16(_op_, _v_)
#define HT_ENCODE_VI64(_op_, _v_, _done_)
#define HT_ENCODE_VI32(_op_, _v_, _done_)
#define HT_DECODE_BYTES32(_ip_, _r_, _out_, _len_)
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
#define HT_ENCODE_BOOL(_op_, _v_)
void encode_inet_addr(uint8_t **bufp, const InetAddr &addr)
Encode an InetAddr structure.
#define HT_ENCODE_I8(_op_, _v_)
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
#define HT_ENCODED_LEN_VI32(_v_)
uint8_t decode_i8(const uint8_t **bufp, size_t *remainp)
Decode a 8-bit integer (a byte/character)
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
int encoded_length_vi32(uint32_t val)
Length of a variable length encoded 32-bit integer (up to 5 bytes)
void encode_vi64(uint8_t **bufp, uint64_t val)
Encode a integer (up to 64-bit) in variable length encoding.
size_t encoded_length_str16(const char *str)
Computes the encoded length of a string16 encoding.
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
Encapsulate an internet address.
uint16_t decode_i16(const uint8_t **bufp, size_t *remainp)
Decode a 16-bit integer in little-endian order.
#define HT_DECODE_I16(_ip_, _r_, _v_)
#define HT_DECODE_I64(_ip_, _r_, _v_)
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
void encode_i16(uint8_t **bufp, uint16_t val)
Encode a 16-bit integer in little-endian order.
size_t encoded_length_bytes32(int32_t len)
Computes the encoded length of a 32-bit length byte array (i32, bytes)
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
const char * decode_str16(const uint8_t **bufp, size_t *remainp)
Decodes a c-style string from the given buffer.
#define HT_DECODE_STR16(_ip_, _r_, _s_, _len_)
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
uint64_t decode_vi64(const uint8_t **bufp, size_t *remainp)
Decode a variable length encoded integer up to 64-bit.
#define HT_ENCODED_LEN_VI64(_v_)
void encode_vi32(uint8_t **bufp, uint32_t val)
Encode a integer (up to 32-bit) in variable length encoding.
void encode_bool(uint8_t **bufp, bool bval)
Encodes a boolean into the given buffer.
double decode_double(const uint8_t **bufp, size_t *remainp)
Decodes a double as 64-bit left-of-decimal, followed by 64-bit right-of-decimal, both in little-endia...
bool equal(double a, double b)
Compare doubles that may have been serialized and unserialized.
Internet address wrapper classes and utility functions.
#define HT_DECODE_VI64(_ip_, _r_, _v_, _done_)
uint8_t * decode_bytes32(const uint8_t **bufp, size_t *remainp, uint32_t *lenp)
Decodes a variable sized byte array from the given buffer.
#define HT_DECODE_VI32(_ip_, _r_, _v_, _done_)
void encode_str16(uint8_t **bufp, const void *str, uint16_t len)
Encodes a string buffer into the given buffer.
#define HT_ENCODE_I32(_op_, _v_)
InetAddr decode_inet_addr(const uint8_t **bufp, size_t *remainp)
Decode an InetAddr structure.
uint8_t decode_byte(const uint8_t **bufp, size_t *remainp)
Decodes a single byte from the given buffer.
void encode_bytes32(uint8_t **bufp, const void *data, int32_t len)
Encodes a variable sized byte array into the given buffer.
Macros to serialize/deserialize primitives to/from a memory buffer.
uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Decode a variable length encoded integer up to 32-bit.
void encode_i8(uint8_t **bufp, uint8_t val)
Encodes a byte into the given buffer.
void encode_double(uint8_t **bufp, double val)
Encodes a double with 18 decimal digits of precision as 64-bit left-of-decimal, followed by 64-bit ri...
#define HT_ENCODE_I64(_op_, _v_)
int encoded_length_vi64(uint64_t val)
Length of a variable length encoded 64-bit integer (up to 9 bytes)