MessagePack for C
pack_template.h
Go to the documentation of this file.
1 /*
2  * MessagePack packing routine template
3  *
4  * Copyright (C) 2008-2010 FURUHASHI Sadayuki
5  *
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)
9  */
10 
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]
21 #else
22 #error msgpack-c supports only big endian and little endian
23 #endif
24 
25 #ifndef msgpack_pack_inline_func
26 #error msgpack_pack_inline_func template is not defined
27 #endif
28 
29 #ifndef msgpack_pack_user
30 #error msgpack_pack_user type is not defined
31 #endif
32 
33 #ifndef msgpack_pack_append_buffer
34 #error msgpack_pack_append_buffer callback is not defined
35 #endif
36 
37 
38 /*
39  * Integer
40  */
41 
42 #define msgpack_pack_real_uint8(x, d) \
43 do { \
44  if(d < (1<<7)) { \
45  /* fixnum */ \
46  msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
47  } else { \
48  /* unsigned 8 */ \
49  unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
50  msgpack_pack_append_buffer(x, buf, 2); \
51  } \
52 } while(0)
53 
54 #define msgpack_pack_real_uint16(x, d) \
55 do { \
56  if(d < (1<<7)) { \
57  /* fixnum */ \
58  msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
59  } else if(d < (1<<8)) { \
60  /* unsigned 8 */ \
61  unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
62  msgpack_pack_append_buffer(x, buf, 2); \
63  } else { \
64  /* unsigned 16 */ \
65  unsigned char buf[3]; \
66  buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
67  msgpack_pack_append_buffer(x, buf, 3); \
68  } \
69 } while(0)
70 
71 #define msgpack_pack_real_uint32(x, d) \
72 do { \
73  if(d < (1<<8)) { \
74  if(d < (1<<7)) { \
75  /* fixnum */ \
76  msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
77  } else { \
78  /* unsigned 8 */ \
79  unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
80  msgpack_pack_append_buffer(x, buf, 2); \
81  } \
82  } else { \
83  if(d < (1<<16)) { \
84  /* unsigned 16 */ \
85  unsigned char buf[3]; \
86  buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
87  msgpack_pack_append_buffer(x, buf, 3); \
88  } else { \
89  /* unsigned 32 */ \
90  unsigned char buf[5]; \
91  buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
92  msgpack_pack_append_buffer(x, buf, 5); \
93  } \
94  } \
95 } while(0)
96 
97 #define msgpack_pack_real_uint64(x, d) \
98 do { \
99  if(d < (1ULL<<8)) { \
100  if(d < (1ULL<<7)) { \
101  /* fixnum */ \
102  msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
103  } else { \
104  /* unsigned 8 */ \
105  unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
106  msgpack_pack_append_buffer(x, buf, 2); \
107  } \
108  } else { \
109  if(d < (1ULL<<16)) { \
110  /* unsigned 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)) { \
115  /* unsigned 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); \
119  } else { \
120  /* unsigned 64 */ \
121  unsigned char buf[9]; \
122  buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
123  msgpack_pack_append_buffer(x, buf, 9); \
124  } \
125  } \
126 } while(0)
127 
128 #define msgpack_pack_real_int8(x, d) \
129 do { \
130  if(d < -(1<<5)) { \
131  /* signed 8 */ \
132  unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
133  msgpack_pack_append_buffer(x, buf, 2); \
134  } else { \
135  /* fixnum */ \
136  msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
137  } \
138 } while(0)
139 
140 #define msgpack_pack_real_int16(x, d) \
141 do { \
142  if(d < -(1<<5)) { \
143  if(d < -(1<<7)) { \
144  /* signed 16 */ \
145  unsigned char buf[3]; \
146  buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
147  msgpack_pack_append_buffer(x, buf, 3); \
148  } else { \
149  /* signed 8 */ \
150  unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
151  msgpack_pack_append_buffer(x, buf, 2); \
152  } \
153  } else if(d < (1<<7)) { \
154  /* fixnum */ \
155  msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
156  } else { \
157  if(d < (1<<8)) { \
158  /* unsigned 8 */ \
159  unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
160  msgpack_pack_append_buffer(x, buf, 2); \
161  } else { \
162  /* unsigned 16 */ \
163  unsigned char buf[3]; \
164  buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
165  msgpack_pack_append_buffer(x, buf, 3); \
166  } \
167  } \
168 } while(0)
169 
170 #define msgpack_pack_real_int32(x, d) \
171 do { \
172  if(d < -(1<<5)) { \
173  if(d < -(1<<15)) { \
174  /* signed 32 */ \
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)) { \
179  /* signed 16 */ \
180  unsigned char buf[3]; \
181  buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
182  msgpack_pack_append_buffer(x, buf, 3); \
183  } else { \
184  /* signed 8 */ \
185  unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
186  msgpack_pack_append_buffer(x, buf, 2); \
187  } \
188  } else if(d < (1<<7)) { \
189  /* fixnum */ \
190  msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
191  } else { \
192  if(d < (1<<8)) { \
193  /* unsigned 8 */ \
194  unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
195  msgpack_pack_append_buffer(x, buf, 2); \
196  } else if(d < (1<<16)) { \
197  /* unsigned 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); \
201  } else { \
202  /* unsigned 32 */ \
203  unsigned char buf[5]; \
204  buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
205  msgpack_pack_append_buffer(x, buf, 5); \
206  } \
207  } \
208 } while(0)
209 
210 #define msgpack_pack_real_int64(x, d) \
211 do { \
212  if(d < -(1LL<<5)) { \
213  if(d < -(1LL<<15)) { \
214  if(d < -(1LL<<31)) { \
215  /* signed 64 */ \
216  unsigned char buf[9]; \
217  buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
218  msgpack_pack_append_buffer(x, buf, 9); \
219  } else { \
220  /* signed 32 */ \
221  unsigned char buf[5]; \
222  buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
223  msgpack_pack_append_buffer(x, buf, 5); \
224  } \
225  } else { \
226  if(d < -(1<<7)) { \
227  /* signed 16 */ \
228  unsigned char buf[3]; \
229  buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
230  msgpack_pack_append_buffer(x, buf, 3); \
231  } else { \
232  /* signed 8 */ \
233  unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
234  msgpack_pack_append_buffer(x, buf, 2); \
235  } \
236  } \
237  } else if(d < (1<<7)) { \
238  /* fixnum */ \
239  msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
240  } else { \
241  if(d < (1LL<<16)) { \
242  if(d < (1<<8)) { \
243  /* unsigned 8 */ \
244  unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
245  msgpack_pack_append_buffer(x, buf, 2); \
246  } else { \
247  /* unsigned 16 */ \
248  unsigned char buf[3]; \
249  buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
250  msgpack_pack_append_buffer(x, buf, 3); \
251  } \
252  } else { \
253  if(d < (1LL<<32)) { \
254  /* unsigned 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); \
258  } else { \
259  /* unsigned 64 */ \
260  unsigned char buf[9]; \
261  buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
262  msgpack_pack_append_buffer(x, buf, 9); \
263  } \
264  } \
265  } \
266 } while(0)
267 
268 
269 #ifdef msgpack_pack_inline_func_fixint
270 
272 {
273  unsigned char buf[2] = {0xcc, TAKE8_8(d)};
274  msgpack_pack_append_buffer(x, buf, 2);
275 }
276 
278 {
279  unsigned char buf[3];
280  buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
281  msgpack_pack_append_buffer(x, buf, 3);
282 }
283 
285 {
286  unsigned char buf[5];
287  buf[0] = 0xce; _msgpack_store32(&buf[1], d);
288  msgpack_pack_append_buffer(x, buf, 5);
289 }
290 
292 {
293  unsigned char buf[9];
294  buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
295  msgpack_pack_append_buffer(x, buf, 9);
296 }
297 
299 {
300  unsigned char buf[2] = {0xd0, TAKE8_8(d)};
301  msgpack_pack_append_buffer(x, buf, 2);
302 }
303 
305 {
306  unsigned char buf[3];
307  buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
308  msgpack_pack_append_buffer(x, buf, 3);
309 }
310 
312 {
313  unsigned char buf[5];
314  buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
315  msgpack_pack_append_buffer(x, buf, 5);
316 }
317 
319 {
320  unsigned char buf[9];
321  buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
322  msgpack_pack_append_buffer(x, buf, 9);
323 }
324 
325 #undef msgpack_pack_inline_func_fixint
326 #endif
327 
328 
330 {
332 }
333 
335 {
337 }
338 
340 {
342 }
343 
345 {
347 }
348 
350 {
352 }
353 
355 {
357 }
358 
360 {
362 }
363 
365 {
367 }
368 
370 {
371 #if defined(CHAR_MIN)
372 #if CHAR_MIN < 0
374 #else
376 #endif
377 #else
378 #error CHAR_MIN is not defined
379 #endif
380 }
381 
383 {
385 }
386 
388 {
390 }
391 
392 #ifdef msgpack_pack_inline_func_cint
393 
395 {
396 #if defined(SIZEOF_SHORT)
397 #if SIZEOF_SHORT == 2
399 #elif SIZEOF_SHORT == 4
401 #else
403 #endif
404 
405 #elif defined(SHRT_MAX)
406 #if SHRT_MAX == 0x7fff
408 #elif SHRT_MAX == 0x7fffffff
410 #else
412 #endif
413 
414 #else
415 if(sizeof(short) == 2) {
417 } else if(sizeof(short) == 4) {
419 } else {
421 }
422 #endif
423 }
424 
426 {
427 #if defined(SIZEOF_INT)
428 #if SIZEOF_INT == 2
430 #elif SIZEOF_INT == 4
432 #else
434 #endif
435 
436 #elif defined(INT_MAX)
437 #if INT_MAX == 0x7fff
439 #elif INT_MAX == 0x7fffffff
441 #else
443 #endif
444 
445 #else
446 if(sizeof(int) == 2) {
448 } else if(sizeof(int) == 4) {
450 } else {
452 }
453 #endif
454 }
455 
457 {
458 #if defined(SIZEOF_LONG)
459 #if SIZEOF_LONG == 2
461 #elif SIZEOF_LONG == 4
463 #else
465 #endif
466 
467 #elif defined(LONG_MAX)
468 #if LONG_MAX == 0x7fffL
470 #elif LONG_MAX == 0x7fffffffL
472 #else
474 #endif
475 
476 #else
477 if(sizeof(long) == 2) {
479 } else if(sizeof(long) == 4) {
481 } else {
483 }
484 #endif
485 }
486 
487 msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d)
488 {
489 #if defined(SIZEOF_LONG_LONG)
490 #if SIZEOF_LONG_LONG == 2
492 #elif SIZEOF_LONG_LONG == 4
494 #else
496 #endif
497 
498 #elif defined(LLONG_MAX)
499 #if LLONG_MAX == 0x7fffL
501 #elif LLONG_MAX == 0x7fffffffL
503 #else
505 #endif
506 
507 #else
508 if(sizeof(long long) == 2) {
510 } else if(sizeof(long long) == 4) {
512 } else {
514 }
515 #endif
516 }
517 
518 msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d)
519 {
520 #if defined(SIZEOF_SHORT)
521 #if SIZEOF_SHORT == 2
523 #elif SIZEOF_SHORT == 4
525 #else
527 #endif
528 
529 #elif defined(USHRT_MAX)
530 #if USHRT_MAX == 0xffffU
532 #elif USHRT_MAX == 0xffffffffU
534 #else
536 #endif
537 
538 #else
539 if(sizeof(unsigned short) == 2) {
541 } else if(sizeof(unsigned short) == 4) {
543 } else {
545 }
546 #endif
547 }
548 
549 msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d)
550 {
551 #if defined(SIZEOF_INT)
552 #if SIZEOF_INT == 2
554 #elif SIZEOF_INT == 4
556 #else
558 #endif
559 
560 #elif defined(UINT_MAX)
561 #if UINT_MAX == 0xffffU
563 #elif UINT_MAX == 0xffffffffU
565 #else
567 #endif
568 
569 #else
570 if(sizeof(unsigned int) == 2) {
572 } else if(sizeof(unsigned int) == 4) {
574 } else {
576 }
577 #endif
578 }
579 
580 msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d)
581 {
582 #if defined(SIZEOF_LONG)
583 #if SIZEOF_LONG == 2
585 #elif SIZEOF_LONG == 4
587 #else
589 #endif
590 
591 #elif defined(ULONG_MAX)
592 #if ULONG_MAX == 0xffffUL
594 #elif ULONG_MAX == 0xffffffffUL
596 #else
598 #endif
599 
600 #else
601 if(sizeof(unsigned long) == 2) {
603 } else if(sizeof(unsigned long) == 4) {
605 } else {
607 }
608 #endif
609 }
610 
611 msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
612 {
613 #if defined(SIZEOF_LONG_LONG)
614 #if SIZEOF_LONG_LONG == 2
616 #elif SIZEOF_LONG_LONG == 4
618 #else
620 #endif
621 
622 #elif defined(ULLONG_MAX)
623 #if ULLONG_MAX == 0xffffUL
625 #elif ULLONG_MAX == 0xffffffffUL
627 #else
629 #endif
630 
631 #else
632 if(sizeof(unsigned long long) == 2) {
634 } else if(sizeof(unsigned long long) == 4) {
636 } else {
638 }
639 #endif
640 }
641 
642 #undef msgpack_pack_inline_func_cint
643 #endif
644 
645 
646 
647 /*
648  * Float
649  */
650 
652 {
653  unsigned char buf[5];
654  union { float f; uint32_t i; } mem;
655  mem.f = d;
656  buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
657  msgpack_pack_append_buffer(x, buf, 5);
658 }
659 
661 {
662  unsigned char buf[9];
663  union { double f; uint64_t i; } mem;
664  mem.f = d;
665  buf[0] = 0xcb;
666 #if defined(TARGET_OS_IPHONE)
667  // ok
668 #elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi
669  // https://github.com/msgpack/msgpack-perl/pull/1
670  mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
671 #endif
672  _msgpack_store64(&buf[1], mem.i);
673  msgpack_pack_append_buffer(x, buf, 9);
674 }
675 
676 
677 /*
678  * Nil
679  */
680 
682 {
683  static const unsigned char d = 0xc0;
684  msgpack_pack_append_buffer(x, &d, 1);
685 }
686 
687 
688 /*
689  * Boolean
690  */
691 
693 {
694  static const unsigned char d = 0xc3;
695  msgpack_pack_append_buffer(x, &d, 1);
696 }
697 
699 {
700  static const unsigned char d = 0xc2;
701  msgpack_pack_append_buffer(x, &d, 1);
702 }
703 
704 
705 /*
706  * Array
707  */
708 
710 {
711  if(n < 16) {
712  unsigned char d = 0x90 | (uint8_t)n;
713  msgpack_pack_append_buffer(x, &d, 1);
714  } else if(n < 65536) {
715  unsigned char buf[3];
716  buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n);
717  msgpack_pack_append_buffer(x, buf, 3);
718  } else {
719  unsigned char buf[5];
720  buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
721  msgpack_pack_append_buffer(x, buf, 5);
722  }
723 }
724 
725 
726 /*
727  * Map
728  */
729 
731 {
732  if(n < 16) {
733  unsigned char d = 0x80 | (uint8_t)n;
734  msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
735  } else if(n < 65536) {
736  unsigned char buf[3];
737  buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n);
738  msgpack_pack_append_buffer(x, buf, 3);
739  } else {
740  unsigned char buf[5];
741  buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
742  msgpack_pack_append_buffer(x, buf, 5);
743  }
744 }
745 
746 
747 /*
748  * Str
749  */
750 
752 {
753  if(l < 32) {
754  unsigned char d = 0xa0 | (uint8_t)l;
755  msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
756  } else if(l < 256) {
757  unsigned char buf[2];
758  buf[0] = 0xd9; buf[1] = (uint8_t)l;
759  msgpack_pack_append_buffer(x, buf, 2);
760  } else if(l < 65536) {
761  unsigned char buf[3];
762  buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
763  msgpack_pack_append_buffer(x, buf, 3);
764  } else {
765  unsigned char buf[5];
766  buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
767  msgpack_pack_append_buffer(x, buf, 5);
768  }
769 }
770 
772 {
773  msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
774 }
775 
776 /*
777  * Raw (V4)
778  */
779 
781 {
782  if(l < 32) {
783  unsigned char d = 0xa0 | (uint8_t)l;
784  msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
785  } else if(l < 65536) {
786  unsigned char buf[3];
787  buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
788  msgpack_pack_append_buffer(x, buf, 3);
789  } else {
790  unsigned char buf[5];
791  buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
792  msgpack_pack_append_buffer(x, buf, 5);
793  }
794 }
795 
797 {
798  msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
799 }
800 
801 /*
802  * Bin
803  */
804 
806 {
807  if(l < 256) {
808  unsigned char buf[2];
809  buf[0] = 0xc4; buf[1] = (uint8_t)l;
810  msgpack_pack_append_buffer(x, buf, 2);
811  } else if(l < 65536) {
812  unsigned char buf[3];
813  buf[0] = 0xc5; _msgpack_store16(&buf[1], (uint16_t)l);
814  msgpack_pack_append_buffer(x, buf, 3);
815  } else {
816  unsigned char buf[5];
817  buf[0] = 0xc6; _msgpack_store32(&buf[1], (uint32_t)l);
818  msgpack_pack_append_buffer(x, buf, 5);
819  }
820 }
821 
823 {
824  msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
825 }
826 
827 /*
828  * Ext
829  */
830 
832 {
833  switch(l) {
834  case 1: {
835  unsigned char buf[2];
836  buf[0] = 0xd4;
837  buf[1] = type;
838  msgpack_pack_append_buffer(x, buf, 2);
839  } break;
840  case 2: {
841  unsigned char buf[2];
842  buf[0] = 0xd5;
843  buf[1] = type;
844  msgpack_pack_append_buffer(x, buf, 2);
845  } break;
846  case 4: {
847  unsigned char buf[2];
848  buf[0] = 0xd6;
849  buf[1] = type;
850  msgpack_pack_append_buffer(x, buf, 2);
851  } break;
852  case 8: {
853  unsigned char buf[2];
854  buf[0] = 0xd7;
855  buf[1] = type;
856  msgpack_pack_append_buffer(x, buf, 2);
857  } break;
858  case 16: {
859  unsigned char buf[2];
860  buf[0] = 0xd8;
861  buf[1] = type;
862  msgpack_pack_append_buffer(x, buf, 2);
863  } break;
864  default:
865  if(l < 256) {
866  unsigned char buf[3];
867  buf[0] = 0xc7;
868  buf[1] = (unsigned char)l;
869  buf[2] = type;
870  msgpack_pack_append_buffer(x, buf, 3);
871  } else if(l < 65536) {
872  unsigned char buf[4];
873  buf[0] = 0xc8;
874  _msgpack_store16(&buf[1], l);
875  buf[3] = type;
876  msgpack_pack_append_buffer(x, buf, 4);
877  } else {
878  unsigned char buf[6];
879  buf[0] = 0xc9;
880  _msgpack_store32(&buf[1], l);
881  buf[5] = type;
882  msgpack_pack_append_buffer(x, buf, 6);
883  }
884  break;
885  }
886 }
887 
889 {
890  msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
891 }
892 
893 #undef msgpack_pack_inline_func
894 #undef msgpack_pack_user
895 #undef msgpack_pack_append_buffer
896 
897 #undef TAKE8_8
898 #undef TAKE8_16
899 #undef TAKE8_32
900 #undef TAKE8_64
901 
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() _double(msgpack_pack_user x, double d)
Definition: pack_template.h:660
#define msgpack_pack_inline_func_fixint(name)
Definition: pack.h:113
#define msgpack_pack_real_int8(x, d)
Definition: pack_template.h:128
msgpack_pack_inline_func() _int16(msgpack_pack_user x, int16_t d)
Definition: pack_template.h:354
#define msgpack_pack_real_int16(x, d)
Definition: pack_template.h:140
msgpack_pack_inline_func() _bin_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:822
msgpack_pack_inline_func() _uint8(msgpack_pack_user x, uint8_t d)
Definition: pack_template.h:329
msgpack_pack_inline_func() _ext(msgpack_pack_user x, size_t l, int8_t type)
Definition: pack_template.h:831
#define msgpack_pack_real_int64(x, d)
Definition: pack_template.h:210
msgpack_pack_inline_func() _int8(msgpack_pack_user x, int8_t d)
Definition: pack_template.h:349
#define msgpack_pack_inline_func_cint(name)
Definition: pack.h:110
msgpack_pack_inline_func() _v4raw(msgpack_pack_user x, size_t l)
Definition: pack_template.h:780
msgpack_pack_inline_func() _unsigned_char(msgpack_pack_user x, unsigned char d)
Definition: pack_template.h:387
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() _bin(msgpack_pack_user x, size_t l)
Definition: pack_template.h:805
#define msgpack_pack_real_int32(x, d)
Definition: pack_template.h:170
#define msgpack_pack_real_uint32(x, d)
Definition: pack_template.h:71
const void * n
Definition: unpack_template.h:95
msgpack_pack_inline_func() _uint32(msgpack_pack_user x, uint32_t d)
Definition: pack_template.h:339
msgpack_pack_inline_func() _char(msgpack_pack_user x, char d)
Definition: pack_template.h:369
msgpack_pack_inline_func() _false(msgpack_pack_user x)
Definition: pack_template.h:698
msgpack_pack_inline_func() _nil(msgpack_pack_user x)
Definition: pack_template.h:681
msgpack_pack_inline_func() _true(msgpack_pack_user x)
Definition: pack_template.h:692
#define msgpack_pack_real_uint16(x, d)
Definition: pack_template.h:54
#define msgpack_pack_real_uint64(x, d)
Definition: pack_template.h:97
#define _msgpack_store64(to, num)
Definition: sysdep.h:167
#define _msgpack_store32(to, num)
Definition: sysdep.h:165
msgpack_pack_inline_func() _uint16(msgpack_pack_user x, uint16_t d)
Definition: pack_template.h:334
msgpack_pack_inline_func() _array(msgpack_pack_user x, size_t n)
Definition: pack_template.h:709
msgpack_pack_inline_func() _int32(msgpack_pack_user x, int32_t d)
Definition: pack_template.h:359
msgpack_pack_inline_func() _uint64(msgpack_pack_user x, uint64_t d)
Definition: pack_template.h:344
msgpack_pack_inline_func() _map(msgpack_pack_user x, size_t n)
Definition: pack_template.h:730
#define msgpack_pack_user
Definition: pack.h:116
msgpack_pack_inline_func() _str_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:771
msgpack_pack_inline_func() _int64(msgpack_pack_user x, int64_t d)
Definition: pack_template.h:364
msgpack_pack_inline_func() _v4raw_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:796
#define msgpack_pack_append_buffer(user, buf, len)
Definition: pack.h:118
#define msgpack_pack_inline_func(name)
Definition: pack.h:107
#define _msgpack_store16(to, num)
Definition: sysdep.h:163
msgpack_pack_inline_func() _str(msgpack_pack_user x, size_t l)
Definition: pack_template.h:751
msgpack_pack_inline_func() _float(msgpack_pack_user x, float d)
Definition: pack_template.h:651
#define msgpack_pack_real_uint8(x, d)
Definition: pack_template.h:42
msgpack_pack_inline_func() _signed_char(msgpack_pack_user x, signed char d)
Definition: pack_template.h:382