10#ifndef MSGPACK_V1_PACK_HPP
11#define MSGPACK_V1_PACK_HPP
32template <
typename Stream>
604 template <
typename T>
605 void pack_imp_uint8(
T d);
606 template <
typename T>
607 void pack_imp_uint16(
T d);
608 template <
typename T>
609 void pack_imp_uint32(
T d);
610 template <
typename T>
611 void pack_imp_uint64(
T d);
612 template <
typename T>
613 void pack_imp_int8(
T d);
614 template <
typename T>
615 void pack_imp_int16(
T d);
616 template <
typename T>
617 void pack_imp_int32(
T d);
618 template <
typename T>
619 void pack_imp_int64(
T d);
621 void append_buffer(
const char*
buf,
size_t len)
623 append_buffer(&Stream::write,
buf,
len);
626 template <
typename Ret,
typename Cls,
typename SizeType>
635#if defined(MSGPACK_USE_CPP03)
659template <
typename Stream,
typename T>
672template <
typename Stream,
typename T>
679#if MSGPACK_ENDIAN_LITTLE_BYTE
682 return static_cast<char>(
reinterpret_cast<uint8_t*
>(&
d)[0]);
686 return static_cast<char>(
reinterpret_cast<uint8_t*
>(&
d)[0]);
690 return static_cast<char>(
reinterpret_cast<uint8_t*
>(&
d)[0]);
694 return static_cast<char>(
reinterpret_cast<uint8_t*
>(&
d)[0]);
697#elif MSGPACK_ENDIAN_BIG_BYTE
701 return static_cast<char>(
reinterpret_cast<uint8_t*
>(&
d)[0]);
705 return static_cast<char>(
reinterpret_cast<uint8_t*
>(&
d)[1]);
709 return static_cast<char>(
reinterpret_cast<uint8_t*
>(&
d)[3]);
713 return static_cast<char>(
reinterpret_cast<uint8_t*
>(&
d)[7]);
717#error msgpack-c supports only big endian and little endian
720template <
typename Stream>
723template <
typename Stream>
727template <
typename Stream>
729{ pack_imp_uint8(
d);
return *
this; }
731template <
typename Stream>
733{ pack_imp_uint16(
d);
return *
this; }
735template <
typename Stream>
737{ pack_imp_uint32(
d);
return *
this; }
739template <
typename Stream>
741{ pack_imp_uint64(
d);
return *
this; }
743template <
typename Stream>
745{ pack_imp_int8(
d);
return *
this; }
747template <
typename Stream>
749{ pack_imp_int16(
d);
return *
this; }
751template <
typename Stream>
753{ pack_imp_int32(
d);
return *
this; }
755template <
typename Stream>
757{ pack_imp_int64(
d);
return *
this;}
760template <
typename Stream>
763 char buf[2] = {
static_cast<char>(0xccu),
take8_8(
d)};
764 append_buffer(
buf, 2);
768template <
typename Stream>
773 append_buffer(
buf, 3);
777template <
typename Stream>
782 append_buffer(
buf, 5);
786template <
typename Stream>
791 append_buffer(
buf, 9);
795template <
typename Stream>
798 char buf[2] = {
static_cast<char>(0xd0u),
take8_8(
d)};
799 append_buffer(
buf, 2);
803template <
typename Stream>
808 append_buffer(
buf, 3);
812template <
typename Stream>
817 append_buffer(
buf, 5);
821template <
typename Stream>
826 append_buffer(
buf, 9);
831template <
typename Stream>
841#error CHAR_MIN is not defined
846template <
typename Stream>
850 pack_imp_int64(
static_cast<int64_t>(
d));
853 pack_imp_uint64(
static_cast<uint64_t>(
d));
858template <
typename Stream>
865template <
typename Stream>
868#if defined(SIZEOF_SHORT)
871#elif SIZEOF_SHORT == 4
877#elif defined(SHRT_MAX)
878#if SHRT_MAX == 0x7fff
880#elif SHRT_MAX == 0x7fffffff
887 if(
sizeof(
short) == 2) {
889 }
else if(
sizeof(
short) == 4) {
898template <
typename Stream>
901#if defined(SIZEOF_INT)
910#elif defined(INT_MAX)
913#elif INT_MAX == 0x7fffffff
920 if(
sizeof(
int) == 2) {
922 }
else if(
sizeof(
int) == 4) {
931template <
typename Stream>
934#if defined(SIZEOF_LONG)
937#elif SIZEOF_LONG == 4
943#elif defined(LONG_MAX)
944#if LONG_MAX == 0x7fffL
946#elif LONG_MAX == 0x7fffffffL
953 if(
sizeof(
long) == 2) {
955 }
else if(
sizeof(
long) == 4) {
964template <
typename Stream>
967#if defined(SIZEOF_LONG_LONG)
968#if SIZEOF_LONG_LONG == 2
970#elif SIZEOF_LONG_LONG == 4
976#elif defined(LLONG_MAX)
977#if LLONG_MAX == 0x7fffL
979#elif LLONG_MAX == 0x7fffffffL
986 if(
sizeof(
long long) == 2) {
988 }
else if(
sizeof(
long long) == 4) {
998template <
typename Stream>
1005template <
typename Stream>
1008#if defined(SIZEOF_SHORT)
1009#if SIZEOF_SHORT == 2
1011#elif SIZEOF_SHORT == 4
1017#elif defined(USHRT_MAX)
1018#if USHRT_MAX == 0xffffU
1020#elif USHRT_MAX == 0xffffffffU
1027 if(
sizeof(
unsigned short) == 2) {
1029 }
else if(
sizeof(
unsigned short) == 4) {
1038template <
typename Stream>
1041#if defined(SIZEOF_INT)
1044#elif SIZEOF_INT == 4
1050#elif defined(UINT_MAX)
1051#if UINT_MAX == 0xffffU
1053#elif UINT_MAX == 0xffffffffU
1060 if(
sizeof(
unsigned int) == 2) {
1062 }
else if(
sizeof(
unsigned int) == 4) {
1071template <
typename Stream>
1074#if defined(SIZEOF_LONG)
1077#elif SIZEOF_LONG == 4
1083#elif defined(ULONG_MAX)
1084#if ULONG_MAX == 0xffffUL
1086#elif ULONG_MAX == 0xffffffffUL
1093 if(
sizeof(
unsigned long) == 2) {
1095 }
else if(
sizeof(
unsigned long) == 4) {
1104template <
typename Stream>
1107#if defined(SIZEOF_LONG_LONG)
1108#if SIZEOF_LONG_LONG == 2
1110#elif SIZEOF_LONG_LONG == 4
1116#elif defined(ULLONG_MAX)
1117#if ULLONG_MAX == 0xffffUL
1119#elif ULLONG_MAX == 0xffffffffUL
1126 if(
sizeof(
unsigned long long) == 2) {
1128 }
else if(
sizeof(
unsigned long long) == 4) {
1138template <
typename Stream>
1143 if(
d >= 0 &&
d <=
float(std::numeric_limits<uint64_t>::max()) &&
d ==
float(
uint64_t(
d))) {
1156 append_buffer(
buf, 5);
1160template <
typename Stream>
1165 if(
d >= 0 &&
d <=
double(std::numeric_limits<uint64_t>::max()) &&
d ==
double(
uint64_t(
d))) {
1177 buf[0] =
static_cast<char>(0xcbu);
1179#if defined(TARGET_OS_IPHONE)
1181#elif defined(__arm__) && !(__ARM_EABI__)
1183 mem.i = (
mem.i & 0xFFFFFFFFUL) << 32UL | (
mem.i >> 32UL);
1186 append_buffer(
buf, 9);
1191template <
typename Stream>
1194 const char d =
static_cast<char>(0xc0u);
1195 append_buffer(&
d, 1);
1199template <
typename Stream>
1202 const char d =
static_cast<char>(0xc3u);
1203 append_buffer(&
d, 1);
1207template <
typename Stream>
1210 const char d =
static_cast<char>(0xc2u);
1211 append_buffer(&
d, 1);
1216template <
typename Stream>
1220 char d =
static_cast<char>(0x90u |
n);
1221 append_buffer(&
d, 1);
1222 }
else if(
n < 65536) {
1225 append_buffer(
buf, 3);
1229 append_buffer(
buf, 5);
1234template <
typename Stream>
1238 unsigned char d =
static_cast<unsigned char>(0x80u |
n);
1240 append_buffer(&
buf, 1);
1241 }
else if(
n < 65536) {
1244 append_buffer(
buf, 3);
1248 append_buffer(
buf, 5);
1253template <
typename Stream>
1257 unsigned char d =
static_cast<uint8_t>(0xa0u |
l);
1259 append_buffer(&
buf, 1);
1260 }
else if(
l < 256) {
1262 buf[0] =
static_cast<char>(0xd9u);
buf[1] =
static_cast<char>(
l);
1263 append_buffer(
buf, 2);
1264 }
else if(
l < 65536) {
1267 append_buffer(
buf, 3);
1271 append_buffer(
buf, 5);
1276template <
typename Stream>
1279 append_buffer(
b,
l);
1285template <
typename Stream>
1289 unsigned char d =
static_cast<uint8_t>(0xa0u |
l);
1291 append_buffer(&
buf, 1);
1292 }
else if(
l < 65536) {
1295 append_buffer(
buf, 3);
1299 append_buffer(
buf, 5);
1304template <
typename Stream>
1307 append_buffer(
b,
l);
1311template <
typename Stream>
1316 buf[0] =
static_cast<char>(0xc4u);
buf[1] =
static_cast<char>(
l);
1317 append_buffer(
buf, 2);
1318 }
else if(
l < 65536) {
1321 append_buffer(
buf, 3);
1325 append_buffer(
buf, 5);
1330template <
typename Stream>
1333 append_buffer(
b,
l);
1337template <
typename Stream>
1343 buf[0] =
static_cast<char>(0xd4u);
1344 buf[1] =
static_cast<char>(type);
1345 append_buffer(
buf, 2);
1349 buf[0] =
static_cast<char>(0xd5u);
1350 buf[1] =
static_cast<char>(type);
1351 append_buffer(
buf, 2);
1355 buf[0] =
static_cast<char>(0xd6u);
1356 buf[1] =
static_cast<char>(type);
1357 append_buffer(
buf, 2);
1361 buf[0] =
static_cast<char>(0xd7u);
1362 buf[1] =
static_cast<char>(type);
1363 append_buffer(
buf, 2);
1367 buf[0] =
static_cast<char>(0xd8u);
1368 buf[1] =
static_cast<char>(type);
1369 append_buffer(
buf, 2);
1374 buf[0] =
static_cast<char>(0xc7u);
1375 buf[1] =
static_cast<char>(
l);
1376 buf[2] =
static_cast<char>(type);
1377 append_buffer(
buf, 3);
1378 }
else if(
l < 65536) {
1380 buf[0] =
static_cast<char>(0xc8u);
1382 buf[3] =
static_cast<char>(type);
1383 append_buffer(
buf, 4);
1386 buf[0] =
static_cast<char>(0xc9u);
1388 buf[5] =
static_cast<char>(type);
1389 append_buffer(
buf, 6);
1396template <
typename Stream>
1399 append_buffer(
b,
l);
1403template <
typename Stream>
1404template <
typename T>
1410 append_buffer(&
buf, 1);
1413 char buf[2] = {
static_cast<char>(0xccu),
take8_8(
d)};
1414 append_buffer(
buf, 2);
1418template <
typename Stream>
1419template <
typename T>
1420inline void packer<Stream>::pack_imp_uint16(
T d)
1425 append_buffer(&
buf, 1);
1426 }
else if(
d < (1<<8)) {
1429 append_buffer(
buf, 2);
1434 append_buffer(
buf, 3);
1438template <
typename Stream>
1439template <
typename T>
1440inline void packer<Stream>::pack_imp_uint32(
T d)
1446 append_buffer(&
buf, 1);
1450 append_buffer(
buf, 2);
1457 append_buffer(
buf, 3);
1462 append_buffer(
buf, 5);
1467template <
typename Stream>
1468template <
typename T>
1469inline void packer<Stream>::pack_imp_uint64(
T d)
1475 append_buffer(&
buf, 1);
1479 append_buffer(
buf, 2);
1482 if(
d < (1ULL<<16)) {
1486 append_buffer(
buf, 3);
1487 }
else if(
d < (1ULL<<32)) {
1491 append_buffer(
buf, 5);
1496 append_buffer(
buf, 9);
1501template <
typename Stream>
1502template <
typename T>
1503inline void packer<Stream>::pack_imp_int8(
T d)
1507 char buf[2] = {
static_cast<char>(0xd0u),
take8_8(
d)};
1508 append_buffer(
buf, 2);
1512 append_buffer(&
buf, 1);
1516template <
typename Stream>
1517template <
typename T>
1518inline void packer<Stream>::pack_imp_int16(
T d)
1525 append_buffer(
buf, 3);
1529 append_buffer(
buf, 2);
1531 }
else if(
d < (1<<7)) {
1534 append_buffer(&
buf, 1);
1539 append_buffer(
buf, 2);
1544 append_buffer(
buf, 3);
1549template <
typename Stream>
1550template <
typename T>
1551inline void packer<Stream>::pack_imp_int32(
T d)
1558 append_buffer(
buf, 5);
1559 }
else if(
d < -(1<<7)) {
1563 append_buffer(
buf, 3);
1566 char buf[2] = {
static_cast<char>(0xd0u),
take8_32(
d)};
1567 append_buffer(
buf, 2);
1569 }
else if(
d < (1<<7)) {
1572 append_buffer(&
buf, 1);
1576 char buf[2] = {
static_cast<char>(0xccu),
take8_32(
d)};
1577 append_buffer(
buf, 2);
1578 }
else if(
d < (1<<16)) {
1582 append_buffer(
buf, 3);
1587 append_buffer(
buf, 5);
1592template <
typename Stream>
1593template <
typename T>
1594inline void packer<Stream>::pack_imp_int64(
T d)
1597 if(
d < -(1LL<<15)) {
1598 if(
d < -(1LL<<31)) {
1602 append_buffer(
buf, 9);
1607 append_buffer(
buf, 5);
1614 append_buffer(
buf, 3);
1618 append_buffer(
buf, 2);
1621 }
else if(
d < (1<<7)) {
1624 append_buffer(&
buf, 1);
1630 append_buffer(
buf, 2);
1635 append_buffer(
buf, 3);
1642 append_buffer(
buf, 5);
1647 append_buffer(
buf, 9);
The class template that supports continuous packing.
Definition pack.hpp:33
packer< Stream > & pack_short(short d)
Packing short.
Definition pack.hpp:866
packer< Stream > & pack_v4raw(uint32_t l)
Packing raw (v4) header and length.
Definition pack.hpp:1286
packer(const packer &)=delete
packer< Stream > & pack_int(int d)
Packing int.
Definition pack.hpp:899
packer< Stream > & pack_uint32(uint32_t d)
Packing uint32.
Definition pack.hpp:736
packer< Stream > & pack_int32(int32_t d)
Packing int32.
Definition pack.hpp:752
packer< Stream > & pack_fix_int64(int64_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:822
packer< Stream > & pack_fix_uint64(uint64_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:787
packer< Stream > & pack_int16(int16_t d)
Packing int16.
Definition pack.hpp:748
packer< Stream > & pack_bin(uint32_t l)
Packing bin header and length.
Definition pack.hpp:1312
packer< Stream > & pack_unsigned_short(unsigned short d)
Packing unsigned short.
Definition pack.hpp:1006
packer< Stream > & pack_double(double d)
Packing double.
Definition pack.hpp:1161
packer< Stream > & pack_uint8(uint8_t d)
Packing uint8.
Definition pack.hpp:728
packer< Stream > & pack_map(uint32_t n)
Packing map header and size.
Definition pack.hpp:1235
packer< Stream > & pack_fix_int8(int8_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:796
packer< Stream > & pack_signed_char(signed char d)
Packing signed char.
Definition pack.hpp:859
packer< Stream > & pack_wchar(wchar_t d)
Packing wchar_t.
Definition pack.hpp:847
packer< Stream > & pack_v4raw_body(const char *b, uint32_t l)
Packing raw (v4) body.
Definition pack.hpp:1305
packer< Stream > & pack_unsigned_int(unsigned int d)
Packing unsigned int.
Definition pack.hpp:1039
packer< Stream > & pack_true()
Packing true.
Definition pack.hpp:1200
packer< Stream > & pack_unsigned_char(unsigned char d)
Packing unsigned char.
Definition pack.hpp:999
packer< Stream > & pack_false()
Packing false.
Definition pack.hpp:1208
packer< Stream > & pack_nil()
Packing nil.
Definition pack.hpp:1192
packer< Stream > & pack_str_body(const char *b, uint32_t l)
Packing str body.
Definition pack.hpp:1277
packer< Stream > & pack_ext(size_t l, int8_t type)
Packing ext header, type, and length.
Definition pack.hpp:1338
packer< Stream > & pack_fix_int32(int32_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:813
packer< Stream > & pack_bin_body(const char *b, uint32_t l)
Packing bin body.
Definition pack.hpp:1331
packer & operator=(const packer &)=delete
packer< Stream > & pack_fix_uint16(uint16_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:769
packer< Stream > & pack_long_long(long long d)
Packing long long.
Definition pack.hpp:965
packer< Stream > & pack_int8(int8_t d)
Packing int8.
Definition pack.hpp:744
packer< Stream > & pack_char(char d)
Packing char.
Definition pack.hpp:832
packer< Stream > & pack_fix_uint32(uint32_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:778
packer< Stream > & pack_fix_int16(int16_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:804
packer< Stream > & pack_unsigned_long_long(unsigned long long d)
Packing unsigned long long.
Definition pack.hpp:1105
packer< Stream > & pack_str(uint32_t l)
Packing str header and length.
Definition pack.hpp:1254
packer< Stream > & pack_uint16(uint16_t d)
Packing uint16.
Definition pack.hpp:732
packer< Stream > & pack_ext_body(const char *b, uint32_t l)
Packing ext body.
Definition pack.hpp:1397
packer< Stream > & pack_array(uint32_t n)
Packing array header and size.
Definition pack.hpp:1217
packer< Stream > & pack_unsigned_long(unsigned long d)
Packing unsigned long.
Definition pack.hpp:1072
packer< Stream > & pack_float(float d)
Packing float.
Definition pack.hpp:1139
packer< Stream > & pack_long(long d)
Packing long.
Definition pack.hpp:932
packer< Stream > & pack_int64(int64_t d)
Packing int32.
Definition pack.hpp:756
packer< Stream > & pack_uint64(uint64_t d)
Packing uint16.
Definition pack.hpp:740
packer< Stream > & pack(const T &v)
Packing function template.
packer< Stream > & pack_fix_uint8(uint8_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:761
Definition adaptor_base.hpp:15
void pack(msgpack::packer< Stream > &o, const T &v)
Definition object.hpp:1185
void convert(T &v, msgpack::object const &o)
Definition object.hpp:1178
#define _msgpack_store32(to, num)
Definition sysdep.hpp:187
#define _msgpack_store64(to, num)
Definition sysdep.hpp:189
#define _msgpack_store16(to, num)
Definition sysdep.hpp:185
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:66