Go to the documentation of this file.
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
42 #define msgpack_pack_real_uint8(x, d) \
46 msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
49 unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
50 msgpack_pack_append_buffer(x, buf, 2); \
54 #define msgpack_pack_real_uint16(x, d) \
58 msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
59 } else if(d < (1<<8)) { \
61 unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
62 msgpack_pack_append_buffer(x, buf, 2); \
65 unsigned char buf[3]; \
66 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
67 msgpack_pack_append_buffer(x, buf, 3); \
71 #define msgpack_pack_real_uint32(x, d) \
76 msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
79 unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
80 msgpack_pack_append_buffer(x, buf, 2); \
85 unsigned char buf[3]; \
86 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
87 msgpack_pack_append_buffer(x, buf, 3); \
90 unsigned char buf[5]; \
91 buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
92 msgpack_pack_append_buffer(x, buf, 5); \
97 #define msgpack_pack_real_uint64(x, d) \
100 if(d < (1ULL<<7)) { \
102 msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
105 unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
106 msgpack_pack_append_buffer(x, buf, 2); \
109 if(d < (1ULL<<16)) { \
111 unsigned char buf[3]; \
112 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
113 msgpack_pack_append_buffer(x, buf, 3); \
114 } else if(d < (1ULL<<32)) { \
116 unsigned char buf[5]; \
117 buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
118 msgpack_pack_append_buffer(x, buf, 5); \
121 unsigned char buf[9]; \
122 buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
123 msgpack_pack_append_buffer(x, buf, 9); \
128 #define msgpack_pack_real_int8(x, d) \
132 unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
133 msgpack_pack_append_buffer(x, buf, 2); \
136 msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
140 #define msgpack_pack_real_int16(x, d) \
145 unsigned char buf[3]; \
146 buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
147 msgpack_pack_append_buffer(x, buf, 3); \
150 unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
151 msgpack_pack_append_buffer(x, buf, 2); \
153 } else if(d < (1<<7)) { \
155 msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
159 unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
160 msgpack_pack_append_buffer(x, buf, 2); \
163 unsigned char buf[3]; \
164 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
165 msgpack_pack_append_buffer(x, buf, 3); \
170 #define msgpack_pack_real_int32(x, d) \
175 unsigned char buf[5]; \
176 buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
177 msgpack_pack_append_buffer(x, buf, 5); \
178 } else if(d < -(1<<7)) { \
180 unsigned char buf[3]; \
181 buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
182 msgpack_pack_append_buffer(x, buf, 3); \
185 unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
186 msgpack_pack_append_buffer(x, buf, 2); \
188 } else if(d < (1<<7)) { \
190 msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
194 unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
195 msgpack_pack_append_buffer(x, buf, 2); \
196 } else if(d < (1<<16)) { \
198 unsigned char buf[3]; \
199 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
200 msgpack_pack_append_buffer(x, buf, 3); \
203 unsigned char buf[5]; \
204 buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
205 msgpack_pack_append_buffer(x, buf, 5); \
210 #define msgpack_pack_real_int64(x, d) \
212 if(d < -(1LL<<5)) { \
213 if(d < -(1LL<<15)) { \
214 if(d < -(1LL<<31)) { \
216 unsigned char buf[9]; \
217 buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
218 msgpack_pack_append_buffer(x, buf, 9); \
221 unsigned char buf[5]; \
222 buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
223 msgpack_pack_append_buffer(x, buf, 5); \
228 unsigned char buf[3]; \
229 buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
230 msgpack_pack_append_buffer(x, buf, 3); \
233 unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
234 msgpack_pack_append_buffer(x, buf, 2); \
237 } else if(d < (1<<7)) { \
239 msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
241 if(d < (1LL<<16)) { \
244 unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
245 msgpack_pack_append_buffer(x, buf, 2); \
248 unsigned char buf[3]; \
249 buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
250 msgpack_pack_append_buffer(x, buf, 3); \
253 if(d < (1LL<<32)) { \
255 unsigned char buf[5]; \
256 buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
257 msgpack_pack_append_buffer(x, buf, 5); \
260 unsigned char buf[9]; \
261 buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
262 msgpack_pack_append_buffer(x, buf, 9); \
269 #ifdef msgpack_pack_inline_func_fixint
273 unsigned char buf[2] = {0xcc, TAKE8_8(d)};
279 unsigned char buf[3];
286 unsigned char buf[5];
293 unsigned char buf[9];
300 unsigned char buf[2] = {0xd0, TAKE8_8(d)};
306 unsigned char buf[3];
313 unsigned char buf[5];
320 unsigned char buf[9];
325 #undef msgpack_pack_inline_func_fixint
371 #if defined(CHAR_MIN)
378 #error CHAR_MIN is not defined
392 #ifdef msgpack_pack_inline_func_cint
396 #if defined(SIZEOF_SHORT)
397 #if SIZEOF_SHORT == 2
399 #elif SIZEOF_SHORT == 4
405 #elif defined(SHRT_MAX)
406 #if SHRT_MAX == 0x7fff
408 #elif SHRT_MAX == 0x7fffffff
415 if(
sizeof(
short) == 2) {
417 }
else if(
sizeof(
short) == 4) {
427 #if defined(SIZEOF_INT)
430 #elif SIZEOF_INT == 4
436 #elif defined(INT_MAX)
437 #if INT_MAX == 0x7fff
439 #elif INT_MAX == 0x7fffffff
446 if(
sizeof(
int) == 2) {
448 }
else if(
sizeof(
int) == 4) {
458 #if defined(SIZEOF_LONG)
461 #elif SIZEOF_LONG == 4
467 #elif defined(LONG_MAX)
468 #if LONG_MAX == 0x7fffL
470 #elif LONG_MAX == 0x7fffffffL
477 if(
sizeof(
long) == 2) {
479 }
else if(
sizeof(
long) == 4) {
489 #if defined(SIZEOF_LONG_LONG)
490 #if SIZEOF_LONG_LONG == 2
492 #elif SIZEOF_LONG_LONG == 4
498 #elif defined(LLONG_MAX)
499 #if LLONG_MAX == 0x7fffL
501 #elif LLONG_MAX == 0x7fffffffL
508 if(
sizeof(
long long) == 2) {
510 }
else if(
sizeof(
long long) == 4) {
520 #if defined(SIZEOF_SHORT)
521 #if SIZEOF_SHORT == 2
523 #elif SIZEOF_SHORT == 4
529 #elif defined(USHRT_MAX)
530 #if USHRT_MAX == 0xffffU
532 #elif USHRT_MAX == 0xffffffffU
539 if(
sizeof(
unsigned short) == 2) {
541 }
else if(
sizeof(
unsigned short) == 4) {
551 #if defined(SIZEOF_INT)
554 #elif SIZEOF_INT == 4
560 #elif defined(UINT_MAX)
561 #if UINT_MAX == 0xffffU
563 #elif UINT_MAX == 0xffffffffU
570 if(
sizeof(
unsigned int) == 2) {
572 }
else if(
sizeof(
unsigned int) == 4) {
582 #if defined(SIZEOF_LONG)
585 #elif SIZEOF_LONG == 4
591 #elif defined(ULONG_MAX)
592 #if ULONG_MAX == 0xffffUL
594 #elif ULONG_MAX == 0xffffffffUL
601 if(
sizeof(
unsigned long) == 2) {
603 }
else if(
sizeof(
unsigned long) == 4) {
613 #if defined(SIZEOF_LONG_LONG)
614 #if SIZEOF_LONG_LONG == 2
616 #elif SIZEOF_LONG_LONG == 4
622 #elif defined(ULLONG_MAX)
623 #if ULLONG_MAX == 0xffffUL
625 #elif ULLONG_MAX == 0xffffffffUL
632 if(
sizeof(
unsigned long long) == 2) {
634 }
else if(
sizeof(
unsigned long long) == 4) {
642 #undef msgpack_pack_inline_func_cint
653 unsigned char buf[5];
654 union {
float f; uint32_t i; } mem;
662 unsigned char buf[9];
663 union {
double f; uint64_t i; } mem;
666 #if defined(TARGET_OS_IPHONE)
668 #elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi
670 mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
683 static const unsigned char d = 0xc0;
694 static const unsigned char d = 0xc3;
700 static const unsigned char d = 0xc2;
712 unsigned char d = 0x90 | (uint8_t)
n;
714 }
else if(
n < 65536) {
715 unsigned char buf[3];
719 unsigned char buf[5];
733 unsigned char d = 0x80 | (uint8_t)
n;
735 }
else if(
n < 65536) {
736 unsigned char buf[3];
740 unsigned char buf[5];
754 unsigned char d = 0xa0 | (uint8_t)l;
757 unsigned char buf[2];
758 buf[0] = 0xd9; buf[1] = (uint8_t)l;
760 }
else if(l < 65536) {
761 unsigned char buf[3];
765 unsigned char buf[5];
783 unsigned char d = 0xa0 | (uint8_t)l;
785 }
else if(l < 65536) {
786 unsigned char buf[3];
790 unsigned char buf[5];
808 unsigned char buf[2];
809 buf[0] = 0xc4; buf[1] = (uint8_t)l;
811 }
else if(l < 65536) {
812 unsigned char buf[3];
816 unsigned char buf[5];
835 unsigned char buf[2];
841 unsigned char buf[2];
847 unsigned char buf[2];
853 unsigned char buf[2];
859 unsigned char buf[2];
866 unsigned char buf[3];
868 buf[1] = (
unsigned char)l;
871 }
else if(l < 65536) {
872 unsigned char buf[4];
878 unsigned char buf[6];
893 #undef msgpack_pack_inline_func
894 #undef msgpack_pack_user
895 #undef msgpack_pack_append_buffer
902 #undef msgpack_pack_real_uint8
903 #undef msgpack_pack_real_uint16
904 #undef msgpack_pack_real_uint32
905 #undef msgpack_pack_real_uint64
906 #undef msgpack_pack_real_int8
907 #undef msgpack_pack_real_int16
908 #undef msgpack_pack_real_int32
909 #undef msgpack_pack_real_int64
msgpack_pack_inline_func() _map(msgpack_pack_user x, size_t n)
Definition: pack_template.h:730
#define msgpack_pack_real_uint32(x, d)
Definition: pack_template.h:71
msgpack_pack_inline_func() _nil(msgpack_pack_user x)
Definition: pack_template.h:681
msgpack_pack_inline_func() _ext_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:888
msgpack_pack_inline_func() _array(msgpack_pack_user x, size_t n)
Definition: pack_template.h:709
msgpack_pack_inline_func() _double(msgpack_pack_user x, double d)
Definition: pack_template.h:660
msgpack_pack_inline_func() _v4raw_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:796
msgpack_pack_inline_func() _signed_char(msgpack_pack_user x, signed char d)
Definition: pack_template.h:382
msgpack_pack_inline_func() _str(msgpack_pack_user x, size_t l)
Definition: pack_template.h:751
msgpack_pack_inline_func() _uint64(msgpack_pack_user x, uint64_t d)
Definition: pack_template.h:344
msgpack_pack_inline_func() _int64(msgpack_pack_user x, int64_t d)
Definition: pack_template.h:364
msgpack_pack_inline_func() _uint16(msgpack_pack_user x, uint16_t d)
Definition: pack_template.h:334
#define msgpack_pack_user
Definition: pack.h:117
msgpack_pack_inline_func() _unsigned_char(msgpack_pack_user x, unsigned char d)
Definition: pack_template.h:387
#define msgpack_pack_inline_func_fixint(name)
Definition: pack.h:114
msgpack_pack_inline_func() _false(msgpack_pack_user x)
Definition: pack_template.h:698
#define msgpack_pack_real_uint64(x, d)
Definition: pack_template.h:97
const void * n
Definition: unpack_template.h:95
#define _msgpack_store32(to, num)
Definition: sysdep.h:165
#define msgpack_pack_inline_func_cint(name)
Definition: pack.h:111
msgpack_pack_inline_func() _uint8(msgpack_pack_user x, uint8_t d)
Definition: pack_template.h:329
msgpack_pack_inline_func() _int16(msgpack_pack_user x, int16_t d)
Definition: pack_template.h:354
msgpack_pack_inline_func() _ext(msgpack_pack_user x, size_t l, int8_t type)
Definition: pack_template.h:831
#define msgpack_pack_inline_func(name)
Definition: pack.h:108
#define _msgpack_store64(to, num)
Definition: sysdep.h:167
#define msgpack_pack_append_buffer(user, buf, len)
Definition: pack.h:119
msgpack_pack_inline_func() _uint32(msgpack_pack_user x, uint32_t d)
Definition: pack_template.h:339
#define msgpack_pack_real_int8(x, d)
Definition: pack_template.h:128
msgpack_pack_inline_func() _float(msgpack_pack_user x, float d)
Definition: pack_template.h:651
msgpack_pack_inline_func() _bin_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:822
#define msgpack_pack_real_int64(x, d)
Definition: pack_template.h:210
msgpack_pack_inline_func() _bin(msgpack_pack_user x, size_t l)
Definition: pack_template.h:805
#define msgpack_pack_real_uint16(x, d)
Definition: pack_template.h:54
#define msgpack_pack_real_uint8(x, d)
Definition: pack_template.h:42
msgpack_pack_inline_func() _char(msgpack_pack_user x, char d)
Definition: pack_template.h:369
#define msgpack_pack_real_int32(x, d)
Definition: pack_template.h:170
msgpack_pack_inline_func() _v4raw(msgpack_pack_user x, size_t l)
Definition: pack_template.h:780
msgpack_pack_inline_func() _int8(msgpack_pack_user x, int8_t d)
Definition: pack_template.h:349
msgpack_pack_inline_func() _int32(msgpack_pack_user x, int32_t d)
Definition: pack_template.h:359
#define msgpack_pack_real_int16(x, d)
Definition: pack_template.h:140
msgpack_pack_inline_func() _true(msgpack_pack_user x)
Definition: pack_template.h:692
msgpack_pack_inline_func() _str_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:771
#define _msgpack_store16(to, num)
Definition: sysdep.h:163