2 * MessagePack packing routine template
4 * Copyright (C) 2008-2010 FURUHASHI Sadayuki
6 * Distributed under the Boost Software License, Version 1.0.
7 * (See accompanying file LICENSE_1_0.txt or copy at
8 * http://www.boost.org/LICENSE_1_0.txt)
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
38 # pragma warning(push)
39 # pragma warning(disable : 4204) /* nonstandard extension used: non-constant aggregate initializer */
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
275 msgpack_pack_inline_func_fixint(_uint8
)(msgpack_pack_user x
, uint8_t d
)
277 unsigned char buf
[2] = {0xcc, TAKE8_8(d
)};
278 msgpack_pack_append_buffer(x
, buf
, 2);
281 msgpack_pack_inline_func_fixint(_uint16
)(msgpack_pack_user x
, uint16_t d
)
283 unsigned char buf
[3];
284 buf
[0] = 0xcd; _msgpack_store16(&buf
[1], d
);
285 msgpack_pack_append_buffer(x
, buf
, 3);
288 msgpack_pack_inline_func_fixint(_uint32
)(msgpack_pack_user x
, uint32_t d
)
290 unsigned char buf
[5];
291 buf
[0] = 0xce; _msgpack_store32(&buf
[1], d
);
292 msgpack_pack_append_buffer(x
, buf
, 5);
295 msgpack_pack_inline_func_fixint(_uint64
)(msgpack_pack_user x
, uint64_t d
)
297 unsigned char buf
[9];
298 buf
[0] = 0xcf; _msgpack_store64(&buf
[1], d
);
299 msgpack_pack_append_buffer(x
, buf
, 9);
302 msgpack_pack_inline_func_fixint(_int8
)(msgpack_pack_user x
, int8_t d
)
304 unsigned char buf
[2] = {0xd0, TAKE8_8(d
)};
305 msgpack_pack_append_buffer(x
, buf
, 2);
308 msgpack_pack_inline_func_fixint(_int16
)(msgpack_pack_user x
, int16_t d
)
310 unsigned char buf
[3];
311 buf
[0] = 0xd1; _msgpack_store16(&buf
[1], d
);
312 msgpack_pack_append_buffer(x
, buf
, 3);
315 msgpack_pack_inline_func_fixint(_int32
)(msgpack_pack_user x
, int32_t d
)
317 unsigned char buf
[5];
318 buf
[0] = 0xd2; _msgpack_store32(&buf
[1], d
);
319 msgpack_pack_append_buffer(x
, buf
, 5);
322 msgpack_pack_inline_func_fixint(_int64
)(msgpack_pack_user x
, int64_t d
)
324 unsigned char buf
[9];
325 buf
[0] = 0xd3; _msgpack_store64(&buf
[1], d
);
326 msgpack_pack_append_buffer(x
, buf
, 9);
329 #undef msgpack_pack_inline_func_fixint
333 msgpack_pack_inline_func(_uint8
)(msgpack_pack_user x
, uint8_t d
)
335 msgpack_pack_real_uint8(x
, d
);
338 msgpack_pack_inline_func(_uint16
)(msgpack_pack_user x
, uint16_t d
)
340 msgpack_pack_real_uint16(x
, d
);
343 msgpack_pack_inline_func(_uint32
)(msgpack_pack_user x
, uint32_t d
)
345 msgpack_pack_real_uint32(x
, d
);
348 msgpack_pack_inline_func(_uint64
)(msgpack_pack_user x
, uint64_t d
)
350 msgpack_pack_real_uint64(x
, d
);
353 msgpack_pack_inline_func(_int8
)(msgpack_pack_user x
, int8_t d
)
355 msgpack_pack_real_int8(x
, d
);
358 msgpack_pack_inline_func(_int16
)(msgpack_pack_user x
, int16_t d
)
360 msgpack_pack_real_int16(x
, d
);
363 msgpack_pack_inline_func(_int32
)(msgpack_pack_user x
, int32_t d
)
365 msgpack_pack_real_int32(x
, d
);
368 msgpack_pack_inline_func(_int64
)(msgpack_pack_user x
, int64_t d
)
370 msgpack_pack_real_int64(x
, d
);
373 msgpack_pack_inline_func(_char
)(msgpack_pack_user x
, char d
)
375 #if defined(CHAR_MIN)
377 msgpack_pack_real_int8(x
, d
);
379 msgpack_pack_real_uint8(x
, d
);
382 #error CHAR_MIN is not defined
386 msgpack_pack_inline_func(_signed_char
)(msgpack_pack_user x
, signed char d
)
388 msgpack_pack_real_int8(x
, d
);
391 msgpack_pack_inline_func(_unsigned_char
)(msgpack_pack_user x
, unsigned char d
)
393 msgpack_pack_real_uint8(x
, d
);
396 #ifdef msgpack_pack_inline_func_cint
398 msgpack_pack_inline_func_cint(_short
)(msgpack_pack_user x
, short d
)
400 #if defined(SIZEOF_SHORT)
401 #if SIZEOF_SHORT == 2
402 msgpack_pack_real_int16(x
, d
);
403 #elif SIZEOF_SHORT == 4
404 msgpack_pack_real_int32(x
, d
);
406 msgpack_pack_real_int64(x
, d
);
409 #elif defined(SHRT_MAX)
410 #if SHRT_MAX == 0x7fff
411 msgpack_pack_real_int16(x
, d
);
412 #elif SHRT_MAX == 0x7fffffff
413 msgpack_pack_real_int32(x
, d
);
415 msgpack_pack_real_int64(x
, d
);
419 if(sizeof(short) == 2) {
420 msgpack_pack_real_int16(x
, d
);
421 } else if(sizeof(short) == 4) {
422 msgpack_pack_real_int32(x
, d
);
424 msgpack_pack_real_int64(x
, d
);
429 msgpack_pack_inline_func_cint(_int
)(msgpack_pack_user x
, int d
)
431 #if defined(SIZEOF_INT)
433 msgpack_pack_real_int16(x
, d
);
434 #elif SIZEOF_INT == 4
435 msgpack_pack_real_int32(x
, d
);
437 msgpack_pack_real_int64(x
, d
);
440 #elif defined(INT_MAX)
441 #if INT_MAX == 0x7fff
442 msgpack_pack_real_int16(x
, d
);
443 #elif INT_MAX == 0x7fffffff
444 msgpack_pack_real_int32(x
, d
);
446 msgpack_pack_real_int64(x
, d
);
450 if(sizeof(int) == 2) {
451 msgpack_pack_real_int16(x
, d
);
452 } else if(sizeof(int) == 4) {
453 msgpack_pack_real_int32(x
, d
);
455 msgpack_pack_real_int64(x
, d
);
460 msgpack_pack_inline_func_cint(_long
)(msgpack_pack_user x
, long d
)
462 #if defined(SIZEOF_LONG)
464 msgpack_pack_real_int16(x
, d
);
465 #elif SIZEOF_LONG == 4
466 msgpack_pack_real_int32(x
, d
);
468 msgpack_pack_real_int64(x
, d
);
471 #elif defined(LONG_MAX)
472 #if LONG_MAX == 0x7fffL
473 msgpack_pack_real_int16(x
, d
);
474 #elif LONG_MAX == 0x7fffffffL
475 msgpack_pack_real_int32(x
, d
);
477 msgpack_pack_real_int64(x
, d
);
481 if(sizeof(long) == 2) {
482 msgpack_pack_real_int16(x
, d
);
483 } else if(sizeof(long) == 4) {
484 msgpack_pack_real_int32(x
, d
);
486 msgpack_pack_real_int64(x
, d
);
491 msgpack_pack_inline_func_cint(_long_long
)(msgpack_pack_user x
, long long d
)
493 #if defined(SIZEOF_LONG_LONG)
494 #if SIZEOF_LONG_LONG == 2
495 msgpack_pack_real_int16(x
, d
);
496 #elif SIZEOF_LONG_LONG == 4
497 msgpack_pack_real_int32(x
, d
);
499 msgpack_pack_real_int64(x
, d
);
502 #elif defined(LLONG_MAX)
503 #if LLONG_MAX == 0x7fffL
504 msgpack_pack_real_int16(x
, d
);
505 #elif LLONG_MAX == 0x7fffffffL
506 msgpack_pack_real_int32(x
, d
);
508 msgpack_pack_real_int64(x
, d
);
512 if(sizeof(long long) == 2) {
513 msgpack_pack_real_int16(x
, d
);
514 } else if(sizeof(long long) == 4) {
515 msgpack_pack_real_int32(x
, d
);
517 msgpack_pack_real_int64(x
, d
);
522 msgpack_pack_inline_func_cint(_unsigned_short
)(msgpack_pack_user x
, unsigned short d
)
524 #if defined(SIZEOF_SHORT)
525 #if SIZEOF_SHORT == 2
526 msgpack_pack_real_uint16(x
, d
);
527 #elif SIZEOF_SHORT == 4
528 msgpack_pack_real_uint32(x
, d
);
530 msgpack_pack_real_uint64(x
, d
);
533 #elif defined(USHRT_MAX)
534 #if USHRT_MAX == 0xffffU
535 msgpack_pack_real_uint16(x
, d
);
536 #elif USHRT_MAX == 0xffffffffU
537 msgpack_pack_real_uint32(x
, d
);
539 msgpack_pack_real_uint64(x
, d
);
543 if(sizeof(unsigned short) == 2) {
544 msgpack_pack_real_uint16(x
, d
);
545 } else if(sizeof(unsigned short) == 4) {
546 msgpack_pack_real_uint32(x
, d
);
548 msgpack_pack_real_uint64(x
, d
);
553 msgpack_pack_inline_func_cint(_unsigned_int
)(msgpack_pack_user x
, unsigned int d
)
555 #if defined(SIZEOF_INT)
557 msgpack_pack_real_uint16(x
, d
);
558 #elif SIZEOF_INT == 4
559 msgpack_pack_real_uint32(x
, d
);
561 msgpack_pack_real_uint64(x
, d
);
564 #elif defined(UINT_MAX)
565 #if UINT_MAX == 0xffffU
566 msgpack_pack_real_uint16(x
, d
);
567 #elif UINT_MAX == 0xffffffffU
568 msgpack_pack_real_uint32(x
, d
);
570 msgpack_pack_real_uint64(x
, d
);
574 if(sizeof(unsigned int) == 2) {
575 msgpack_pack_real_uint16(x
, d
);
576 } else if(sizeof(unsigned int) == 4) {
577 msgpack_pack_real_uint32(x
, d
);
579 msgpack_pack_real_uint64(x
, d
);
584 msgpack_pack_inline_func_cint(_unsigned_long
)(msgpack_pack_user x
, unsigned long d
)
586 #if defined(SIZEOF_LONG)
588 msgpack_pack_real_uint16(x
, d
);
589 #elif SIZEOF_LONG == 4
590 msgpack_pack_real_uint32(x
, d
);
592 msgpack_pack_real_uint64(x
, d
);
595 #elif defined(ULONG_MAX)
596 #if ULONG_MAX == 0xffffUL
597 msgpack_pack_real_uint16(x
, d
);
598 #elif ULONG_MAX == 0xffffffffUL
599 msgpack_pack_real_uint32(x
, d
);
601 msgpack_pack_real_uint64(x
, d
);
605 if(sizeof(unsigned long) == 2) {
606 msgpack_pack_real_uint16(x
, d
);
607 } else if(sizeof(unsigned long) == 4) {
608 msgpack_pack_real_uint32(x
, d
);
610 msgpack_pack_real_uint64(x
, d
);
615 msgpack_pack_inline_func_cint(_unsigned_long_long
)(msgpack_pack_user x
, unsigned long long d
)
617 #if defined(SIZEOF_LONG_LONG)
618 #if SIZEOF_LONG_LONG == 2
619 msgpack_pack_real_uint16(x
, d
);
620 #elif SIZEOF_LONG_LONG == 4
621 msgpack_pack_real_uint32(x
, d
);
623 msgpack_pack_real_uint64(x
, d
);
626 #elif defined(ULLONG_MAX)
627 #if ULLONG_MAX == 0xffffUL
628 msgpack_pack_real_uint16(x
, d
);
629 #elif ULLONG_MAX == 0xffffffffUL
630 msgpack_pack_real_uint32(x
, d
);
632 msgpack_pack_real_uint64(x
, d
);
636 if(sizeof(unsigned long long) == 2) {
637 msgpack_pack_real_uint16(x
, d
);
638 } else if(sizeof(unsigned long long) == 4) {
639 msgpack_pack_real_uint32(x
, d
);
641 msgpack_pack_real_uint64(x
, d
);
646 #undef msgpack_pack_inline_func_cint
655 msgpack_pack_inline_func(_float
)(msgpack_pack_user x
, float d
)
657 unsigned char buf
[5];
658 union { float f
; uint32_t i
; } mem
;
660 buf
[0] = 0xca; _msgpack_store32(&buf
[1], mem
.i
);
661 msgpack_pack_append_buffer(x
, buf
, 5);
664 msgpack_pack_inline_func(_double
)(msgpack_pack_user x
, double d
)
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__) // arm-oabi
673 // https://github.com/msgpack/msgpack-perl/pull/1
674 mem
.i
= (mem
.i
& 0xFFFFFFFFUL
) << 32UL | (mem
.i
>> 32UL);
676 _msgpack_store64(&buf
[1], mem
.i
);
677 msgpack_pack_append_buffer(x
, buf
, 9);
685 msgpack_pack_inline_func(_nil
)(msgpack_pack_user x
)
687 static const unsigned char d
= 0xc0;
688 msgpack_pack_append_buffer(x
, &d
, 1);
696 msgpack_pack_inline_func(_true
)(msgpack_pack_user x
)
698 static const unsigned char d
= 0xc3;
699 msgpack_pack_append_buffer(x
, &d
, 1);
702 msgpack_pack_inline_func(_false
)(msgpack_pack_user x
)
704 static const unsigned char d
= 0xc2;
705 msgpack_pack_append_buffer(x
, &d
, 1);
713 msgpack_pack_inline_func(_array
)(msgpack_pack_user x
, size_t n
)
716 unsigned char d
= 0x90 | (uint8_t)n
;
717 msgpack_pack_append_buffer(x
, &d
, 1);
718 } else if(n
< 65536) {
719 unsigned char buf
[3];
720 buf
[0] = 0xdc; _msgpack_store16(&buf
[1], (uint16_t)n
);
721 msgpack_pack_append_buffer(x
, buf
, 3);
723 unsigned char buf
[5];
724 buf
[0] = 0xdd; _msgpack_store32(&buf
[1], (uint32_t)n
);
725 msgpack_pack_append_buffer(x
, buf
, 5);
734 msgpack_pack_inline_func(_map
)(msgpack_pack_user x
, size_t n
)
737 unsigned char d
= 0x80 | (uint8_t)n
;
738 msgpack_pack_append_buffer(x
, &TAKE8_8(d
), 1);
739 } else if(n
< 65536) {
740 unsigned char buf
[3];
741 buf
[0] = 0xde; _msgpack_store16(&buf
[1], (uint16_t)n
);
742 msgpack_pack_append_buffer(x
, buf
, 3);
744 unsigned char buf
[5];
745 buf
[0] = 0xdf; _msgpack_store32(&buf
[1], (uint32_t)n
);
746 msgpack_pack_append_buffer(x
, buf
, 5);
755 msgpack_pack_inline_func(_str
)(msgpack_pack_user x
, size_t l
)
758 unsigned char d
= 0xa0 | (uint8_t)l
;
759 msgpack_pack_append_buffer(x
, &TAKE8_8(d
), 1);
761 unsigned char buf
[2];
762 buf
[0] = 0xd9; buf
[1] = (uint8_t)l
;
763 msgpack_pack_append_buffer(x
, buf
, 2);
764 } else if(l
< 65536) {
765 unsigned char buf
[3];
766 buf
[0] = 0xda; _msgpack_store16(&buf
[1], (uint16_t)l
);
767 msgpack_pack_append_buffer(x
, buf
, 3);
769 unsigned char buf
[5];
770 buf
[0] = 0xdb; _msgpack_store32(&buf
[1], (uint32_t)l
);
771 msgpack_pack_append_buffer(x
, buf
, 5);
775 msgpack_pack_inline_func(_str_body
)(msgpack_pack_user x
, const void* b
, size_t l
)
777 msgpack_pack_append_buffer(x
, (const unsigned char*)b
, l
);
784 msgpack_pack_inline_func(_v4raw
)(msgpack_pack_user x
, size_t l
)
787 unsigned char d
= 0xa0 | (uint8_t)l
;
788 msgpack_pack_append_buffer(x
, &TAKE8_8(d
), 1);
789 } else if(l
< 65536) {
790 unsigned char buf
[3];
791 buf
[0] = 0xda; _msgpack_store16(&buf
[1], (uint16_t)l
);
792 msgpack_pack_append_buffer(x
, buf
, 3);
794 unsigned char buf
[5];
795 buf
[0] = 0xdb; _msgpack_store32(&buf
[1], (uint32_t)l
);
796 msgpack_pack_append_buffer(x
, buf
, 5);
800 msgpack_pack_inline_func(_v4raw_body
)(msgpack_pack_user x
, const void* b
, size_t l
)
802 msgpack_pack_append_buffer(x
, (const unsigned char*)b
, l
);
809 msgpack_pack_inline_func(_bin
)(msgpack_pack_user x
, size_t l
)
812 unsigned char buf
[2];
813 buf
[0] = 0xc4; buf
[1] = (uint8_t)l
;
814 msgpack_pack_append_buffer(x
, buf
, 2);
815 } else if(l
< 65536) {
816 unsigned char buf
[3];
817 buf
[0] = 0xc5; _msgpack_store16(&buf
[1], (uint16_t)l
);
818 msgpack_pack_append_buffer(x
, buf
, 3);
820 unsigned char buf
[5];
821 buf
[0] = 0xc6; _msgpack_store32(&buf
[1], (uint32_t)l
);
822 msgpack_pack_append_buffer(x
, buf
, 5);
826 msgpack_pack_inline_func(_bin_body
)(msgpack_pack_user x
, const void* b
, size_t l
)
828 msgpack_pack_append_buffer(x
, (const unsigned char*)b
, l
);
835 msgpack_pack_inline_func(_ext
)(msgpack_pack_user x
, size_t l
, int8_t type
)
839 unsigned char buf
[2];
841 buf
[1] = (unsigned char)type
;
842 msgpack_pack_append_buffer(x
, buf
, 2);
845 unsigned char buf
[2];
847 buf
[1] = (unsigned char)type
;
848 msgpack_pack_append_buffer(x
, buf
, 2);
851 unsigned char buf
[2];
853 buf
[1] = (unsigned char)type
;
854 msgpack_pack_append_buffer(x
, buf
, 2);
857 unsigned char buf
[2];
859 buf
[1] = (unsigned char)type
;
860 msgpack_pack_append_buffer(x
, buf
, 2);
863 unsigned char buf
[2];
865 buf
[1] = (unsigned char)type
;
866 msgpack_pack_append_buffer(x
, buf
, 2);
870 unsigned char buf
[3];
872 buf
[1] = (unsigned char)l
;
873 buf
[2] = (unsigned char)type
;
874 msgpack_pack_append_buffer(x
, buf
, 3);
875 } else if(l
< 65536) {
876 unsigned char buf
[4];
878 _msgpack_store16(&buf
[1], l
);
879 buf
[3] = (unsigned char)type
;
880 msgpack_pack_append_buffer(x
, buf
, 4);
882 unsigned char buf
[6];
884 _msgpack_store32(&buf
[1], l
);
885 buf
[5] = (unsigned char)type
;
886 msgpack_pack_append_buffer(x
, buf
, 6);
892 msgpack_pack_inline_func(_ext_body
)(msgpack_pack_user x
, const void* b
, size_t l
)
894 msgpack_pack_append_buffer(x
, (const unsigned char*)b
, l
);
897 msgpack_pack_inline_func(_timestamp
)(msgpack_pack_user x
, const msgpack_timestamp
* d
)
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);
906 _msgpack_store32(buf
, data32
);
907 msgpack_pack_append_buffer(x
, buf
, 4);
911 msgpack_pack_ext(x
, 8, -1);
912 _msgpack_store64(buf
, data64
);
913 msgpack_pack_append_buffer(x
, buf
, 8);
918 _msgpack_store32(&buf
[0], d
->tv_nsec
);
919 _msgpack_store64(&buf
[4], d
->tv_sec
);
920 msgpack_pack_ext(x
, 12, -1);
921 msgpack_pack_append_buffer(x
, buf
, 12);
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
943 #if defined(_MSC_VER)
944 # pragma warning(pop)
This page took 0.049146 seconds and 4 git commands to generate.