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