11#if MSGPACK_ENDIAN_LITTLE_BYTE
12#define TAKE8_8(d) ((uint8_t*)&d)[0]
13#define TAKE8_16(d) ((uint8_t*)&d)[0]
14#define TAKE8_32(d) ((uint8_t*)&d)[0]
15#define TAKE8_64(d) ((uint8_t*)&d)[0]
16#elif MSGPACK_ENDIAN_BIG_BYTE
17#define TAKE8_8(d) ((uint8_t*)&d)[0]
18#define TAKE8_16(d) ((uint8_t*)&d)[1]
19#define TAKE8_32(d) ((uint8_t*)&d)[3]
20#define TAKE8_64(d) ((uint8_t*)&d)[7]
22#error msgpack-c supports only big endian and little endian
25#ifndef msgpack_pack_inline_func
26#error msgpack_pack_inline_func template is not defined
29#ifndef msgpack_pack_user
30#error msgpack_pack_user type is not defined
33#ifndef msgpack_pack_append_buffer
34#error msgpack_pack_append_buffer callback is not defined
39# pragma warning(disable : 4204)
46#define msgpack_pack_real_uint8(x, d) \
50 msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
53 unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
54 msgpack_pack_append_buffer(x, buf, 2); \
58#define msgpack_pack_real_uint16(x, d) \
62 msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
63 } else if(d < (1<<8)) { \
65 unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
66 msgpack_pack_append_buffer(x, buf, 2); \
69 unsigned char buf[3]; \
70 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
71 msgpack_pack_append_buffer(x, buf, 3); \
75#define msgpack_pack_real_uint32(x, d) \
80 msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
83 unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
84 msgpack_pack_append_buffer(x, buf, 2); \
89 unsigned char buf[3]; \
90 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
91 msgpack_pack_append_buffer(x, buf, 3); \
94 unsigned char buf[5]; \
95 buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
96 msgpack_pack_append_buffer(x, buf, 5); \
101#define msgpack_pack_real_uint64(x, d) \
103 if(d < (1ULL<<8)) { \
104 if(d < (1ULL<<7)) { \
106 msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
109 unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
110 msgpack_pack_append_buffer(x, buf, 2); \
113 if(d < (1ULL<<16)) { \
115 unsigned char buf[3]; \
116 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
117 msgpack_pack_append_buffer(x, buf, 3); \
118 } else if(d < (1ULL<<32)) { \
120 unsigned char buf[5]; \
121 buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
122 msgpack_pack_append_buffer(x, buf, 5); \
125 unsigned char buf[9]; \
126 buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
127 msgpack_pack_append_buffer(x, buf, 9); \
132#define msgpack_pack_real_int8(x, d) \
136 unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
137 msgpack_pack_append_buffer(x, buf, 2); \
140 msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
144#define msgpack_pack_real_int16(x, d) \
149 unsigned char buf[3]; \
150 buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
151 msgpack_pack_append_buffer(x, buf, 3); \
154 unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
155 msgpack_pack_append_buffer(x, buf, 2); \
157 } else if(d < (1<<7)) { \
159 msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
163 unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
164 msgpack_pack_append_buffer(x, buf, 2); \
167 unsigned char buf[3]; \
168 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
169 msgpack_pack_append_buffer(x, buf, 3); \
174#define msgpack_pack_real_int32(x, d) \
179 unsigned char buf[5]; \
180 buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
181 msgpack_pack_append_buffer(x, buf, 5); \
182 } else if(d < -(1<<7)) { \
184 unsigned char buf[3]; \
185 buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
186 msgpack_pack_append_buffer(x, buf, 3); \
189 unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
190 msgpack_pack_append_buffer(x, buf, 2); \
192 } else if(d < (1<<7)) { \
194 msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
198 unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
199 msgpack_pack_append_buffer(x, buf, 2); \
200 } else if(d < (1<<16)) { \
202 unsigned char buf[3]; \
203 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
204 msgpack_pack_append_buffer(x, buf, 3); \
207 unsigned char buf[5]; \
208 buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
209 msgpack_pack_append_buffer(x, buf, 5); \
214#define msgpack_pack_real_int64(x, d) \
216 if(d < -(1LL<<5)) { \
217 if(d < -(1LL<<15)) { \
218 if(d < -(1LL<<31)) { \
220 unsigned char buf[9]; \
221 buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
222 msgpack_pack_append_buffer(x, buf, 9); \
225 unsigned char buf[5]; \
226 buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
227 msgpack_pack_append_buffer(x, buf, 5); \
232 unsigned char buf[3]; \
233 buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
234 msgpack_pack_append_buffer(x, buf, 3); \
237 unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
238 msgpack_pack_append_buffer(x, buf, 2); \
241 } else if(d < (1<<7)) { \
243 msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
245 if(d < (1LL<<16)) { \
248 unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
249 msgpack_pack_append_buffer(x, buf, 2); \
252 unsigned char buf[3]; \
253 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
254 msgpack_pack_append_buffer(x, buf, 3); \
257 if(d < (1LL<<32)) { \
259 unsigned char buf[5]; \
260 buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
261 msgpack_pack_append_buffer(x, buf, 5); \
264 unsigned char buf[9]; \
265 buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
266 msgpack_pack_append_buffer(x, buf, 9); \
273#ifdef msgpack_pack_inline_func_fixint
277 unsigned char buf[2] = {0xcc, TAKE8_8(d)};
283 unsigned char buf[3];
290 unsigned char buf[5];
297 unsigned char buf[9];
304 unsigned char buf[2] = {0xd0, TAKE8_8(d)};
310 unsigned char buf[3];
317 unsigned char buf[5];
324 unsigned char buf[9];
329#undef msgpack_pack_inline_func_fixint
382#error CHAR_MIN is not defined
396#ifdef msgpack_pack_inline_func_cint
400#if defined(SIZEOF_SHORT)
403#elif SIZEOF_SHORT == 4
409#elif defined(SHRT_MAX)
410#if SHRT_MAX == 0x7fff
412#elif SHRT_MAX == 0x7fffffff
419if(
sizeof(
short) == 2) {
421}
else if(
sizeof(
short) == 4) {
431#if defined(SIZEOF_INT)
440#elif defined(INT_MAX)
443#elif INT_MAX == 0x7fffffff
450if(
sizeof(
int) == 2) {
452}
else if(
sizeof(
int) == 4) {
462#if defined(SIZEOF_LONG)
465#elif SIZEOF_LONG == 4
471#elif defined(LONG_MAX)
472#if LONG_MAX == 0x7fffL
474#elif LONG_MAX == 0x7fffffffL
481if(
sizeof(
long) == 2) {
483}
else if(
sizeof(
long) == 4) {
493#if defined(SIZEOF_LONG_LONG)
494#if SIZEOF_LONG_LONG == 2
496#elif SIZEOF_LONG_LONG == 4
502#elif defined(LLONG_MAX)
503#if LLONG_MAX == 0x7fffL
505#elif LLONG_MAX == 0x7fffffffL
512if(
sizeof(
long long) == 2) {
514}
else if(
sizeof(
long long) == 4) {
524#if defined(SIZEOF_SHORT)
527#elif SIZEOF_SHORT == 4
533#elif defined(USHRT_MAX)
534#if USHRT_MAX == 0xffffU
536#elif USHRT_MAX == 0xffffffffU
543if(
sizeof(
unsigned short) == 2) {
545}
else if(
sizeof(
unsigned short) == 4) {
555#if defined(SIZEOF_INT)
564#elif defined(UINT_MAX)
565#if UINT_MAX == 0xffffU
567#elif UINT_MAX == 0xffffffffU
574if(
sizeof(
unsigned int) == 2) {
576}
else if(
sizeof(
unsigned int) == 4) {
586#if defined(SIZEOF_LONG)
589#elif SIZEOF_LONG == 4
595#elif defined(ULONG_MAX)
596#if ULONG_MAX == 0xffffUL
598#elif ULONG_MAX == 0xffffffffUL
605if(
sizeof(
unsigned long) == 2) {
607}
else if(
sizeof(
unsigned long) == 4) {
617#if defined(SIZEOF_LONG_LONG)
618#if SIZEOF_LONG_LONG == 2
620#elif SIZEOF_LONG_LONG == 4
626#elif defined(ULLONG_MAX)
627#if ULLONG_MAX == 0xffffUL
629#elif ULLONG_MAX == 0xffffffffUL
636if(
sizeof(
unsigned long long) == 2) {
638}
else if(
sizeof(
unsigned long long) == 4) {
646#undef msgpack_pack_inline_func_cint
657 unsigned char buf[5];
658 union {
float f; uint32_t i; } mem;
666 unsigned char buf[9];
667 union {
double f; uint64_t i; } mem;
670#if defined(TARGET_OS_IPHONE)
672#elif defined(__arm__) && !(__ARM_EABI__)
674 mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
687 static const unsigned char d = 0xc0;
698 static const unsigned char d = 0xc3;
704 static const unsigned char d = 0xc2;
716 unsigned char d = 0x90 | (uint8_t)
n;
718 }
else if(
n < 65536) {
719 unsigned char buf[3];
723 unsigned char buf[5];
737 unsigned char d = 0x80 | (uint8_t)
n;
739 }
else if(
n < 65536) {
740 unsigned char buf[3];
744 unsigned char buf[5];
758 unsigned char d = 0xa0 | (uint8_t)l;
761 unsigned char buf[2];
762 buf[0] = 0xd9; buf[1] = (uint8_t)l;
764 }
else if(l < 65536) {
765 unsigned char buf[3];
769 unsigned char buf[5];
787 unsigned char d = 0xa0 | (uint8_t)l;
789 }
else if(l < 65536) {
790 unsigned char buf[3];
794 unsigned char buf[5];
812 unsigned char buf[2];
813 buf[0] = 0xc4; buf[1] = (uint8_t)l;
815 }
else if(l < 65536) {
816 unsigned char buf[3];
820 unsigned char buf[5];
839 unsigned char buf[2];
841 buf[1] = (
unsigned char)type;
845 unsigned char buf[2];
847 buf[1] = (
unsigned char)type;
851 unsigned char buf[2];
853 buf[1] = (
unsigned char)type;
857 unsigned char buf[2];
859 buf[1] = (
unsigned char)type;
863 unsigned char buf[2];
865 buf[1] = (
unsigned char)type;
870 unsigned char buf[3];
872 buf[1] = (
unsigned char)l;
873 buf[2] = (
unsigned char)type;
875 }
else if(l < 65536) {
876 unsigned char buf[4];
879 buf[3] = (
unsigned char)type;
882 unsigned char buf[6];
885 buf[5] = (
unsigned char)type;
899 if ((((int64_t)d->tv_sec) >> 34) == 0) {
900 uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | (uint64_t)d->tv_sec;
901 if ((data64 & 0xffffffff00000000L) == 0) {
904 uint32_t data32 = (uint32_t)data64;
905 msgpack_pack_ext(x, 4, -1);
911 msgpack_pack_ext(x, 8, -1);
920 msgpack_pack_ext(x, 12, -1);
925#undef msgpack_pack_inline_func
926#undef msgpack_pack_user
927#undef msgpack_pack_append_buffer
934#undef msgpack_pack_real_uint8
935#undef msgpack_pack_real_uint16
936#undef msgpack_pack_real_uint32
937#undef msgpack_pack_real_uint64
938#undef msgpack_pack_real_int8
939#undef msgpack_pack_real_int16
940#undef msgpack_pack_real_int32
941#undef msgpack_pack_real_int64
#define msgpack_pack_inline_func_fixint(name)
Definition pack.h:120
#define msgpack_pack_append_buffer(user, buf, len)
Definition pack.h:125
#define msgpack_pack_inline_func_cint(name)
Definition pack.h:117
#define msgpack_pack_inline_func(name)
Definition pack.h:114
#define msgpack_pack_user
Definition pack.h:123
msgpack_pack_inline_func() _bin_body(msgpack_pack_user x, const void *b, size_t l)
Definition pack_template.h:826
#define msgpack_pack_real_int32(x, d)
Definition pack_template.h:174
msgpack_pack_inline_func() _nil(msgpack_pack_user x)
Definition pack_template.h:685
msgpack_pack_inline_func() _str(msgpack_pack_user x, size_t l)
Definition pack_template.h:755
msgpack_pack_inline_func() _v4raw(msgpack_pack_user x, size_t l)
Definition pack_template.h:784
msgpack_pack_inline_func() _double(msgpack_pack_user x, double d)
Definition pack_template.h:664
msgpack_pack_inline_func() _uint8(msgpack_pack_user x, uint8_t d)
Definition pack_template.h:333
msgpack_pack_inline_func() _uint32(msgpack_pack_user x, uint32_t d)
Definition pack_template.h:343
#define msgpack_pack_real_uint64(x, d)
Definition pack_template.h:101
msgpack_pack_inline_func() _ext(msgpack_pack_user x, size_t l, int8_t type)
Definition pack_template.h:835
msgpack_pack_inline_func() _char(msgpack_pack_user x, char d)
Definition pack_template.h:373
msgpack_pack_inline_func() _unsigned_char(msgpack_pack_user x, unsigned char d)
Definition pack_template.h:391
msgpack_pack_inline_func() _bin(msgpack_pack_user x, size_t l)
Definition pack_template.h:809
msgpack_pack_inline_func() _signed_char(msgpack_pack_user x, signed char d)
Definition pack_template.h:386
msgpack_pack_inline_func() _int64(msgpack_pack_user x, int64_t d)
Definition pack_template.h:368
msgpack_pack_inline_func() _map(msgpack_pack_user x, size_t n)
Definition pack_template.h:734
#define msgpack_pack_real_uint32(x, d)
Definition pack_template.h:75
msgpack_pack_inline_func() _ext_body(msgpack_pack_user x, const void *b, size_t l)
Definition pack_template.h:892
#define msgpack_pack_real_int8(x, d)
Definition pack_template.h:132
msgpack_pack_inline_func() _uint16(msgpack_pack_user x, uint16_t d)
Definition pack_template.h:338
#define msgpack_pack_real_uint16(x, d)
Definition pack_template.h:58
msgpack_pack_inline_func() _int16(msgpack_pack_user x, int16_t d)
Definition pack_template.h:358
msgpack_pack_inline_func() _true(msgpack_pack_user x)
Definition pack_template.h:696
#define msgpack_pack_real_int64(x, d)
Definition pack_template.h:214
msgpack_pack_inline_func() _uint64(msgpack_pack_user x, uint64_t d)
Definition pack_template.h:348
msgpack_pack_inline_func() _int32(msgpack_pack_user x, int32_t d)
Definition pack_template.h:363
msgpack_pack_inline_func() _float(msgpack_pack_user x, float d)
Definition pack_template.h:655
#define msgpack_pack_real_int16(x, d)
Definition pack_template.h:144
#define msgpack_pack_real_uint8(x, d)
Definition pack_template.h:46
msgpack_pack_inline_func() _int8(msgpack_pack_user x, int8_t d)
Definition pack_template.h:353
msgpack_pack_inline_func() _v4raw_body(msgpack_pack_user x, const void *b, size_t l)
Definition pack_template.h:800
msgpack_pack_inline_func() _false(msgpack_pack_user x)
Definition pack_template.h:702
msgpack_pack_inline_func() _timestamp(msgpack_pack_user x, const msgpack_timestamp *d)
Definition pack_template.h:897
msgpack_pack_inline_func() _array(msgpack_pack_user x, size_t n)
Definition pack_template.h:713
msgpack_pack_inline_func() _str_body(msgpack_pack_user x, const void *b, size_t l)
Definition pack_template.h:775
Definition timestamp.h:20
#define _msgpack_store32(to, num)
Definition sysdep.h:176
#define _msgpack_store64(to, num)
Definition sysdep.h:178
#define _msgpack_store16(to, num)
Definition sysdep.h:174
const void * n
Definition unpack_template.h:100