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 #if defined(_MSC_VER)
38 # pragma warning(push)
39 # pragma warning(disable : 4204) /* nonstandard extension used: non-constant aggregate initializer */
40 #endif
41 
42 /*
43  * Integer
44  */
45 
46 #define msgpack_pack_real_uint8(x, d) \
47 do { \
48  if(d < (1<<7)) { \
49  /* fixnum */ \
50  msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
51  } else { \
52  /* unsigned 8 */ \
53  unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
54  msgpack_pack_append_buffer(x, buf, 2); \
55  } \
56 } while(0)
57 
58 #define msgpack_pack_real_uint16(x, d) \
59 do { \
60  if(d < (1<<7)) { \
61  /* fixnum */ \
62  msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
63  } else if(d < (1<<8)) { \
64  /* unsigned 8 */ \
65  unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
66  msgpack_pack_append_buffer(x, buf, 2); \
67  } else { \
68  /* unsigned 16 */ \
69  unsigned char buf[3]; \
70  buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
71  msgpack_pack_append_buffer(x, buf, 3); \
72  } \
73 } while(0)
74 
75 #define msgpack_pack_real_uint32(x, d) \
76 do { \
77  if(d < (1<<8)) { \
78  if(d < (1<<7)) { \
79  /* fixnum */ \
80  msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
81  } else { \
82  /* unsigned 8 */ \
83  unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
84  msgpack_pack_append_buffer(x, buf, 2); \
85  } \
86  } else { \
87  if(d < (1<<16)) { \
88  /* unsigned 16 */ \
89  unsigned char buf[3]; \
90  buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
91  msgpack_pack_append_buffer(x, buf, 3); \
92  } else { \
93  /* unsigned 32 */ \
94  unsigned char buf[5]; \
95  buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
96  msgpack_pack_append_buffer(x, buf, 5); \
97  } \
98  } \
99 } while(0)
100 
101 #define msgpack_pack_real_uint64(x, d) \
102 do { \
103  if(d < (1ULL<<8)) { \
104  if(d < (1ULL<<7)) { \
105  /* fixnum */ \
106  msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
107  } else { \
108  /* unsigned 8 */ \
109  unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
110  msgpack_pack_append_buffer(x, buf, 2); \
111  } \
112  } else { \
113  if(d < (1ULL<<16)) { \
114  /* unsigned 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)) { \
119  /* unsigned 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); \
123  } else { \
124  /* unsigned 64 */ \
125  unsigned char buf[9]; \
126  buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
127  msgpack_pack_append_buffer(x, buf, 9); \
128  } \
129  } \
130 } while(0)
131 
132 #define msgpack_pack_real_int8(x, d) \
133 do { \
134  if(d < -(1<<5)) { \
135  /* signed 8 */ \
136  unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
137  msgpack_pack_append_buffer(x, buf, 2); \
138  } else { \
139  /* fixnum */ \
140  msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
141  } \
142 } while(0)
143 
144 #define msgpack_pack_real_int16(x, d) \
145 do { \
146  if(d < -(1<<5)) { \
147  if(d < -(1<<7)) { \
148  /* signed 16 */ \
149  unsigned char buf[3]; \
150  buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
151  msgpack_pack_append_buffer(x, buf, 3); \
152  } else { \
153  /* signed 8 */ \
154  unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
155  msgpack_pack_append_buffer(x, buf, 2); \
156  } \
157  } else if(d < (1<<7)) { \
158  /* fixnum */ \
159  msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
160  } else { \
161  if(d < (1<<8)) { \
162  /* unsigned 8 */ \
163  unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
164  msgpack_pack_append_buffer(x, buf, 2); \
165  } else { \
166  /* unsigned 16 */ \
167  unsigned char buf[3]; \
168  buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
169  msgpack_pack_append_buffer(x, buf, 3); \
170  } \
171  } \
172 } while(0)
173 
174 #define msgpack_pack_real_int32(x, d) \
175 do { \
176  if(d < -(1<<5)) { \
177  if(d < -(1<<15)) { \
178  /* signed 32 */ \
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)) { \
183  /* signed 16 */ \
184  unsigned char buf[3]; \
185  buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
186  msgpack_pack_append_buffer(x, buf, 3); \
187  } else { \
188  /* signed 8 */ \
189  unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
190  msgpack_pack_append_buffer(x, buf, 2); \
191  } \
192  } else if(d < (1<<7)) { \
193  /* fixnum */ \
194  msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
195  } else { \
196  if(d < (1<<8)) { \
197  /* unsigned 8 */ \
198  unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
199  msgpack_pack_append_buffer(x, buf, 2); \
200  } else if(d < (1<<16)) { \
201  /* unsigned 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); \
205  } else { \
206  /* unsigned 32 */ \
207  unsigned char buf[5]; \
208  buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
209  msgpack_pack_append_buffer(x, buf, 5); \
210  } \
211  } \
212 } while(0)
213 
214 #define msgpack_pack_real_int64(x, d) \
215 do { \
216  if(d < -(1LL<<5)) { \
217  if(d < -(1LL<<15)) { \
218  if(d < -(1LL<<31)) { \
219  /* signed 64 */ \
220  unsigned char buf[9]; \
221  buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
222  msgpack_pack_append_buffer(x, buf, 9); \
223  } else { \
224  /* signed 32 */ \
225  unsigned char buf[5]; \
226  buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
227  msgpack_pack_append_buffer(x, buf, 5); \
228  } \
229  } else { \
230  if(d < -(1<<7)) { \
231  /* signed 16 */ \
232  unsigned char buf[3]; \
233  buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
234  msgpack_pack_append_buffer(x, buf, 3); \
235  } else { \
236  /* signed 8 */ \
237  unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
238  msgpack_pack_append_buffer(x, buf, 2); \
239  } \
240  } \
241  } else if(d < (1<<7)) { \
242  /* fixnum */ \
243  msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
244  } else { \
245  if(d < (1LL<<16)) { \
246  if(d < (1<<8)) { \
247  /* unsigned 8 */ \
248  unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
249  msgpack_pack_append_buffer(x, buf, 2); \
250  } else { \
251  /* unsigned 16 */ \
252  unsigned char buf[3]; \
253  buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
254  msgpack_pack_append_buffer(x, buf, 3); \
255  } \
256  } else { \
257  if(d < (1LL<<32)) { \
258  /* unsigned 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); \
262  } else { \
263  /* unsigned 64 */ \
264  unsigned char buf[9]; \
265  buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
266  msgpack_pack_append_buffer(x, buf, 9); \
267  } \
268  } \
269  } \
270 } while(0)
271 
272 
273 #ifdef msgpack_pack_inline_func_fixint
274 
276 {
277  unsigned char buf[2] = {0xcc, TAKE8_8(d)};
278  msgpack_pack_append_buffer(x, buf, 2);
279 }
280 
282 {
283  unsigned char buf[3];
284  buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
285  msgpack_pack_append_buffer(x, buf, 3);
286 }
287 
289 {
290  unsigned char buf[5];
291  buf[0] = 0xce; _msgpack_store32(&buf[1], d);
292  msgpack_pack_append_buffer(x, buf, 5);
293 }
294 
296 {
297  unsigned char buf[9];
298  buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
299  msgpack_pack_append_buffer(x, buf, 9);
300 }
301 
303 {
304  unsigned char buf[2] = {0xd0, TAKE8_8(d)};
305  msgpack_pack_append_buffer(x, buf, 2);
306 }
307 
309 {
310  unsigned char buf[3];
311  buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
312  msgpack_pack_append_buffer(x, buf, 3);
313 }
314 
316 {
317  unsigned char buf[5];
318  buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
319  msgpack_pack_append_buffer(x, buf, 5);
320 }
321 
323 {
324  unsigned char buf[9];
325  buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
326  msgpack_pack_append_buffer(x, buf, 9);
327 }
328 
329 #undef msgpack_pack_inline_func_fixint
330 #endif
331 
332 
334 {
336 }
337 
339 {
341 }
342 
344 {
346 }
347 
349 {
351 }
352 
354 {
356 }
357 
359 {
361 }
362 
364 {
366 }
367 
369 {
371 }
372 
374 {
375 #if defined(CHAR_MIN)
376 #if CHAR_MIN < 0
378 #else
380 #endif
381 #else
382 #error CHAR_MIN is not defined
383 #endif
384 }
385 
387 {
389 }
390 
392 {
394 }
395 
396 #ifdef msgpack_pack_inline_func_cint
397 
399 {
400 #if defined(SIZEOF_SHORT)
401 #if SIZEOF_SHORT == 2
403 #elif SIZEOF_SHORT == 4
405 #else
407 #endif
408 
409 #elif defined(SHRT_MAX)
410 #if SHRT_MAX == 0x7fff
412 #elif SHRT_MAX == 0x7fffffff
414 #else
416 #endif
417 
418 #else
419 if(sizeof(short) == 2) {
421 } else if(sizeof(short) == 4) {
423 } else {
425 }
426 #endif
427 }
428 
430 {
431 #if defined(SIZEOF_INT)
432 #if SIZEOF_INT == 2
434 #elif SIZEOF_INT == 4
436 #else
438 #endif
439 
440 #elif defined(INT_MAX)
441 #if INT_MAX == 0x7fff
443 #elif INT_MAX == 0x7fffffff
445 #else
447 #endif
448 
449 #else
450 if(sizeof(int) == 2) {
452 } else if(sizeof(int) == 4) {
454 } else {
456 }
457 #endif
458 }
459 
461 {
462 #if defined(SIZEOF_LONG)
463 #if SIZEOF_LONG == 2
465 #elif SIZEOF_LONG == 4
467 #else
469 #endif
470 
471 #elif defined(LONG_MAX)
472 #if LONG_MAX == 0x7fffL
474 #elif LONG_MAX == 0x7fffffffL
476 #else
478 #endif
479 
480 #else
481 if(sizeof(long) == 2) {
483 } else if(sizeof(long) == 4) {
485 } else {
487 }
488 #endif
489 }
490 
491 msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d)
492 {
493 #if defined(SIZEOF_LONG_LONG)
494 #if SIZEOF_LONG_LONG == 2
496 #elif SIZEOF_LONG_LONG == 4
498 #else
500 #endif
501 
502 #elif defined(LLONG_MAX)
503 #if LLONG_MAX == 0x7fffL
505 #elif LLONG_MAX == 0x7fffffffL
507 #else
509 #endif
510 
511 #else
512 if(sizeof(long long) == 2) {
514 } else if(sizeof(long long) == 4) {
516 } else {
518 }
519 #endif
520 }
521 
522 msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d)
523 {
524 #if defined(SIZEOF_SHORT)
525 #if SIZEOF_SHORT == 2
527 #elif SIZEOF_SHORT == 4
529 #else
531 #endif
532 
533 #elif defined(USHRT_MAX)
534 #if USHRT_MAX == 0xffffU
536 #elif USHRT_MAX == 0xffffffffU
538 #else
540 #endif
541 
542 #else
543 if(sizeof(unsigned short) == 2) {
545 } else if(sizeof(unsigned short) == 4) {
547 } else {
549 }
550 #endif
551 }
552 
553 msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d)
554 {
555 #if defined(SIZEOF_INT)
556 #if SIZEOF_INT == 2
558 #elif SIZEOF_INT == 4
560 #else
562 #endif
563 
564 #elif defined(UINT_MAX)
565 #if UINT_MAX == 0xffffU
567 #elif UINT_MAX == 0xffffffffU
569 #else
571 #endif
572 
573 #else
574 if(sizeof(unsigned int) == 2) {
576 } else if(sizeof(unsigned int) == 4) {
578 } else {
580 }
581 #endif
582 }
583 
584 msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d)
585 {
586 #if defined(SIZEOF_LONG)
587 #if SIZEOF_LONG == 2
589 #elif SIZEOF_LONG == 4
591 #else
593 #endif
594 
595 #elif defined(ULONG_MAX)
596 #if ULONG_MAX == 0xffffUL
598 #elif ULONG_MAX == 0xffffffffUL
600 #else
602 #endif
603 
604 #else
605 if(sizeof(unsigned long) == 2) {
607 } else if(sizeof(unsigned long) == 4) {
609 } else {
611 }
612 #endif
613 }
614 
615 msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
616 {
617 #if defined(SIZEOF_LONG_LONG)
618 #if SIZEOF_LONG_LONG == 2
620 #elif SIZEOF_LONG_LONG == 4
622 #else
624 #endif
625 
626 #elif defined(ULLONG_MAX)
627 #if ULLONG_MAX == 0xffffUL
629 #elif ULLONG_MAX == 0xffffffffUL
631 #else
633 #endif
634 
635 #else
636 if(sizeof(unsigned long long) == 2) {
638 } else if(sizeof(unsigned long long) == 4) {
640 } else {
642 }
643 #endif
644 }
645 
646 #undef msgpack_pack_inline_func_cint
647 #endif
648 
649 
650 
651 /*
652  * Float
653  */
654 
656 {
657  unsigned char buf[5];
658  union { float f; uint32_t i; } mem;
659  mem.f = d;
660  buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
661  msgpack_pack_append_buffer(x, buf, 5);
662 }
663 
665 {
666  unsigned char buf[9];
667  union { double f; uint64_t i; } mem;
668  mem.f = d;
669  buf[0] = 0xcb;
670 #if defined(TARGET_OS_IPHONE)
671  // ok
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);
675 #endif
676  _msgpack_store64(&buf[1], mem.i);
677  msgpack_pack_append_buffer(x, buf, 9);
678 }
679 
680 
681 /*
682  * Nil
683  */
684 
686 {
687  static const unsigned char d = 0xc0;
688  msgpack_pack_append_buffer(x, &d, 1);
689 }
690 
691 
692 /*
693  * Boolean
694  */
695 
697 {
698  static const unsigned char d = 0xc3;
699  msgpack_pack_append_buffer(x, &d, 1);
700 }
701 
703 {
704  static const unsigned char d = 0xc2;
705  msgpack_pack_append_buffer(x, &d, 1);
706 }
707 
708 
709 /*
710  * Array
711  */
712 
714 {
715  if(n < 16) {
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);
722  } else {
723  unsigned char buf[5];
724  buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
725  msgpack_pack_append_buffer(x, buf, 5);
726  }
727 }
728 
729 
730 /*
731  * Map
732  */
733 
735 {
736  if(n < 16) {
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);
743  } else {
744  unsigned char buf[5];
745  buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
746  msgpack_pack_append_buffer(x, buf, 5);
747  }
748 }
749 
750 
751 /*
752  * Str
753  */
754 
756 {
757  if(l < 32) {
758  unsigned char d = 0xa0 | (uint8_t)l;
759  msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
760  } else if(l < 256) {
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);
768  } else {
769  unsigned char buf[5];
770  buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
771  msgpack_pack_append_buffer(x, buf, 5);
772  }
773 }
774 
776 {
777  msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
778 }
779 
780 /*
781  * Raw (V4)
782  */
783 
785 {
786  if(l < 32) {
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);
793  } else {
794  unsigned char buf[5];
795  buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
796  msgpack_pack_append_buffer(x, buf, 5);
797  }
798 }
799 
801 {
802  msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
803 }
804 
805 /*
806  * Bin
807  */
808 
810 {
811  if(l < 256) {
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);
819  } else {
820  unsigned char buf[5];
821  buf[0] = 0xc6; _msgpack_store32(&buf[1], (uint32_t)l);
822  msgpack_pack_append_buffer(x, buf, 5);
823  }
824 }
825 
827 {
828  msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
829 }
830 
831 /*
832  * Ext
833  */
834 
836 {
837  switch(l) {
838  case 1: {
839  unsigned char buf[2];
840  buf[0] = 0xd4;
841  buf[1] = (unsigned char)type;
842  msgpack_pack_append_buffer(x, buf, 2);
843  } break;
844  case 2: {
845  unsigned char buf[2];
846  buf[0] = 0xd5;
847  buf[1] = (unsigned char)type;
848  msgpack_pack_append_buffer(x, buf, 2);
849  } break;
850  case 4: {
851  unsigned char buf[2];
852  buf[0] = 0xd6;
853  buf[1] = (unsigned char)type;
854  msgpack_pack_append_buffer(x, buf, 2);
855  } break;
856  case 8: {
857  unsigned char buf[2];
858  buf[0] = 0xd7;
859  buf[1] = (unsigned char)type;
860  msgpack_pack_append_buffer(x, buf, 2);
861  } break;
862  case 16: {
863  unsigned char buf[2];
864  buf[0] = 0xd8;
865  buf[1] = (unsigned char)type;
866  msgpack_pack_append_buffer(x, buf, 2);
867  } break;
868  default:
869  if(l < 256) {
870  unsigned char buf[3];
871  buf[0] = 0xc7;
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];
877  buf[0] = 0xc8;
878  _msgpack_store16(&buf[1], l);
879  buf[3] = (unsigned char)type;
880  msgpack_pack_append_buffer(x, buf, 4);
881  } else {
882  unsigned char buf[6];
883  buf[0] = 0xc9;
884  _msgpack_store32(&buf[1], l);
885  buf[5] = (unsigned char)type;
886  msgpack_pack_append_buffer(x, buf, 6);
887  }
888  break;
889  }
890 }
891 
893 {
894  msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
895 }
896 
898 {
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) {
902  // timestamp 32
903  char buf[4];
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);
908  } else {
909  // timestamp 64
910  char buf[8];
911  msgpack_pack_ext(x, 8, -1);
912  _msgpack_store64(buf, data64);
913  msgpack_pack_append_buffer(x, buf, 8);
914  }
915  } else {
916  // timestamp 96
917  char buf[12];
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);
922  }
923 }
924 
925 #undef msgpack_pack_inline_func
926 #undef msgpack_pack_user
927 #undef msgpack_pack_append_buffer
928 
929 #undef TAKE8_8
930 #undef TAKE8_16
931 #undef TAKE8_32
932 #undef TAKE8_64
933 
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
942 
943 #if defined(_MSC_VER)
944 # pragma warning(pop)
945 #endif
_map
msgpack_pack_inline_func() _map(msgpack_pack_user x, size_t n)
Definition: pack_template.h:734
msgpack_pack_real_uint32
#define msgpack_pack_real_uint32(x, d)
Definition: pack_template.h:75
_nil
msgpack_pack_inline_func() _nil(msgpack_pack_user x)
Definition: pack_template.h:685
_ext_body
msgpack_pack_inline_func() _ext_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:892
_array
msgpack_pack_inline_func() _array(msgpack_pack_user x, size_t n)
Definition: pack_template.h:713
_double
msgpack_pack_inline_func() _double(msgpack_pack_user x, double d)
Definition: pack_template.h:664
_v4raw_body
msgpack_pack_inline_func() _v4raw_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:800
_signed_char
msgpack_pack_inline_func() _signed_char(msgpack_pack_user x, signed char d)
Definition: pack_template.h:386
_str
msgpack_pack_inline_func() _str(msgpack_pack_user x, size_t l)
Definition: pack_template.h:755
_uint64
msgpack_pack_inline_func() _uint64(msgpack_pack_user x, uint64_t d)
Definition: pack_template.h:348
_int64
msgpack_pack_inline_func() _int64(msgpack_pack_user x, int64_t d)
Definition: pack_template.h:368
_uint16
msgpack_pack_inline_func() _uint16(msgpack_pack_user x, uint16_t d)
Definition: pack_template.h:338
msgpack_pack_user
#define msgpack_pack_user
Definition: pack.h:123
_unsigned_char
msgpack_pack_inline_func() _unsigned_char(msgpack_pack_user x, unsigned char d)
Definition: pack_template.h:391
msgpack_pack_inline_func_fixint
#define msgpack_pack_inline_func_fixint(name)
Definition: pack.h:120
if
if(p==pe)
Definition: unpack_template.h:168
_false
msgpack_pack_inline_func() _false(msgpack_pack_user x)
Definition: pack_template.h:702
msgpack_pack_real_uint64
#define msgpack_pack_real_uint64(x, d)
Definition: pack_template.h:101
_timestamp
msgpack_pack_inline_func() _timestamp(msgpack_pack_user x, const msgpack_timestamp *d)
Definition: pack_template.h:897
n
const void * n
Definition: unpack_template.h:100
_msgpack_store32
#define _msgpack_store32(to, num)
Definition: sysdep.h:176
msgpack_pack_inline_func_cint
#define msgpack_pack_inline_func_cint(name)
Definition: pack.h:117
_uint8
msgpack_pack_inline_func() _uint8(msgpack_pack_user x, uint8_t d)
Definition: pack_template.h:333
_int16
msgpack_pack_inline_func() _int16(msgpack_pack_user x, int16_t d)
Definition: pack_template.h:358
_ext
msgpack_pack_inline_func() _ext(msgpack_pack_user x, size_t l, int8_t type)
Definition: pack_template.h:835
msgpack_pack_inline_func
#define msgpack_pack_inline_func(name)
Definition: pack.h:114
_msgpack_store64
#define _msgpack_store64(to, num)
Definition: sysdep.h:178
msgpack_pack_append_buffer
#define msgpack_pack_append_buffer(user, buf, len)
Definition: pack.h:125
_uint32
msgpack_pack_inline_func() _uint32(msgpack_pack_user x, uint32_t d)
Definition: pack_template.h:343
msgpack_pack_real_int8
#define msgpack_pack_real_int8(x, d)
Definition: pack_template.h:132
_float
msgpack_pack_inline_func() _float(msgpack_pack_user x, float d)
Definition: pack_template.h:655
_bin_body
msgpack_pack_inline_func() _bin_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:826
msgpack_pack_real_int64
#define msgpack_pack_real_int64(x, d)
Definition: pack_template.h:214
_bin
msgpack_pack_inline_func() _bin(msgpack_pack_user x, size_t l)
Definition: pack_template.h:809
msgpack_timestamp
Definition: timestamp.h:20
msgpack_pack_real_uint16
#define msgpack_pack_real_uint16(x, d)
Definition: pack_template.h:58
msgpack_pack_real_uint8
#define msgpack_pack_real_uint8(x, d)
Definition: pack_template.h:46
_char
msgpack_pack_inline_func() _char(msgpack_pack_user x, char d)
Definition: pack_template.h:373
msgpack_pack_real_int32
#define msgpack_pack_real_int32(x, d)
Definition: pack_template.h:174
_v4raw
msgpack_pack_inline_func() _v4raw(msgpack_pack_user x, size_t l)
Definition: pack_template.h:784
_int8
msgpack_pack_inline_func() _int8(msgpack_pack_user x, int8_t d)
Definition: pack_template.h:353
_int32
msgpack_pack_inline_func() _int32(msgpack_pack_user x, int32_t d)
Definition: pack_template.h:363
msgpack_pack_real_int16
#define msgpack_pack_real_int16(x, d)
Definition: pack_template.h:144
_true
msgpack_pack_inline_func() _true(msgpack_pack_user x)
Definition: pack_template.h:696
_str_body
msgpack_pack_inline_func() _str_body(msgpack_pack_user x, const void *b, size_t l)
Definition: pack_template.h:775
_msgpack_store16
#define _msgpack_store16(to, num)
Definition: sysdep.h:174