#pragma once #include //#include #include #include //#include //#include namespace Incart::Common { #if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) #include #endif #define MSGPACK_ENDIAN_BIG_BYTE 0 #define MSGPACK_ENDIAN_LITTLE_BYTE 1 #if MSGPACK_ENDIAN_LITTLE_BYTE # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) # define _msgpack_be16(x) ntohs((uint16_t)x) # else # if defined(ntohs) # define _msgpack_be16(x) ntohs(x) # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x)) # else # define _msgpack_be16(x) ( \ ((((uint16_t)x) << 8) ) | \ ((((uint16_t)x) >> 8) ) ) # endif # endif # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) # define _msgpack_be32(x) ntohl((uint32_t)x) # else # if defined(ntohl) # define _msgpack_be32(x) ntohl(x) # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x)) # else # define _msgpack_be32(x) \ ( ((((uint32_t)x) << 24) ) | \ ((((uint32_t)x) << 8) & 0x00ff0000U ) | \ ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \ ((((uint32_t)x) >> 24) ) ) # endif # endif # if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be64(x) (_byteswap_uint64(x)) # elif defined(bswap_64) # define _msgpack_be64(x) bswap_64(x) # elif defined(__DARWIN_OSSwapInt64) # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x) # else # define _msgpack_be64(x) \ ( ((((uint64_t)x) << 56) ) | \ ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \ ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \ ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \ ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \ ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \ ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \ ((((uint64_t)x) >> 56) ) ) # endif #elif MSGPACK_ENDIAN_BIG_BYTE # define _msgpack_be16(x) (x) # define _msgpack_be32(x) (x) # define _msgpack_be64(x) (x) #else #error msgpack-c supports only big endian and little endian #endif /* MSGPACK_ENDIAN_LITTLE_BYTE */ #define _msgpack_load16(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be16(*(to)); \ } while (0); #define _msgpack_load32(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be32(*(to)); \ } while (0); #define _msgpack_load64(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be64(*(to)); \ } while (0); #define _msgpack_store16(to, num) \ do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0) #define _msgpack_store32(to, num) \ do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0) #define _msgpack_store64(to, num) \ do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0) #if MSGPACK_ENDIAN_LITTLE_BYTE template inline char take8_8(T d) { return static_cast(reinterpret_cast(&d)[0]); } template inline char take8_16(T d) { return static_cast(reinterpret_cast(&d)[0]); } template inline char take8_32(T d) { return static_cast(reinterpret_cast(&d)[0]); } template inline char take8_64(T d) { return static_cast(reinterpret_cast(&d)[0]); } #elif MSGPACK_ENDIAN_BIG_BYTE template inline char take8_8(T d) { return static_cast(reinterpret_cast(&d)[0]); } template inline char take8_16(T d) { return static_cast(reinterpret_cast(&d)[1]); } template inline char take8_32(T d) { return static_cast(reinterpret_cast(&d)[3]); } template inline char take8_64(T d) { return static_cast(reinterpret_cast(&d)[7]); } #else #error msgpack-c supports only big endian and little endian #endif class MessagePacker { private: //std::stringstream m_stream; QByteArray m_stream; public: MessagePacker() { } void clear() { //std::stringstream().swap(m_stream); m_stream.clear(); } QByteArray pack() { //std::string sdata = m_stream.str(); /* const char* strData = sdata.c_str(); std::cout << "MessagePacker:" << strData << std::endl; std::cout << std::hex; for (int i = 0; i < sdata.length(); i++) { std::cout << " " << std::setfill('0') << std::setw(2) << static_cast(strData[i] & 0xff); } std::cout << std::dec << std::endl; for (int i = 0; i < sdata.length(); i++) { std::cout << " " << std::setfill(' ') << std::setw(2) << strData[i]; } std::cout << std::dec << std::endl; */ //return QByteArray::fromStdString(sdata); return m_stream; } template MessagePacker& add_value(const std::string& fieldName, T v) { *this << fieldName; *this << v; return *this; } MessagePacker& add_value(const std::string& fieldName, const char* v, uint32_t size) { *this << fieldName; add_string(v, size); return *this; } MessagePacker& add_struct_value(const std::string& fieldName, uint32_t n) { *this << fieldName; start_map(n); return *this; } MessagePacker& add_array_value(const std::string& fieldName, uint32_t n) { *this << fieldName; start_array(n); return *this; } MessagePacker& operator<<(bool v) { if (v) pack_true(); else pack_false(); return *this; } MessagePacker& operator<<(uint32_t v) { pack_uint32(v); return *this; } MessagePacker& operator<<(int32_t v) { pack_int32(v); return *this; } MessagePacker& operator<<(uint64_t v) { pack_uint64(v); return *this; } MessagePacker& operator<<(int64_t v) { pack_int64(v); return *this; } MessagePacker& operator<<(float v) { pack_float(v); return *this; } MessagePacker& operator<<(double v) { pack_double(v); return *this; } MessagePacker& operator<<(const std::string& str) { uint32_t strLength = static_cast(str.size()); pack_str(strLength); pack_str_body(str.c_str(), strLength); return *this; } template MessagePacker& operator<<(const std::vector& vec) { start_array(static_cast(vec.size())); for (size_t i = 0; i < vec.size(); i++) { *this << vec[i]; } return *this; } MessagePacker& add_string(const char* v, uint32_t size) { pack_str(size); pack_str_body(v, size); return *this; } MessagePacker& start_array(uint32_t num_elements) { pack_array(num_elements); return *this; } MessagePacker& start_map(uint32_t num_kv_pairs) { pack_map(num_kv_pairs); return *this; } private: void append_buffer(const char* buf, size_t len) { //m_stream.write(buf, len); m_stream.append(buf, static_cast(len)); } MessagePacker& pack_nil() { const char d = static_cast(0xc0u); append_buffer(&d, 1); return *this; } MessagePacker& pack_true() { const char d = static_cast(0xc3u); append_buffer(&d, 1); return *this; } MessagePacker& pack_false() { const char d = static_cast(0xc2u); append_buffer(&d, 1); return *this; } MessagePacker& pack_array(uint32_t n) { if(n < 16) { char d = static_cast(0x90u | n); append_buffer(&d, 1); } else if(n < 65536) { char buf[3]; buf[0] = static_cast(0xdcu); _msgpack_store16(&buf[1], static_cast(n)); append_buffer(buf, 3); } else { char buf[5]; buf[0] = static_cast(0xddu); _msgpack_store32(&buf[1], static_cast(n)); append_buffer(buf, 5); } return *this; } MessagePacker& pack_map(uint32_t n) { if(n < 16) { unsigned char d = static_cast(0x80u | n); char buf = take8_8(d); append_buffer(&buf, 1); } else if(n < 65536) { char buf[3]; buf[0] = static_cast(0xdeu); _msgpack_store16(&buf[1], static_cast(n)); append_buffer(buf, 3); } else { char buf[5]; buf[0] = static_cast(0xdfu); _msgpack_store32(&buf[1], static_cast(n)); append_buffer(buf, 5); } return *this; } MessagePacker& pack_str(uint32_t l) { if(l < 32) { unsigned char d = static_cast(0xa0u | l); char buf = take8_8(d); append_buffer(&buf, 1); } else if(l < 256) { char buf[2]; buf[0] = static_cast(0xd9u); buf[1] = static_cast(l); append_buffer(buf, 2); } else if(l < 65536) { char buf[3]; buf[0] = static_cast(0xdau); _msgpack_store16(&buf[1], static_cast(l)); append_buffer(buf, 3); } else { char buf[5]; buf[0] = static_cast(0xdbu); _msgpack_store32(&buf[1], static_cast(l)); append_buffer(buf, 5); } return *this; } MessagePacker& pack_str_body(const char* b, uint32_t l) { append_buffer(b, l); return *this; } MessagePacker& pack_uint8(uint8_t d) { pack_imp_uint8(d); return *this; } MessagePacker& pack_uint16(uint16_t d) { pack_imp_uint16(d); return *this; } MessagePacker& pack_uint32(uint32_t d) { pack_imp_uint32(d); return *this; } MessagePacker& pack_uint64(uint64_t d) { pack_imp_uint64(d); return *this; } MessagePacker& pack_int8(int8_t d) { pack_imp_int8(d); return *this; } MessagePacker& pack_int16(int16_t d) { pack_imp_int16(d); return *this; } MessagePacker& pack_int32(int32_t d) { pack_imp_int32(d); return *this; } MessagePacker& pack_int64(int64_t d) { pack_imp_int64(d); return *this; } MessagePacker& pack_fix_uint8(uint8_t d) { char buf[2] = {static_cast(0xccu), take8_8(d)}; append_buffer(buf, 2); return *this; } MessagePacker& pack_fix_uint16(uint16_t d) { char buf[3]; buf[0] = static_cast(0xcdu); _msgpack_store16(&buf[1], d); append_buffer(buf, 3); return *this; } MessagePacker& pack_fix_uint32(uint32_t d) { char buf[5]; buf[0] = static_cast(0xceu); _msgpack_store32(&buf[1], d); append_buffer(buf, 5); return *this; } MessagePacker& pack_fix_uint64(uint64_t d) { char buf[9]; buf[0] = static_cast(0xcfu); _msgpack_store64(&buf[1], d); append_buffer(buf, 9); return *this; } MessagePacker& pack_fix_int8(int8_t d) { char buf[2] = {static_cast(0xd0u), take8_8(d)}; append_buffer(buf, 2); return *this; } MessagePacker& pack_fix_int16(int16_t d) { char buf[3]; buf[0] = static_cast(0xd1u); _msgpack_store16(&buf[1], (uint16_t)d); append_buffer(buf, 3); return *this; } MessagePacker& pack_fix_int32(int32_t d) { char buf[5]; buf[0] = static_cast(0xd2u); _msgpack_store32(&buf[1], (uint32_t)d); append_buffer(buf, 5); return *this; } MessagePacker& pack_fix_int64(int64_t d) { char buf[9]; buf[0] = static_cast(0xd3u); _msgpack_store64(&buf[1], d); append_buffer(buf, 9); return *this; } MessagePacker& pack_char(char d) { #if defined(CHAR_MIN) #if CHAR_MIN < 0 pack_imp_int8(d); #else pack_imp_uint8(d); #endif #else #error CHAR_MIN is not defined #endif return *this; } MessagePacker& pack_wchar(wchar_t d) { if (d < 0) { pack_imp_int64(static_cast(d)); } else { pack_imp_uint64(static_cast(d)); } return *this; } MessagePacker& pack_signed_char(signed char d) { pack_imp_int8(d); return *this; } MessagePacker& pack_short(short d) { #if defined(SIZEOF_SHORT) #if SIZEOF_SHORT == 2 pack_imp_int16(d); #elif SIZEOF_SHORT == 4 pack_imp_int32(d); #else pack_imp_int64(d); #endif #elif defined(SHRT_MAX) #if SHRT_MAX == 0x7fff pack_imp_int16(d); #elif SHRT_MAX == 0x7fffffff pack_imp_int32(d); #else pack_imp_int64(d); #endif #else if(sizeof(short) == 2) { pack_imp_int16(d); } else if(sizeof(short) == 4) { pack_imp_int32(d); } else { pack_imp_int64(d); } #endif return *this; } MessagePacker& pack_int(int d) { #if defined(SIZEOF_INT) #if SIZEOF_INT == 2 pack_imp_int16(d); #elif SIZEOF_INT == 4 pack_imp_int32(d); #else pack_imp_int64(d); #endif #elif defined(INT_MAX) #if INT_MAX == 0x7fff pack_imp_int16(d); #elif INT_MAX == 0x7fffffff pack_imp_int32(d); #else pack_imp_int64(d); #endif #else if(sizeof(int) == 2) { pack_imp_int16(d); } else if(sizeof(int) == 4) { pack_imp_int32(d); } else { pack_imp_int64(d); } #endif return *this; } MessagePacker& pack_long(long d) { #if defined(SIZEOF_LONG) #if SIZEOF_LONG == 2 pack_imp_int16(d); #elif SIZEOF_LONG == 4 pack_imp_int32(d); #else pack_imp_int64(d); #endif #elif defined(LONG_MAX) #if LONG_MAX == 0x7fffL pack_imp_int16(d); #elif LONG_MAX == 0x7fffffffL pack_imp_int32(d); #else pack_imp_int64(d); #endif #else if(sizeof(long) == 2) { pack_imp_int16(d); } else if(sizeof(long) == 4) { pack_imp_int32(d); } else { pack_imp_int64(d); } #endif return *this; } MessagePacker& pack_long_long(long long d) { #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG == 2 pack_imp_int16(d); #elif SIZEOF_LONG_LONG == 4 pack_imp_int32(d); #else pack_imp_int64(d); #endif #elif defined(LLONG_MAX) #if LLONG_MAX == 0x7fffL pack_imp_int16(d); #elif LLONG_MAX == 0x7fffffffL pack_imp_int32(d); #else pack_imp_int64(d); #endif #else if(sizeof(long long) == 2) { pack_imp_int16(d); } else if(sizeof(long long) == 4) { pack_imp_int32(d); } else { pack_imp_int64(d); } #endif return *this; } MessagePacker& pack_unsigned_char(unsigned char d) { pack_imp_uint8(d); return *this; } MessagePacker& pack_unsigned_short(unsigned short d) { #if defined(SIZEOF_SHORT) #if SIZEOF_SHORT == 2 pack_imp_uint16(d); #elif SIZEOF_SHORT == 4 pack_imp_uint32(d); #else pack_imp_uint64(d); #endif #elif defined(USHRT_MAX) #if USHRT_MAX == 0xffffU pack_imp_uint16(d); #elif USHRT_MAX == 0xffffffffU pack_imp_uint32(d); #else pack_imp_uint64(d); #endif #else if(sizeof(unsigned short) == 2) { pack_imp_uint16(d); } else if(sizeof(unsigned short) == 4) { pack_imp_uint32(d); } else { pack_imp_uint64(d); } #endif return *this; } MessagePacker& pack_unsigned_int(unsigned int d) { #if defined(SIZEOF_INT) #if SIZEOF_INT == 2 pack_imp_uint16(d); #elif SIZEOF_INT == 4 pack_imp_uint32(d); #else pack_imp_uint64(d); #endif #elif defined(UINT_MAX) #if UINT_MAX == 0xffffU pack_imp_uint16(d); #elif UINT_MAX == 0xffffffffU pack_imp_uint32(d); #else pack_imp_uint64(d); #endif #else if(sizeof(unsigned int) == 2) { pack_imp_uint16(d); } else if(sizeof(unsigned int) == 4) { pack_imp_uint32(d); } else { pack_imp_uint64(d); } #endif return *this; } MessagePacker& pack_unsigned_long(unsigned long d) { #if defined(SIZEOF_LONG) #if SIZEOF_LONG == 2 pack_imp_uint16(d); #elif SIZEOF_LONG == 4 pack_imp_uint32(d); #else pack_imp_uint64(d); #endif #elif defined(ULONG_MAX) #if ULONG_MAX == 0xffffUL pack_imp_uint16(d); #elif ULONG_MAX == 0xffffffffUL pack_imp_uint32(d); #else pack_imp_uint64(d); #endif #else if(sizeof(unsigned long) == 2) { pack_imp_uint16(d); } else if(sizeof(unsigned long) == 4) { pack_imp_uint32(d); } else { pack_imp_uint64(d); } #endif return *this; } MessagePacker& pack_unsigned_long_long(unsigned long long d) { #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG == 2 pack_imp_uint16(d); #elif SIZEOF_LONG_LONG == 4 pack_imp_uint32(d); #else pack_imp_uint64(d); #endif #elif defined(ULLONG_MAX) #if ULLONG_MAX == 0xffffUL pack_imp_uint16(d); #elif ULLONG_MAX == 0xffffffffUL pack_imp_uint32(d); #else pack_imp_uint64(d); #endif #else if(sizeof(unsigned long long) == 2) { pack_imp_uint16(d); } else if(sizeof(unsigned long long) == 4) { pack_imp_uint32(d); } else { pack_imp_uint64(d); } #endif return *this; } MessagePacker& pack_float(float d) { union { float f; uint32_t i; } mem; mem.f = d; char buf[5]; buf[0] = static_cast(0xcau); _msgpack_store32(&buf[1], mem.i); append_buffer(buf, 5); return *this; } MessagePacker& pack_double(double d) { union { double f; uint64_t i; } mem; mem.f = d; char buf[9]; buf[0] = static_cast(0xcbu); #if defined(TARGET_OS_IPHONE) // ok #elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi // https://github.com/msgpack/msgpack-perl/pull/1 mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL); #endif _msgpack_store64(&buf[1], mem.i); append_buffer(buf, 9); return *this; } template void pack_imp_uint8(T d) { if(d < (1<<7)) { /* fixnum */ char buf = take8_8(d); append_buffer(&buf, 1); } else { /* unsigned 8 */ char buf[2] = {static_cast(0xccu), take8_8(d)}; append_buffer(buf, 2); } } template void pack_imp_uint16(T d) { if(d < (1<<7)) { /* fixnum */ char buf = take8_16(d); append_buffer(&buf, 1); } else if(d < (1<<8)) { /* unsigned 8 */ char buf[2] = {static_cast(0xccu), take8_16(d)}; append_buffer(buf, 2); } else { /* unsigned 16 */ char buf[3]; buf[0] = static_cast(0xcdu); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } } template void pack_imp_uint32(T d) { if(d < (1<<8)) { if(d < (1<<7)) { /* fixnum */ char buf = take8_32(d); append_buffer(&buf, 1); } else { /* unsigned 8 */ char buf[2] = {static_cast(0xccu), take8_32(d)}; append_buffer(buf, 2); } } else { if(d < (1<<16)) { /* unsigned 16 */ char buf[3]; buf[0] = static_cast(0xcdu); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* unsigned 32 */ char buf[5]; buf[0] = static_cast(0xceu); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } } } template void pack_imp_uint64(T d) { if(d < (1ULL<<8)) { if(d < (1ULL<<7)) { /* fixnum */ char buf = take8_64(d); append_buffer(&buf, 1); } else { /* unsigned 8 */ char buf[2] = {static_cast(0xccu), take8_64(d)}; append_buffer(buf, 2); } } else { if(d < (1ULL<<16)) { /* unsigned 16 */ char buf[3]; buf[0] = static_cast(0xcdu); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else if(d < (1ULL<<32)) { /* unsigned 32 */ char buf[5]; buf[0] = static_cast(0xceu); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } else { /* unsigned 64 */ char buf[9]; buf[0] = static_cast(0xcfu); _msgpack_store64(&buf[1], d); append_buffer(buf, 9); } } } template void pack_imp_int8(T d) { if(d < -(1<<5)) { /* signed 8 */ char buf[2] = {static_cast(0xd0u), take8_8(d)}; append_buffer(buf, 2); } else { /* fixnum */ char buf = take8_8(d); append_buffer(&buf, 1); } } template void pack_imp_int16(T d) { if(d < -(1<<5)) { if(d < -(1<<7)) { /* signed 16 */ char buf[3]; buf[0] = static_cast(0xd1u); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* signed 8 */ char buf[2] = {static_cast(0xd0u), take8_16(d)}; append_buffer(buf, 2); } } else if(d < (1<<7)) { /* fixnum */ char buf = take8_16(d); append_buffer(&buf, 1); } else { if(d < (1<<8)) { /* unsigned 8 */ char buf[2] = {static_cast(0xccu), take8_16(d)}; append_buffer(buf, 2); } else { /* unsigned 16 */ char buf[3]; buf[0] = static_cast(0xcdu); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } } } template void pack_imp_int32(T d) { if(d < -(1<<5)) { if(d < -(1<<15)) { /* signed 32 */ char buf[5]; buf[0] = static_cast(0xd2u); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } else if(d < -(1<<7)) { /* signed 16 */ char buf[3]; buf[0] = static_cast(0xd1u); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* signed 8 */ char buf[2] = { static_cast(0xd0u), take8_32(d)}; append_buffer(buf, 2); } } else if(d < (1<<7)) { /* fixnum */ char buf = take8_32(d); append_buffer(&buf, 1); } else { if(d < (1<<8)) { /* unsigned 8 */ char buf[2] = { static_cast(0xccu), take8_32(d)}; append_buffer(buf, 2); } else if(d < (1<<16)) { /* unsigned 16 */ char buf[3]; buf[0] = static_cast(0xcdu); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* unsigned 32 */ char buf[5]; buf[0] = static_cast(0xceu); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } } } template void pack_imp_int64(T d) { if(d < -(1LL<<5)) { if(d < -(1LL<<15)) { if(d < -(1LL<<31)) { /* signed 64 */ char buf[9]; buf[0] = static_cast(0xd3u); _msgpack_store64(&buf[1], d); append_buffer(buf, 9); } else { /* signed 32 */ char buf[5]; buf[0] = static_cast(0xd2u); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } } else { if(d < -(1<<7)) { /* signed 16 */ char buf[3]; buf[0] = static_cast(0xd1u); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } else { /* signed 8 */ char buf[2] = {static_cast(0xd0u), take8_64(d)}; append_buffer(buf, 2); } } } else if(d < (1<<7)) { /* fixnum */ char buf = take8_64(d); append_buffer(&buf, 1); } else { if(d < (1LL<<16)) { if(d < (1<<8)) { /* unsigned 8 */ char buf[2] = {static_cast(0xccu), take8_64(d)}; append_buffer(buf, 2); } else { /* unsigned 16 */ char buf[3]; buf[0] = static_cast(0xcdu); _msgpack_store16(&buf[1], static_cast(d)); append_buffer(buf, 3); } } else { if(d < (1LL<<32)) { /* unsigned 32 */ char buf[5]; buf[0] = static_cast(0xceu); _msgpack_store32(&buf[1], static_cast(d)); append_buffer(buf, 5); } else { /* unsigned 64 */ char buf[9]; buf[0] = static_cast(0xcfu); _msgpack_store64(&buf[1], d); append_buffer(buf, 9); } } } } }; } // namespace Incart::Common