libutil++  1.9.3
 All Classes Functions Variables
MessagePack.cpp
1 /*
2 ** libutil++
3 ** $Id: MessagePack.cpp 1911 2017-09-02 17:37:35Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 static const char rcsid[] __attribute__((used)) = "$Id: MessagePack.cpp 1911 2017-09-02 17:37:35Z sella $";
10 
11 #include "MessagePack.h"
12 
13 #include <limits>
14 
15 #include <string.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 
19 using namespace sella::util;
20 
21 MessagePack::MessagePack(uint8_t * & buffer, uint32_t & length, uint32_t offset, uint32_t unused, bool resizable) THROWS(MemoryException) :
22  buffer_memory(buffer),
23  buffer_length(length),
24 
25  buffer_offset(offset),
26  buffer_unused(unused),
27 
28  resizable(resizable)
29 { }
30 
31 uint32_t MessagePack::memcpy(uint8_t * buffer, uint32_t length, uint32_t offset) NO_EXCEPTIONS {
32  uint32_t bytes = this->bytes(offset);
33 
34  if (bytes > length ) {
35  return UINT32_MAX;
36  }
37  ::memcpy(buffer, &(this->buffer_memory[this->buffer_offset + offset]), bytes);
38 
39  return bytes;
40 }
41 
42 int MessagePack::compare(uint32_t offset, const char * value, uint32_t length) NO_EXCEPTIONS {
43  if (UNLIKELY(offset == UINT32_MAX)) {
44  return MessagePack::TYPE_UNKNOWN;
45  }
46  offset += this->buffer_offset;
47 
48  const mpack_table_t * index = &(MessagePack::mpack_table[this->buffer_memory[offset]]);
49  uint32_t bytes = __builtin_bswap32(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[offset + 1]))));
50 
51  bytes = ((bytes & index->bytes_zero) >> index->shift_swap) + (this->buffer_memory[offset] & index->bytes_mask);
52 
53  uint32_t minimum = length ^ ((bytes ^ length) & -(bytes < length));
54  int compare = ::memcmp(value, &(this->buffer_memory[offset + index->bytes_base]), minimum);
55 
56  return (compare != 0) ? compare : ((bytes == length) ? 0 : ((length > bytes) ? 1 : -1));
57 }
58 
59 int MessagePack::compare(uint32_t offset, const char * value) NO_EXCEPTIONS {
60  if (UNLIKELY(offset == UINT32_MAX)) {
61  return 1;
62  }
63  uint32_t bytes;
64  int comparison = 1;
65 
66  switch (this->buffer_memory[this->buffer_offset + offset]) {
67  case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: /* Fixed string. */
68  case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
69  case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
70  case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
71  if ((bytes = (this->buffer_memory[this->buffer_offset + offset] & 0x1f)) > 0) {
72  if ((comparison = ::strncmp(reinterpret_cast<const char *>(&(this->buffer_memory[this->buffer_offset + offset + 1])), value, bytes)) == 0) {
73  if (value[bytes] != 0) {
74  comparison = 1;
75  }
76  }
77  } else {
78  if (value[0] != 0) {
79  comparison = 1;
80  }
81  }
82  return comparison;
83 
84  case 0xd9: /* String with 8 bit length. */
85  if ((bytes = this->buffer_memory[this->buffer_offset + offset + 1]) > 0) {
86  if ((comparison = ::strncmp(reinterpret_cast<const char *>(&(this->buffer_memory[this->buffer_offset + offset + 2])), value, bytes)) == 0) {
87  if (value[bytes] != 0) {
88  comparison = 1;
89  }
90  }
91  } else {
92  if (value[0] != 0) {
93  comparison = 1;
94  }
95  }
96  return comparison;
97 
98  case 0xda: /* String with 16 bit length. */
99  if ((bytes = __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) > 0) {
100  if ((comparison = ::strncmp(reinterpret_cast<const char *>(&(this->buffer_memory[this->buffer_offset + offset + 3])), value, bytes)) == 0) {
101  if (value[bytes] != 0) {
102  comparison = 1;
103  }
104  }
105  } else {
106  if (value[0] != 0) {
107  comparison = 1;
108  }
109  }
110  return comparison;
111 
112  case 0xdb: /* String with 32 bit length. */
113  if ((bytes = __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) > 0) {
114  if ((comparison = ::strncmp(reinterpret_cast<const char *>(&(this->buffer_memory[this->buffer_offset + offset + 5])), value, bytes)) == 0) {
115  if (value[bytes] != 0) {
116  comparison = 1;
117  }
118  }
119  } else {
120  if (value[0] != 0) {
121  comparison = 1;
122  }
123  }
124  return comparison;
125  }
126  return 1;
127 }
128 
129 int MessagePack::compare(uint32_t offset, const std::string & value) NO_EXCEPTIONS {
130  return compare(offset, value.data(), (uint32_t) value.size());
131 }
132 
133 int MessagePack::compare(uint32_t offset, bool value) NO_EXCEPTIONS {
134  if (UNLIKELY(offset == UINT32_MAX)) {
135  return 1;
136  }
137 
138  switch (this->buffer_memory[this->buffer_offset + offset]) {
139  case 0xc2: /* Boolean false. */
140  return value ? -1 : 0;
141 
142  case 0xc3: /* Boolean true. */
143  return value ? 0 : 1;
144  }
145  return 1;
146 }
147 
148 int MessagePack::compare(uint32_t offset, int64_t value) NO_EXCEPTIONS {
149  if (UNLIKELY(offset == UINT32_MAX)) {
150  return 1;
151  }
152  int16_t read16; /* Required due to what appears to be an upcast defect in gcc. */
153  int32_t read32; /* Required due to what appears to be an upcast defect in gcc. */
154 
155  switch (this->buffer_memory[this->buffer_offset + offset]) {
156  case 0xcc: /* Unsigned 8 bit integer. */
157  return static_cast<int64_t>(this->buffer_memory[this->buffer_offset + offset + 1]) - value;
158 
159  case 0xcd: /* Unsigned 16 bit integer. */
160  if (__builtin_bswap16(static_cast<uint16_t>(*(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) <= INT16_MAX) {
161  return static_cast<int64_t>(__builtin_bswap16(static_cast<uint16_t>(*(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))))) - value;
162  }
163  return 1;
164 
165  case 0xce: /* Unsigned 32 bit integer. */
166  if (__builtin_bswap32(static_cast<uint32_t>(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) <= INT32_MAX) {
167  return static_cast<int64_t>(__builtin_bswap32(static_cast<uint32_t>(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))))) - value;
168  }
169  return 1;
170 
171  case 0xcf: /* Unsigned 64 bit integer. */
172  if (__builtin_bswap64(static_cast<uint64_t>(*(reinterpret_cast<uint64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) <= INT64_MAX) {
173  return static_cast<int64_t>(__builtin_bswap64(static_cast<uint64_t>(*(reinterpret_cast<uint64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))))) - value;
174  }
175  return 1;
176 
177  case 0xd0: /* Signed 8 bit integer. */
178  return static_cast<int64_t>(this->buffer_memory[this->buffer_offset + offset + 1]) - value;
179 
180  case 0xd1: /* Signed 16 bit integer. */
181  read16 = __builtin_bswap16(*(reinterpret_cast<int16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
182 
183  return static_cast<int64_t>(read16) - value;
184 
185  case 0xd2: /* Signed 32 bit integer. */
186  read32 = __builtin_bswap32(*(reinterpret_cast<int32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
187 
188  return static_cast<int64_t>(read32) - value;
189 
190  case 0xd3: /* Signed 64 bit integer. */
191  return static_cast<int64_t>(__builtin_bswap64(static_cast<int64_t>(*(reinterpret_cast<int64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))))) - value;
192 
193  case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7: /* Fixed negative integer. */
194  case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
195  case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7:
196  case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff:
197  return static_cast<int64_t>(this->buffer_memory[this->buffer_offset + offset]) - value;
198 
199  default:
200  if ((this->buffer_memory[this->buffer_offset + offset] & 0x7f) == this->buffer_memory[this->buffer_offset + offset]) { /* Fixed positive integer. */
201  return static_cast<int64_t>(this->buffer_memory[this->buffer_offset + offset] & 0x7f) - value;
202  }
203  }
204  return 1;
205 }
206 
207 int MessagePack::compare(uint32_t offset, uint64_t value) NO_EXCEPTIONS {
208  return 0;
209 }
210 
211 int MessagePack::compare(uint32_t offset, double value) NO_EXCEPTIONS {
212  return 0;
213 }
214 
215 bool MessagePack::update(uint32_t offset, MessagePack & other, uint32_t source) NO_EXCEPTIONS {
216  uint32_t exist = this->bytes(offset);
217  uint32_t bytes = other.bytes(source);
218 
219  /* Ensure proper sizing for the splice. */
220  if (exist != bytes) {
221  if (exist < bytes) {
222  if (UNLIKELY(this->expand(offset, bytes - exist) == false)) {
223  return false;
224  }
225  } else {
226  if (UNLIKELY(this->reduce(offset, exist - bytes) == false)) {
227  return false;
228  }
229  }
230  }
231  ::memcpy(&(this->buffer_memory[this->buffer_offset + offset]), &(other.buffer_memory[other.buffer_offset + source]), bytes);
232 
233  return true;
234 }
235 
236 uint32_t MessagePack::create(uint32_t offset) NO_EXCEPTIONS {
237  if (UNLIKELY(offset == UINT32_MAX)) {
238  return UINT32_MAX;
239  }
240 
241  if (this->buffer_unused == 0) {
242  if (this->expand(offset, 1) == false) {
243  return UINT32_MAX;
244  }
245  }
246  this->buffer_memory[this->buffer_offset + offset] = 0xc0;
247  this->buffer_unused -= 1;
248 
249  return offset;
250 }
251 
252 HOT_FUNCTION
253 bool MessagePack::verify(void) NO_EXCEPTIONS {
254  uint32_t index = this->buffer_offset;
255  uint32_t length = this->buffer_length - this->buffer_unused;
256 
257  uint8_t depth = 0;
258  uint32_t size = 0;
259 
260  uint64_t count[64];
261  uint64_t bytes[64];
262 
263  if (index == length) {
264  if ((this->buffer_length - this->buffer_offset - this->buffer_unused) > 0) {
265  this->create(0);
266 
267  return true;
268  }
269  }
270 
271  while (index < length) {
272  switch (this->buffer_memory[index]) {
273  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
274  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
275  count[depth] = (this->buffer_memory[index] & 0x0f) << 1;
276  bytes[depth] = static_cast<uint64_t>(index) << 32;
277 
278  size = 1;
279 
280  if (UNLIKELY((depth = depth + 1) == 64)) {
281  return false;
282  }
283  index = index + size;
284 
285  if (UNLIKELY(index > length)) {
286  return false;
287  }
288  break;
289 
290  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed vector. */
291  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
292  count[depth] = this->buffer_memory[index] & 0x0f;
293  bytes[depth] = static_cast<uint64_t>(index) << 32;
294 
295  size = 1;
296 
297  if (UNLIKELY((depth = depth + 1) == 64)) {
298  return false;
299  }
300  index = index + size;
301 
302  if (UNLIKELY(index > length)) {
303  return false;
304  }
305  break;
306 
307  case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: /* Fixed string. */
308  case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
309  case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
310  case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
311  size = 1 + (this->buffer_memory[index] & 0x1f);
312 
313  index = index + size;
314 
315  if (UNLIKELY(index > length)) {
316  return false;
317  }
318  break;
319 
320  case 0xc0: /* NULL value. */
321  size = 1;
322 
323  index = index + size;
324 
325  if (UNLIKELY(index > length)) {
326  return false;
327  }
328  break;
329 
330  case 0xc1: /* Unused value: skip it. */
331  return false;
332 
333  case 0xc2: /* Boolean false. */
334  case 0xc3: /* Boolean true. */
335  size = 1;
336 
337  index = index + size;
338 
339  if (UNLIKELY(index > length)) {
340  return false;
341  }
342  break;
343 
344  case 0xc4: /* Binary with 8 bit length. */
345  if (UNLIKELY((index + 2) > length)) {
346  return false;
347  }
348  size = 2 + this->buffer_memory[index + 1];
349 
350  index = index + size;
351 
352  if (UNLIKELY(index > length)) {
353  return false;
354  }
355  break;
356 
357  case 0xc5: /* Binary with 16 bit length. */
358  if (UNLIKELY((index + 3) > length)) {
359  return false;
360  }
361  size = 3 + __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[index + 1]))));
362 
363  index = index + size;
364 
365  if (UNLIKELY(index > length)) {
366  return false;
367  }
368  break;
369 
370  case 0xc6: /* Binary with 32 bit length. */
371  if (UNLIKELY((index + 5) > length)) {
372  return false;
373  }
374  size = 5 + __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[index + 1]))));
375 
376  index = index + size;
377 
378  if (UNLIKELY(index > length)) {
379  return false;
380  }
381  break;
382 
383  case 0xc7: /* Extension with 8 bit length value. */
384  if (UNLIKELY((index + 3) > length)) {
385  return false;
386  }
387  size = 3 + this->buffer_memory[index + 1];
388 
389  index = index + size;
390 
391  if (UNLIKELY(index > length)) {
392  return false;
393  }
394  break;
395 
396  case 0xc8: /* Extension with 16 bit length value. */
397  if (UNLIKELY((index + 4) > length)) {
398  return false;
399  }
400  size = 4 + __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[index + 1]))));
401 
402  index = index + size;
403 
404  if (UNLIKELY(index > length)) {
405  return false;
406  }
407  break;
408 
409  case 0xc9: /* Extension with 32 bit length value. */
410  if (UNLIKELY((index + 6) > length)) {
411  return false;
412  }
413  size = 6 + __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[index + 1]))));
414 
415  index = index + size;
416 
417  if (UNLIKELY(index > length)) {
418  return false;
419  }
420  break;
421 
422  case 0xca: /* Floating point 32 bit value. */
423  size = 5;
424 
425  index = index + size;
426 
427  if (UNLIKELY(index > length)) {
428  return false;
429  }
430  break;
431 
432  case 0xcb: /* Floating point 64 bit value. */
433  size = 9;
434 
435  index = index + size;
436 
437  if (UNLIKELY(index > length)) {
438  return false;
439  }
440  break;
441 
442  case 0xcc: /* Unsigned 8 bit integer. */
443  size = 2;
444 
445  index = index + size;
446 
447  if (UNLIKELY(index > length)) {
448  return false;
449  }
450  break;
451 
452  case 0xcd: /* Unsigned 16 bit integer. */
453  size = 3;
454 
455  index = index + size;
456 
457  if (UNLIKELY(index > length)) {
458  return false;
459  }
460  break;
461 
462  case 0xce: /* Unsigned 32 bit integer. */
463  size = 5;
464 
465  index = index + size;
466 
467  if (UNLIKELY(index > length)) {
468  return false;
469  }
470  break;
471 
472  case 0xcf: /* Unsigned 64 bit integer. */
473  size = 9;
474 
475  index = index + size;
476 
477  if (UNLIKELY(index > length)) {
478  return false;
479  }
480  break;
481 
482  case 0xd0: /* Signed 8 bit integer. */
483  size = 2;
484 
485  index = index + size;
486 
487  if (UNLIKELY(index > length)) {
488  return false;
489  }
490  break;
491 
492  case 0xd1: /* Signed 16 bit integer. */
493  size = 3;
494 
495  index = index + size;
496 
497  if (UNLIKELY(index > length)) {
498  return false;
499  }
500  break;
501 
502  case 0xd2: /* Signed 32 bit integer. */
503  size = 5;
504 
505  index = index + size;
506 
507  if (UNLIKELY(index > length)) {
508  return false;
509  }
510  break;
511 
512  case 0xd3: /* Signed 64 bit integer. */
513  size = 9;
514 
515  index = index + size;
516 
517  if (UNLIKELY(index > length)) {
518  return false;
519  }
520  break;
521 
522  case 0xd4: /* Extension 1 byte value. */
523  size = 3;
524 
525  index = index + size;
526 
527  if (UNLIKELY(index > length)) {
528  return false;
529  }
530  break;
531 
532  case 0xd5: /* Extension 2 byte value. */
533  size = 4;
534 
535  index = index + size;
536 
537  if (UNLIKELY(index > length)) {
538  return false;
539  }
540  break;
541 
542  case 0xd6: /* Extension 4 byte value. */
543  size = 6;
544 
545  index = index + size;
546 
547  if (UNLIKELY(index > length)) {
548  return false;
549  }
550  break;
551 
552  case 0xd7: /* Extension 8 byte value. */
553  size = 10;
554 
555  index = index + size;
556 
557  if (UNLIKELY(index > length)) {
558  return false;
559  }
560  break;
561 
562  case 0xd8: /* Extension 16 byte value. */
563  size = 18;
564 
565  index = index + size;
566 
567  if (UNLIKELY(index > length)) {
568  return false;
569  }
570  break;
571 
572  case 0xd9: /* String with 8 bit length. */
573  if (UNLIKELY((index + 2) > length)) {
574  return false;
575  }
576  size = 2 + this->buffer_memory[index + 1];
577 
578  index = index + size;
579 
580  if (UNLIKELY(index > length)) {
581  return false;
582  }
583  break;
584 
585  case 0xda: /* String with 16 bit length. */
586  if (UNLIKELY((index + 3) > length)) {
587  return false;
588  }
589  size = 3 + __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[index + 1]))));
590 
591  index = index + size;
592 
593  if (UNLIKELY(index > length)) {
594  return false;
595  }
596  break;
597 
598  case 0xdb: /* String with 32 bit length. */
599  if (UNLIKELY((index + 5) > length)) {
600  return false;
601  }
602  size = 5 + __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[index + 1]))));
603 
604  index = index + size;
605 
606  if (UNLIKELY(index > length)) {
607  return false;
608  }
609  break;
610 
611  case 0xdc: /* Vector with 16 bit length. */
612  if (UNLIKELY((index + 3) > length)) {
613  return false;
614  }
615  count[depth] = __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[index + 1]))));
616  bytes[depth] = static_cast<uint64_t>(index) << 32;
617 
618  size = 3;
619 
620  if (UNLIKELY((depth = depth + 1) == 64)) {
621  return false;
622  }
623  index = index + size;
624 
625  if (UNLIKELY(index > length)) {
626  return false;
627  }
628  break;
629 
630  case 0xdd: /* Vector with 32 bit length. */
631  if (UNLIKELY((index + 5) > length)) {
632  return false;
633  }
634  count[depth] = __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[index + 1]))));
635  bytes[depth] = static_cast<uint64_t>(index) << 32;
636 
637  size = 5;
638 
639  if (UNLIKELY((depth = depth + 1) == 64)) {
640  return false;
641  }
642  index = index + size;
643 
644  if (UNLIKELY(index > length)) {
645  return false;
646  }
647  break;
648 
649  case 0xde: /* Object with 16 bit length. */
650  if (UNLIKELY((index + 3) > length)) {
651  return false;
652  }
653  count[depth] = __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[index + 1])))) << 1;
654  bytes[depth] = static_cast<uint64_t>(index) << 32;
655 
656  size = 3;
657 
658  if (UNLIKELY((depth = depth + 1) == 64)) {
659  return false;
660  }
661  index = index + size;
662 
663  if (UNLIKELY(index > length)) {
664  return false;
665  }
666  break;
667 
668  case 0xdf: /* Object with 32 bit length. */
669  if (UNLIKELY((index + 5) > length)) {
670  return false;
671  }
672  count[depth] = __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[index + 1])))) << 1;
673  bytes[depth] = static_cast<uint64_t>(index) << 32;
674 
675  size = 5;
676 
677  if (UNLIKELY((depth = depth + 1) == 64)) {
678  return false;
679  }
680  index = index + size;
681 
682  if (UNLIKELY(index > length)) {
683  return false;
684  }
685  break;
686 
687  case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7: /* Fixed negative integer. */
688  case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
689  case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7:
690  case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff:
691  size = 1;
692 
693  index = index + size;
694 
695  if (UNLIKELY(index > length)) {
696  return false;
697  }
698  break;
699 
700  default: /* Fixed positive integer. */
701  size = 1;
702 
703  index = index + size;
704 
705  if (UNLIKELY(index > length)) {
706  return false;
707  }
708  }
709 
710  if (depth > 0) {
711  if ((bytes[depth - 1] & 0x00000000ffffffff) > 0) {
712  for (uint32_t i = 0; i < depth; i++) {
713  bytes[i] += size;
714  }
715 
716  while ((count[depth - 1] -= 1) == 0) {
717  if ((depth -= 1) == 0) {
718  break;
719  }
720  }
721  } else {
722  for (uint32_t i = 0; i < depth; i++) {
723  bytes[i] += size;
724  }
725  }
726  } else {
727  return false;
728  }
729  }
730 
731  if (depth > 0) {
732  while ((count[depth - 1] -= 1) == 0) {
733  if ((depth -= 1) == 0) {
734  break;
735  }
736  }
737  }
738  return true;
739 }
740 
741 uint32_t MessagePack::create(uint32_t offset, const char * index) NO_EXCEPTIONS {
742  return this->search(offset, index, ::strlen(index), true);
743 }
744 
745 uint32_t MessagePack::select(uint32_t offset, const char * index) NO_EXCEPTIONS {
746  return this->search(offset, index, ::strlen(index), false);
747 }
748 
749 uint32_t MessagePack::create(uint32_t offset, MessagePack & other, uint32_t source) NO_EXCEPTIONS {
750  if (UNLIKELY(offset == UINT32_MAX)) {
751  return MessagePack::TYPE_UNKNOWN;
752  }
753  const mpack_table_t * index = &(MessagePack::mpack_table[other.buffer_memory[other.buffer_offset + source]]);
754 
755  uint32_t value = __builtin_bswap32(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[offset + 1]))));
756  uint32_t bytes = ((value & index->bytes_zero) >> index->shift_swap) + (other.buffer_memory[other.buffer_offset + source] & index->bytes_mask);
757 
758  return this->search(offset, reinterpret_cast<const char *>(&(other.buffer_memory[other.buffer_offset + source + index->bytes_base])), bytes, true);
759 }
760 
761 uint32_t MessagePack::create(uint32_t offset, const uint8_t * buffer, uint32_t length) NO_EXCEPTIONS {
762  if (UNLIKELY((offset == UINT32_MAX) || (length < 1))) {
763  return UINT32_MAX;
764  }
765  uint32_t bytes;
766 
767  switch (buffer[0]) {
768  case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: /* Fixed string. */
769  case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
770  case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
771  case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
772  bytes = buffer[0] & 0x1f;
773 
774  if (bytes > 0) {
775  return this->search(offset, reinterpret_cast<const char *>(&(buffer[1])), bytes, true);
776  }
777  break;
778 
779  case 0xd9: /* String with 8 bit length. */
780  bytes = buffer[1];
781 
782  if (bytes > 0) {
783  return this->search(offset, reinterpret_cast<const char *>(&(buffer[2])), bytes, true);
784  }
785  break;
786 
787  case 0xda: /* String with 16 bit length. */
788  bytes = __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(buffer[1]))));
789 
790  if (bytes > 0) {
791  return this->search(offset, reinterpret_cast<const char *>(&(buffer[3])), bytes, true);
792  }
793  break;
794 
795  case 0xdb: /* String with 32 bit length. */
796  bytes = __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(buffer[1]))));
797 
798  if (bytes > 0) {
799  return this->search(offset, reinterpret_cast<const char *>(&(buffer[5])), bytes, true);
800  }
801  break;
802  }
803  return UINT32_MAX;
804 }
805 
806 uint32_t MessagePack::select(uint32_t offset, const uint8_t * buffer, uint32_t length) NO_EXCEPTIONS {
807  if (UNLIKELY((offset == UINT32_MAX) || (length < 1))) {
808  return UINT32_MAX;
809  }
810  uint32_t bytes;
811 
812  switch (buffer[0]) {
813  case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: /* Fixed string. */
814  case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
815  case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
816  case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
817  bytes = buffer[0] & 0x1f;
818 
819  if (bytes > 0) {
820  return this->search(offset, reinterpret_cast<const char *>(&(buffer[1])), bytes, false);
821  }
822  break;
823 
824  case 0xd9: /* String with 8 bit length. */
825  bytes = buffer[1];
826 
827  if (bytes > 0) {
828  return this->search(offset, reinterpret_cast<const char *>(&(buffer[2])), bytes, false);
829  }
830  break;
831 
832  case 0xda: /* String with 16 bit length. */
833  bytes = __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(buffer[1]))));
834 
835  if (bytes > 0) {
836  return this->search(offset, reinterpret_cast<const char *>(&(buffer[3])), bytes, false);
837  }
838  break;
839 
840  case 0xdb: /* String with 32 bit length. */
841  bytes = __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(buffer[1]))));
842 
843  if (bytes > 0) {
844  return this->search(offset, reinterpret_cast<const char *>(&(buffer[5])), bytes, false);
845  }
846  break;
847  }
848  return UINT32_MAX;
849 }
850 
851 uint32_t MessagePack::select(uint32_t offset, MessagePack & other, uint32_t source) NO_EXCEPTIONS {
852  if (UNLIKELY(offset == UINT32_MAX)) {
853  return UINT32_MAX;
854  }
855  uint32_t bytes;
856 
857  switch (other.buffer_memory[other.buffer_offset + source]) {
858  case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: /* Fixed string. */
859  case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
860  case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
861  case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
862  bytes = other.buffer_memory[other.buffer_offset + source] & 0x1f;
863 
864  if (bytes > 0) {
865  return this->search(offset, reinterpret_cast<const char *>(&(other.buffer_memory[other.buffer_offset + source + 1])), bytes, false);
866  }
867  break;
868 
869  case 0xd9: /* String with 8 bit length. */
870  bytes = this->buffer_memory[other.buffer_offset + source + 1];
871 
872  if (bytes > 0) {
873  return this->search(offset, reinterpret_cast<const char *>(&(other.buffer_memory[other.buffer_offset + source + 2])), bytes, false);
874  }
875  break;
876 
877  case 0xda: /* String with 16 bit length. */
878  bytes = __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(other.buffer_memory[other.buffer_offset + offset + 1]))));
879 
880  if (bytes > 0) {
881  return this->search(offset, reinterpret_cast<const char *>(&(other.buffer_memory[other.buffer_offset + source + 3])), bytes, false);
882  }
883  break;
884 
885  case 0xdb: /* String with 32 bit length. */
886  bytes = __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(other.buffer_memory[other.buffer_offset + offset + 1]))));
887 
888  if (bytes > 0) {
889  return this->search(offset, reinterpret_cast<const char *>(&(other.buffer_memory[other.buffer_offset + source + 5])), bytes, false);
890  }
891  break;
892  }
893  return UINT32_MAX;
894 }
895 
896 uint32_t MessagePack::remove(uint32_t offset, const char * index) NO_EXCEPTIONS {
897  if ((offset = this->select(offset, index)) != UINT32_MAX) {
898  if (this->reduce(offset, this->bytes(offset)) == false) {
899  offset = UINT32_MAX;
900  }
901  }
902  return offset;
903 }
904 
905 uint32_t MessagePack::search(uint32_t offset, const char * index, uint32_t bytes, bool create) NO_EXCEPTIONS {
906  if (UNLIKELY(offset == UINT32_MAX)) {
907  return offset;
908  }
909  bool numerical = false;
910  uint32_t number = 0;
911 
912  char string[bytes + 1];
913  uint32_t n = 0;
914 
915  string[0] = 0;
916 
917  for (uint32_t i = 0; i < bytes; i++) {
918  switch (index[i]) {
919  case '-':
920  if (UNLIKELY((i == 0) || numerical)) {
921  return UINT32_MAX;
922  }
923  string[n] = index[i];
924  n += 1;
925 
926  break;
927 
928  case '.':
929  if (UNLIKELY((i == 0) || numerical)) {
930  return UINT32_MAX;
931  }
932  string[n] = 0;
933 
934  return this->search(this->select(offset, string, n, create), index + i + 1, bytes - n - 1, create);
935 
936  case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
937  if (i > 0) {
938  if (numerical) {
939  number = number * 10;
940  number = number + (index[i] - '0');
941  } else {
942  string[n] = index[i];
943  n += 1;
944  }
945  } else {
946  numerical = true;
947 
948  number = index[i] - '0';
949  }
950  break;
951 
952  case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M':
953  case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
954  if (UNLIKELY(numerical)) {
955  return UINT32_MAX;
956  }
957  string[n] = index[i];
958  n += 1;
959 
960  break;
961 
962  case '[':
963  if (UNLIKELY((i == 0) || numerical)) {
964  return UINT32_MAX;
965  }
966  string[n] = 0;
967 
968  return this->search(this->select(offset, string, n, create), index + i + 1, bytes - n - 1, create);
969 
970  case ']':
971  if (UNLIKELY((i == 0) || (numerical == false))) {
972  return UINT32_MAX;
973  }
974 
975  if (*(index + 1) != 0) {
976  return this->select(offset, number, create);
977  }
978  return this->search(this->select(offset, number, create), index + i + 1, bytes - n - 1, create);
979 
980  case '_':
981  if (UNLIKELY(numerical)) {
982  return UINT32_MAX;
983  }
984  string[n] = index[i];
985  n += 1;
986 
987  break;
988 
989  case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm':
990  case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
991  if (UNLIKELY(numerical)) {
992  return UINT32_MAX;
993  }
994  string[n] = index[i];
995  n += 1;
996 
997  break;
998 
999  case '{': case '}':
1000  if (UNLIKELY(numerical)) {
1001  return UINT32_MAX;
1002  }
1003  string[n] = index[i];
1004  n += 1;
1005 
1006  break;
1007 
1008  default:
1009  return UINT32_MAX;
1010  }
1011  }
1012 
1013  if (LIKELY(n > 0)) {
1014  if (UNLIKELY(numerical)) {
1015  return UINT32_MAX;
1016  }
1017  string[n] = 0;
1018 
1019  return this->select(offset, string, n, create);
1020  }
1021  return UINT32_MAX;
1022 }
1023 
1024 bool MessagePack::update(uint32_t offset, const char * value) NO_EXCEPTIONS {
1025  return update(offset, value, (uint32_t) ::strlen(value));
1026 }
1027 
1028 bool MessagePack::update(uint32_t offset, const char * value, uint32_t length) NO_EXCEPTIONS {
1029  if (UNLIKELY(offset == UINT32_MAX)) {
1030  return false;
1031  }
1032  uint32_t bytes = length;
1033  uint32_t exist = this->bytes(offset);
1034 
1035  uint32_t zeros = 0;
1036 
1037  /* Determine the length of the value. */
1038  switch (CLZ32(bytes)) {
1039  case 32: case 31: case 30: case 29: case 28:
1040  zeros = 0;
1041  break;
1042 
1043  case 27: case 26: case 25: case 24:
1044  zeros = 1;
1045  break;
1046 
1047  case 23: case 22: case 21: case 20:
1048  case 19: case 18: case 17: case 16:
1049  zeros = 2;
1050  break;
1051 
1052  case 15: case 14: case 13: case 12:
1053  case 11: case 10: case 9: case 8:
1054  case 7: case 6: case 5: case 4:
1055  case 3: case 2: case 1: case 0:
1056  zeros = 4;
1057  break;
1058 
1059  default:
1060  return false;
1061  }
1062 
1063  /* Resize the buffer if required. */
1064  if (exist != (1 + zeros + bytes)) {
1065  if (exist > (1 + zeros + bytes)) {
1066  if (UNLIKELY(this->reduce(offset, exist - (1 + zeros + bytes)) == false)) {
1067  return false;
1068  }
1069  } else {
1070  if (UNLIKELY(this->expand(offset, (1 + zeros + bytes) - exist) == false)) {
1071  return false;
1072  }
1073  }
1074  }
1075 
1076  /* Update the value. */
1077  switch (zeros) {
1078  case 0:
1079  this->buffer_memory[this->buffer_offset + offset] = 0xa0 + bytes;
1080  break;
1081 
1082  case 1:
1083  this->buffer_memory[this->buffer_offset + offset] = 0xd9;
1084  this->buffer_memory[this->buffer_offset + offset + 1] = bytes;
1085  break;
1086 
1087  case 2:
1088  this->buffer_memory[this->buffer_offset + offset] = 0xda;
1089  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(bytes));
1090  break;
1091 
1092  case 4:
1093  this->buffer_memory[this->buffer_offset + offset] = 0xdb;
1094  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(bytes));
1095  break;
1096  }
1097  ::memcpy(&(this->buffer_memory[this->buffer_offset + offset + zeros + 1]), value, bytes);
1098 
1099  return true;
1100 }
1101 
1102 bool MessagePack::update(uint32_t offset, const std::string & value) NO_EXCEPTIONS {
1103  return update(offset, value.data(), (uint32_t) value.size());
1104 }
1105 
1106 bool MessagePack::update(uint32_t offset, bool value) NO_EXCEPTIONS {
1107  if (UNLIKELY(offset == UINT32_MAX)) {
1108  return offset;
1109  }
1110  uint32_t exist = this->bytes(offset);
1111 
1112  /* Resize the buffer if required. */
1113  if (exist > 1) {
1114  if (UNLIKELY(this->reduce(offset, exist - 1) == false)) {
1115  return false;
1116  }
1117  }
1118 
1119  /* Update the value. */
1120  if (value) {
1121  this->buffer_memory[this->buffer_offset + offset] = 0xc3;
1122  } else {
1123  this->buffer_memory[this->buffer_offset + offset] = 0xc2;
1124  }
1125  return true;
1126 }
1127 
1128 bool MessagePack::update(uint32_t offset, int64_t value) NO_EXCEPTIONS {
1129  if (UNLIKELY(offset == UINT32_MAX)) {
1130  return offset;
1131  }
1132  uint32_t exist = this->bytes(offset);
1133  uint32_t zeros = 0;
1134 
1135  /* Determine the size of the target. */
1136  if (value > 0) {
1137  switch (CLZ64(value)) {
1138  case 64: case 63: case 62: case 61: case 60: case 59: case 58: case 57:
1139  zeros = 0;
1140  break;
1141 
1142  case 56: case 55: case 54: case 53: case 52: case 51: case 50: case 49:
1143  zeros = 2;
1144  break;
1145 
1146  case 48:
1147  case 47: case 46: case 45: case 44:
1148  case 43: case 42: case 41: case 40:
1149  case 39: case 38: case 37: case 36:
1150  case 35: case 34: case 33:
1151  zeros = 4;
1152  break;
1153 
1154  default:
1155  zeros = 8;
1156  }
1157  } else {
1158  if (value < -32) {
1159  if (value < INT8_MIN) {
1160  if (value < INT16_MIN) {
1161  if (value < INT32_MIN) {
1162  zeros = 8;
1163  } else {
1164  zeros = 4;
1165  }
1166  } else {
1167  zeros = 2;
1168  }
1169  } else {
1170  zeros = 1;
1171  }
1172  }
1173  }
1174 
1175  /* Resize the buffer if required. */
1176  if (exist > (1 + zeros)) {
1177  if (UNLIKELY(this->reduce(offset, exist - (1 + zeros)) == false)) {
1178  return false;
1179  }
1180  } else {
1181  if (exist < (1 + zeros)) {
1182  if (UNLIKELY(this->expand(offset, (1 + zeros) - exist) == false)) {
1183  return false;
1184  }
1185  }
1186  }
1187 
1188  /* Update the value. */
1189  switch (zeros) {
1190  case 0:
1191  if (value < 0) {
1192  this->buffer_memory[this->buffer_offset + offset] = static_cast<int8_t>(value) | 0xe0;
1193  } else {
1194  this->buffer_memory[this->buffer_offset + offset] = static_cast<int8_t>(value);
1195  }
1196  break;
1197 
1198  case 1:
1199  this->buffer_memory[this->buffer_offset + offset + 1] = static_cast<int8_t>(value);
1200  this->buffer_memory[this->buffer_offset + offset] = 0xd0;
1201 
1202  break;
1203 
1204  case 2:
1205  *(reinterpret_cast<int16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<int16_t>(value));
1206  this->buffer_memory[this->buffer_offset + offset] = 0xd1;
1207 
1208  break;
1209 
1210  case 4:
1211  *(reinterpret_cast<int32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<int32_t>(value));
1212  this->buffer_memory[this->buffer_offset + offset] = 0xd2;
1213 
1214  break;
1215 
1216  case 8:
1217  *(reinterpret_cast<int64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap64(static_cast<int64_t>(value));
1218  this->buffer_memory[this->buffer_offset + offset] = 0xd3;
1219 
1220  break;
1221  }
1222  return true;
1223 }
1224 
1225 bool MessagePack::update(uint32_t offset, uint64_t value) NO_EXCEPTIONS {
1226  if (UNLIKELY(offset == UINT32_MAX)) {
1227  return offset;
1228  }
1229  uint32_t exist = this->bytes(offset);
1230  uint32_t zeros = 0;
1231 
1232  /* Determine the size of the target. */
1233  switch (CLZ64(value)) {
1234  case 64: case 63: case 62: case 61: case 60: case 59: case 58: case 57:
1235  zeros = 0;
1236  break;
1237 
1238  case 56:
1239  zeros = 1;
1240  break;
1241 
1242  case 55: case 54: case 53: case 52:
1243  case 51: case 50: case 49: case 48:
1244  zeros = 2;
1245  break;
1246 
1247  case 47: case 46: case 45: case 44:
1248  case 43: case 42: case 41: case 40:
1249  case 39: case 38: case 37: case 36:
1250  case 35: case 34: case 33: case 32:
1251  zeros = 4;
1252  break;
1253 
1254  default:
1255  zeros = 8;
1256  }
1257 
1258  /* Resize the buffer if required. */
1259  if (exist > (1 + zeros)) {
1260  if (UNLIKELY(this->reduce(offset, exist - (1 + zeros)) == false)) {
1261  return false;
1262  }
1263  } else {
1264  if (exist < (1 + zeros)) {
1265  if (UNLIKELY(this->expand(offset, (1 + zeros) - exist) == false)) {
1266  return false;
1267  }
1268  }
1269  }
1270 
1271  /* Update the value. */
1272  switch (zeros) {
1273  case 0:
1274  this->buffer_memory[this->buffer_offset + offset] = static_cast<uint8_t>(value);
1275 
1276  break;
1277 
1278  case 1:
1279  this->buffer_memory[this->buffer_offset + offset + 1] = static_cast<uint8_t>(value);
1280  this->buffer_memory[this->buffer_offset + offset] = 0xcc;
1281 
1282  break;
1283 
1284  case 2:
1285  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(value));
1286  this->buffer_memory[this->buffer_offset + offset] = 0xcd;
1287 
1288  break;
1289 
1290  case 4:
1291  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(value));
1292  this->buffer_memory[this->buffer_offset + offset] = 0xce;
1293 
1294  break;
1295 
1296  case 8:
1297  *(reinterpret_cast<uint64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap64(static_cast<uint64_t>(value));
1298  this->buffer_memory[this->buffer_offset + offset] = 0xcf;
1299 
1300  break;
1301  }
1302  return true;
1303 }
1304 
1305 HOT_FUNCTION
1306 double MessagePack::swap64(double value) NO_EXCEPTIONS {
1307  union {
1308  uint64_t i;
1309  double d;
1310  } v;
1311 
1312  v.d = value;
1313  v.i = __builtin_bswap64(v.i);
1314 
1315  return v.d;
1316 }
1317 
1318 bool MessagePack::update(uint32_t offset, double value) NO_EXCEPTIONS {
1319  uint32_t exist = this->bytes(offset);
1320 
1321  if (exist != 9) {
1322  if (exist > 9) {
1323  if (UNLIKELY(this->reduce(offset, exist - 9) == false)) {
1324  return false;
1325  }
1326  } else {
1327  if (UNLIKELY(this->expand(offset, 9 - exist) == false)) {
1328  return false;
1329  }
1330  }
1331  }
1332  value = this->swap64(value);
1333 
1334  ::memcpy(&(this->buffer_memory[this->buffer_offset + offset + 1]), &(value), sizeof(double));
1335  this->buffer_memory[this->buffer_offset + offset] = 0xcb;
1336 
1337  return true;
1338 }
1339 
1340 bool MessagePack::update(uint32_t offset) NO_EXCEPTIONS {
1341  if (UNLIKELY(offset == UINT32_MAX)) {
1342  return offset;
1343  }
1344  uint32_t exist = this->bytes(offset);
1345 
1346  if (exist > 1) {
1347  if (UNLIKELY(this->reduce(offset, exist - 1) == false)) {
1348  return false;
1349  }
1350  }
1351  this->buffer_memory[this->buffer_offset + offset] = 0xc0;
1352 
1353  return true;
1354 }
1355 
1356 uint32_t MessagePack::select(uint32_t offset, uint32_t index, bool create) NO_EXCEPTIONS {
1357  if (offset == UINT32_MAX) {
1358  return UINT32_MAX;
1359  }
1360  uint32_t count = this->count(offset);
1361 
1362  if (count > index) {
1363  select_vector_callback_param_t parameters = { index, UINT32_MAX };
1364 
1365  this->scan(offset, MessagePack::select_vector_callback, reinterpret_cast<void *>(&(parameters)));
1366 
1367  return parameters.value;
1368  }
1369 
1370  if (create) {
1371  return this->insert(offset, index, count);
1372  }
1373  return UINT32_MAX;
1374 }
1375 
1376 bool MessagePack::select_vector_callback(uint32_t i, uint32_t v, void * p) {
1377  select_vector_callback_param_t * param = reinterpret_cast<select_vector_callback_param_t *>(p);
1378 
1379  if (i == param->index) {
1380  param->value = v;
1381 
1382  return false;
1383  }
1384  return true;
1385 }
1386 
1387 uint32_t MessagePack::insert(uint32_t offset, uint32_t index, uint32_t count) NO_EXCEPTIONS {
1388  uint32_t bytes = this->bytes(offset);
1389 
1390  /* Expand the type to hold the new count as necessary. */
1391  if (this->buffer_memory[this->buffer_offset + offset] == 0xc0) {
1392  if (UNLIKELY(this->recast(offset, 0x90) == false)) {
1393  return UINT32_MAX;
1394  }
1395  }
1396 
1397  if (UNLIKELY(this->expand(offset + bytes, index - count + 1) == false)) {
1398  return UINT32_MAX;
1399  }
1400  ::memset(&(this->buffer_memory[this->buffer_offset + offset + bytes]), 0xc1, index - count + 1);
1401 
1402  if (UNLIKELY(this->resize(offset, index + 1) == false)) {
1403  this->reduce(offset + bytes, index - count + 1);
1404 
1405  return UINT32_MAX;
1406  }
1407  return offset + bytes + index - count;
1408 }
1409 
1410 uint32_t MessagePack::select(uint32_t offset, const char * index, uint32_t bytes, bool create) NO_EXCEPTIONS {
1411  if (UNLIKELY(offset == UINT32_MAX)) {
1412  return UINT32_MAX;
1413  }
1414  select_object_callback_param_t parameters = { this, index, bytes, UINT32_MAX };
1415 
1416  this->scan(offset, MessagePack::select_object_callback, reinterpret_cast<void *>(&(parameters)));
1417 
1418  if ((parameters.value == UINT32_MAX) && create) {
1419  return this->insert(offset, index);
1420  }
1421 
1422  return parameters.value;
1423 }
1424 
1425 bool MessagePack::select_object_callback(uint32_t i, uint32_t v, void * p) {
1426  select_object_callback_param_t * param = reinterpret_cast<select_object_callback_param_t *>(p);
1427 
1428  if (param->instance->compare(i, param->index, param->bytes) == 0) {
1429  param->value = v;
1430 
1431  return false;
1432  }
1433  return true;
1434 }
1435 
1436 uint32_t MessagePack::insert(uint32_t offset, const char * index) NO_EXCEPTIONS {
1437  if (UNLIKELY(offset == UINT32_MAX)) {
1438  return UINT32_MAX;
1439  }
1440  uint32_t buffer = offset;
1441 
1442  uint32_t count = this->count(offset);
1443  uint32_t bytes = ::strlen(index);
1444 
1445  uint32_t zeros = 0;
1446 
1447  /* Expand the type to hold the new count as necessary. */
1448  if (this->buffer_memory[this->buffer_offset + offset] == 0xc0) {
1449  if (UNLIKELY(this->recast(offset, 0x80) == false)) {
1450  return UINT32_MAX;
1451  }
1452  }
1453 
1454  switch (count) {
1455  case 0:
1456  if (UNLIKELY(this->recast(offset, 0x80) == false)) {
1457  return UINT32_MAX;
1458  }
1459  break;
1460 
1461  case 15:
1462  if (UNLIKELY(this->recast(offset, 0xde) == false)) {
1463  return UINT32_MAX;
1464  }
1465  break;
1466 
1467  case 65535:
1468  if (UNLIKELY(this->recast(offset, 0xdf) == false)) {
1469  return UINT32_MAX;
1470  }
1471  break;
1472  }
1473 
1474  /* Determine the length of the expansion. */
1475  switch (CLZ32(bytes)) {
1476  case 32: case 31: case 30: case 29: case 28:
1477  zeros = 0;
1478  break;
1479 
1480  case 27: case 26: case 25: case 24:
1481  zeros = 1;
1482  break;
1483 
1484  case 23: case 22: case 21: case 20:
1485  case 19: case 18: case 17: case 16:
1486  zeros = 2;
1487  break;
1488 
1489  case 15: case 14: case 13: case 12:
1490  case 11: case 10: case 9: case 8:
1491  case 7: case 6: case 5: case 4:
1492  case 3: case 2: case 1: case 0:
1493  zeros = 4;
1494  break;
1495 
1496  default:
1497  return UINT32_MAX;
1498  }
1499 
1500  /* Insert the new index with a null value. */
1501  switch (this->buffer_memory[this->buffer_offset + offset]) {
1502  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
1503  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
1504  if (UNLIKELY(this->expand(offset + 1, 2 + zeros + bytes) == false)) {
1505  return UINT32_MAX;
1506  }
1507  buffer += 1;
1508  break;
1509 
1510  case 0xde: /* Object with 16 bit length. */
1511  if (UNLIKELY(this->expand(offset + 3, 2 + zeros + bytes) == false)) {
1512  return UINT32_MAX;
1513  }
1514  buffer += 3;
1515  break;
1516 
1517  case 0xdf: /* Object with 32 bit length. */
1518  if (UNLIKELY(this->expand(offset + 5, 2 + zeros + bytes) == false)) {
1519  return UINT32_MAX;
1520  }
1521  buffer += 5;
1522  break;
1523 
1524  default:
1525  return UINT32_MAX;
1526  }
1527 
1528  switch (zeros) {
1529  case 0:
1530  this->buffer_memory[this->buffer_offset + buffer] = 0xa0 + bytes;
1531  break;
1532 
1533  case 1:
1534  this->buffer_memory[this->buffer_offset + buffer] = 0xd9;
1535  this->buffer_memory[this->buffer_offset + buffer + 1] = bytes;
1536  break;
1537 
1538  case 2:
1539  this->buffer_memory[this->buffer_offset + buffer] = 0xda;
1540  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + buffer + 1]))) = __builtin_bswap16(static_cast<uint16_t>(bytes));
1541  break;
1542 
1543  case 4:
1544  this->buffer_memory[this->buffer_offset + buffer] = 0xdb;
1545  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + buffer + 1]))) = __builtin_bswap32(static_cast<uint32_t>(bytes));
1546  break;
1547  }
1548  ::memcpy(&(this->buffer_memory[this->buffer_offset + buffer + zeros + 1]), index, bytes);
1549  this->buffer_memory[this->buffer_offset + buffer + zeros + 1 + bytes] = 0xc0;
1550 
1551  /* Adjust the size of the container and return. */
1552  if (UNLIKELY(this->resize(offset, count + 1) == false)) {
1553  return UINT32_MAX;
1554  }
1555  return buffer + zeros + 1 + bytes;
1556 }
1557 
1558 HOT_FUNCTION
1559 uint32_t MessagePack::decode_first(uint32_t offset) NO_EXCEPTIONS {
1560  if (UNLIKELY(offset == UINT32_MAX)) {
1561  return UINT32_MAX;
1562  }
1563 
1564  switch (this->buffer_memory[this->buffer_offset + offset]) {
1565  case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: /* Fixed string. */
1566  case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
1567  case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
1568  case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
1569  if ((this->buffer_memory[this->buffer_offset + offset] & 0x1f) > 0) {
1570  return this->buffer_memory[this->buffer_offset + offset + 1];
1571  }
1572  return 0;
1573 
1574  case 0xd9: /* String with 8 bit length. */
1575  if (this->buffer_memory[this->buffer_offset + offset + 1] > 0) {
1576  return this->buffer_memory[this->buffer_offset + offset + 2];
1577  }
1578  return 0;
1579 
1580  case 0xda: /* String with 16 bit length. */
1581  if (__builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))) > 0) {
1582  return this->buffer_memory[this->buffer_offset + offset + 3];
1583  }
1584  return 0;
1585 
1586  case 0xdb: /* String with 32 bit length. */
1587  if (__builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))) > 0) {
1588  return this->buffer_memory[this->buffer_offset + offset + 5];
1589  }
1590  return 0;
1591  }
1592  return UINT32_MAX;
1593 }
1594 
1595 HOT_FUNCTION
1596 bool MessagePack::decode(char * buffer, uint32_t length, uint32_t offset) NO_EXCEPTIONS {
1597  if (UNLIKELY(offset == UINT32_MAX)) {
1598  return false;
1599  }
1600  uint32_t bytes;
1601 
1602  switch (this->buffer_memory[this->buffer_offset + offset]) {
1603  case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: /* Fixed string. */
1604  case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
1605  case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
1606  case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
1607  if ((bytes = (this->buffer_memory[this->buffer_offset + offset] & 0x1f)) < length) {
1608  ::memcpy(buffer, &(this->buffer_memory[this->buffer_offset + offset + 1]), bytes);
1609 
1610  buffer[bytes] = 0;
1611  return true;
1612  }
1613  break;
1614 
1615  case 0xd9: /* String with 8 bit length. */
1616  if ((bytes = this->buffer_memory[this->buffer_offset + offset + 1]) < length) {
1617  ::memcpy(buffer, &(this->buffer_memory[this->buffer_offset + offset + 2]), bytes);
1618 
1619  buffer[bytes] = 0;
1620  return true;
1621  }
1622  break;
1623 
1624  case 0xda: /* String with 16 bit length. */
1625  if ((bytes = __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) < length) {
1626  ::memcpy(buffer, &(this->buffer_memory[this->buffer_offset + offset + 3]), bytes);
1627 
1628  buffer[bytes] = 0;
1629  return true;
1630  }
1631  break;
1632 
1633  case 0xdb: /* String with 32 bit length. */
1634  if ((bytes = __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) < length) {
1635  ::memcpy(buffer, &(this->buffer_memory[this->buffer_offset + offset + 5]), bytes);
1636 
1637  buffer[bytes] = 0;
1638  return true;
1639  }
1640  break;
1641  }
1642  return false;
1643 }
1644 
1645 bool MessagePack::decode(std::string & buffer, uint32_t offset) NO_EXCEPTIONS {
1646  if (UNLIKELY(offset == UINT32_MAX)) {
1647  return false;
1648  }
1649  uint32_t bytes;
1650 
1651  switch (this->buffer_memory[this->buffer_offset + offset]) {
1652  case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: /* Fixed string. */
1653  case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
1654  case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
1655  case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
1656  bytes = (this->buffer_memory[this->buffer_offset + offset] & 0x1f);
1657  buffer.assign(reinterpret_cast<const char *>(&(this->buffer_memory[this->buffer_offset + offset + 1])), bytes);
1658 
1659  return true;
1660 
1661  case 0xd9: /* String with 8 bit length. */
1662  bytes = this->buffer_memory[this->buffer_offset + offset + 1];
1663  buffer.assign(reinterpret_cast<const char *>(&(this->buffer_memory[this->buffer_offset + offset + 2])), bytes);
1664 
1665  return true;
1666 
1667  case 0xda: /* String with 16 bit length. */
1668  bytes = __builtin_bswap16(*(reinterpret_cast<const uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
1669  buffer.assign(reinterpret_cast<const char *>(&(this->buffer_memory[this->buffer_offset + offset + 3])), bytes);
1670 
1671  return true;
1672 
1673  case 0xdb: /* String with 32 bit length. */
1674  bytes = __builtin_bswap32(*(reinterpret_cast<const uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
1675  buffer.assign(reinterpret_cast<const char *>(&(this->buffer_memory[this->buffer_offset + offset + 5])), bytes);
1676 
1677  return true;
1678  }
1679  return false;
1680 }
1681 
1682 bool MessagePack::decode(bool & buffer, uint32_t offset) NO_EXCEPTIONS {
1683  if (UNLIKELY(offset == UINT32_MAX)) {
1684  return false;
1685  }
1686 
1687  switch (this->buffer_memory[this->buffer_offset + offset]) {
1688  case 0xc2: /* Boolean false. */
1689  buffer = false;
1690 
1691  return true;
1692 
1693  case 0xc3: /* Boolean true. */
1694  buffer = true;
1695 
1696  return true;
1697  }
1698  return false;
1699 }
1700 
1701 bool MessagePack::decode(int64_t & buffer, uint32_t offset) NO_EXCEPTIONS {
1702  if (UNLIKELY(offset == UINT32_MAX)) {
1703  return false;
1704  }
1705  int16_t read16; /* Required due to what appears to be an upcast defect in gcc. */
1706  int32_t read32; /* Required due to what appears to be an upcast defect in gcc. */
1707 
1708  switch (this->buffer_memory[this->buffer_offset + offset]) {
1709  case 0xcc: /* Unsigned 8 bit integer. */
1710  if (this->buffer_memory[this->buffer_offset + offset + 1] < 128) {
1711  buffer = static_cast<int8_t>(this->buffer_memory[this->buffer_offset + offset + 1]);
1712 
1713  return true;
1714  }
1715  return false;
1716 
1717  case 0xcd: /* Unsigned 16 bit integer. */
1718  if (__builtin_bswap16(static_cast<uint16_t>(*(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) <= INT16_MAX) {
1719  buffer = static_cast<int16_t>(__builtin_bswap16(static_cast<uint16_t>(*(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))));
1720 
1721  return true;
1722  }
1723  return false;
1724 
1725  case 0xce: /* Unsigned 32 bit integer. */
1726  if (__builtin_bswap32(static_cast<uint32_t>(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) <= INT32_MAX) {
1727  buffer = static_cast<int32_t>(__builtin_bswap32(static_cast<uint32_t>(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))));
1728 
1729  return true;
1730  }
1731  return false;
1732 
1733  case 0xcf: /* Unsigned 64 bit integer. */
1734  if (__builtin_bswap64(static_cast<uint64_t>(*(reinterpret_cast<uint64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))) <= INT64_MAX) {
1735  buffer = static_cast<int64_t>(__builtin_bswap64(static_cast<uint64_t>(*(reinterpret_cast<uint64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))))));
1736 
1737  return true;
1738  }
1739  return false;
1740 
1741  case 0xd0: /* Signed 8 bit integer. */
1742  buffer = static_cast<int8_t>(this->buffer_memory[this->buffer_offset + offset + 1]);
1743 
1744  return true;
1745 
1746  case 0xd1: /* Signed 16 bit integer. */
1747  read16 = __builtin_bswap16(*(reinterpret_cast<int16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
1748  buffer = read16;
1749 
1750  return true;
1751 
1752  case 0xd2: /* Signed 32 bit integer. */
1753  read32 = __builtin_bswap32(*(reinterpret_cast<int32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
1754  buffer = read32;
1755 
1756  return true;
1757 
1758  case 0xd3: /* Signed 64 bit integer. */
1759  buffer = __builtin_bswap64(static_cast<int64_t>(*(reinterpret_cast<int64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))));
1760 
1761  return true;
1762 
1763  case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7: /* Fixed negative integer. */
1764  case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
1765  case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7:
1766  case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff:
1767  buffer = static_cast<int8_t>(this->buffer_memory[this->buffer_offset + offset]);
1768 
1769  return true;
1770 
1771  default:
1772  if ((this->buffer_memory[this->buffer_offset + offset] & 0x7f) == this->buffer_memory[this->buffer_offset + offset]) { /* Fixed positive integer. */
1773  buffer = this->buffer_memory[this->buffer_offset + offset] & 0x7f;
1774 
1775  return true;
1776  }
1777  }
1778  return false;
1779 }
1780 
1781 bool MessagePack::decode(uint64_t & buffer, uint32_t offset) NO_EXCEPTIONS {
1782  if (UNLIKELY(offset == UINT32_MAX)) {
1783  return false;
1784  }
1785 
1786  switch (this->buffer_memory[this->buffer_offset + offset]) {
1787  case 0xcc: /* Unsigned 8 bit integer. */
1788  buffer = this->buffer_memory[this->buffer_offset + offset + 1];
1789 
1790  return true;
1791 
1792  case 0xcd: /* Unsigned 16 bit integer. */
1793  buffer = __builtin_bswap16(static_cast<uint16_t>(*(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))));
1794 
1795  return true;
1796 
1797  case 0xce: /* Unsigned 32 bit integer. */
1798  buffer = __builtin_bswap32(static_cast<uint32_t>(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))));
1799 
1800  return true;
1801 
1802  case 0xcf: /* Unsigned 64 bit integer. */
1803  buffer = __builtin_bswap64(static_cast<uint64_t>(*(reinterpret_cast<uint64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))));
1804 
1805  return true;
1806 
1807  case 0xd0: /* Signed 8 bit integer. */
1808  if (static_cast<int8_t>(this->buffer_memory[this->buffer_offset + offset + 1]) >= 0) {
1809  buffer = this->buffer_memory[this->buffer_offset + offset + 1];
1810 
1811  return true;
1812  }
1813  return false;
1814 
1815  case 0xd1: /* Signed 16 bit integer. */
1816  if (__builtin_bswap16(*(reinterpret_cast<int16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))) >= 0) {
1817  buffer = static_cast<uint16_t>(__builtin_bswap16(*(reinterpret_cast<int16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))));
1818 
1819  return true;
1820  }
1821  return false;
1822 
1823  case 0xd2: /* Signed 32 bit integer. */
1824  if (__builtin_bswap32(*(reinterpret_cast<int32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))) >= 0) {
1825  buffer = static_cast<uint32_t>(__builtin_bswap32(*(reinterpret_cast<int32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))));
1826 
1827  return true;
1828  }
1829  return false;
1830 
1831  case 0xd3: /* Signed 64 bit integer. */
1832  if (__builtin_bswap64(*(reinterpret_cast<int64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))) >= 0) {
1833  buffer = static_cast<uint64_t>(__builtin_bswap64(*(reinterpret_cast<int64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1])))));
1834 
1835  return true;
1836  }
1837  return false;
1838 
1839  default:
1840  if ((this->buffer_memory[this->buffer_offset + offset] & 0x7f) == this->buffer_memory[this->buffer_offset + offset]) { /* Fixed positive integer. */
1841  buffer = this->buffer_memory[this->buffer_offset + offset] & 0x7f;
1842 
1843  return true;
1844  }
1845  }
1846  return false;
1847 }
1848 
1849 bool MessagePack::decode(double & buffer, uint32_t offset) NO_EXCEPTIONS {
1850  if (UNLIKELY(offset == UINT32_MAX)) {
1851  return false;
1852  }
1853 
1854  switch (this->buffer_memory[this->buffer_offset + offset]) {
1855  case 0xca: /* Floating point 32 bit value. */
1856  buffer = __builtin_bswap32(*(reinterpret_cast<const float *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
1857 
1858  return true;
1859 
1860  case 0xcb: /* Floating point 64 bit value. */
1861  buffer = this->swap64(*(reinterpret_cast<const double *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
1862 
1863  return true;
1864  }
1865  return false;
1866 }
1867 
1868 HOT_FUNCTION
1869 void MessagePack::scan(uint32_t offset, mp_scan_callback callback, void * parameters) {
1870  if (UNLIKELY(offset == UINT32_MAX)) {
1871  return;
1872  }
1873  uint64_t count = this->count(offset);
1874 
1875  switch (this->buffer_memory[this->buffer_offset + offset]) {
1876  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
1877  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
1878  this->scan_object(count, offset + 1, callback, parameters);
1879  break;
1880 
1881  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed vector. */
1882  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
1883  this->scan_vector(count, offset + 1, callback, parameters);
1884  break;
1885 
1886  case 0xdc: /* Vector with 16 bit length. */
1887  this->scan_vector(count, offset + 3, callback, parameters);
1888  break;
1889 
1890  case 0xdd: /* Vector with 32 bit length. */
1891  this->scan_vector(count, offset + 5, callback, parameters);
1892  break;
1893 
1894  case 0xde: /* Object with 16 bit length. */
1895  this->scan_object(count, offset + 3, callback, parameters);
1896  break;
1897 
1898  case 0xdf: /* Object with 32 bit length. */
1899  this->scan_object(count, offset + 5, callback, parameters);
1900  break;
1901  }
1902 }
1903 
1904 HOT_FUNCTION
1905 void MessagePack::scan(uint32_t offset, std::function<bool (uint32_t i, uint32_t v)> callback) {
1906  if (UNLIKELY(offset == UINT32_MAX)) {
1907  return;
1908  }
1909  uint64_t count = this->count(offset);
1910 
1911  switch (this->buffer_memory[this->buffer_offset + offset]) {
1912  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
1913  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
1914  this->scan_object(count, offset + 1, callback);
1915  break;
1916 
1917  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed vector. */
1918  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
1919  this->scan_vector(count, offset + 1, callback);
1920  break;
1921 
1922  case 0xdc: /* Vector with 16 bit length. */
1923  this->scan_vector(count, offset + 3, callback);
1924  break;
1925 
1926  case 0xdd: /* Vector with 32 bit length. */
1927  this->scan_vector(count, offset + 5, callback);
1928  break;
1929 
1930  case 0xde: /* Object with 16 bit length. */
1931  this->scan_object(count, offset + 3, callback);
1932  break;
1933 
1934  case 0xdf: /* Object with 32 bit length. */
1935  this->scan_object(count, offset + 5, callback);
1936  break;
1937  }
1938 }
1939 
1940 HOT_FUNCTION
1941 void MessagePack::scan_vector(uint32_t length, uint32_t offset, std::function<bool (uint32_t i, uint32_t v)> callback) {
1942  uint32_t bytes = 0;
1943 
1944  if (UNLIKELY(offset == UINT32_MAX)) {
1945  return;
1946  }
1947 
1948  for (uint32_t i = 0; i < length; i++) {
1949  if (i < (length - 1)) {
1950  bytes = this->bytes(offset);
1951  }
1952 
1953  if (callback(i, offset) == false) {
1954  i = length - 1;
1955  }
1956 
1957  if (i < (length - 1)) {
1958  offset += bytes;
1959  }
1960  }
1961 }
1962 
1963 HOT_FUNCTION
1964 void MessagePack::scan_vector(uint32_t length, uint32_t offset, mp_scan_callback callback, void * parameters) {
1965  uint32_t bytes = 0;
1966 
1967  if (UNLIKELY(offset == UINT32_MAX)) {
1968  return;
1969  }
1970 
1971  for (uint32_t i = 0; i < length; i++) {
1972  if (i < (length - 1)) {
1973  bytes = this->bytes(offset);
1974  }
1975 
1976  if (callback(i, offset, parameters) == false) {
1977  i = length - 1;
1978  }
1979 
1980  if (i < (length - 1)) {
1981  offset += bytes;
1982  }
1983  }
1984 }
1985 
1986 HOT_FUNCTION
1987 void MessagePack::scan_object(uint32_t length, uint32_t offset, std::function<bool (uint32_t i, uint32_t v)> callback) {
1988  if (UNLIKELY(offset == UINT32_MAX)) {
1989  return;
1990  }
1991 
1992  for (uint32_t i = 0; i < length; i++) {
1993  uint32_t bytes = this->bytes(offset);
1994 
1995  if (callback(offset, offset + bytes) == false) {
1996  i = length - 1;
1997  }
1998 
1999  if (i < (length - 1)) {
2000  offset += bytes;
2001  offset += this->bytes(offset);
2002  }
2003  }
2004 }
2005 
2006 HOT_FUNCTION
2007 void MessagePack::scan_object(uint32_t length, uint32_t offset, mp_scan_callback callback, void * parameters) {
2008  if (UNLIKELY(offset == UINT32_MAX)) {
2009  return;
2010  }
2011 
2012  for (uint32_t i = 0; i < length; i++) {
2013  uint32_t bytes = this->bytes(offset);
2014 
2015  if (callback(offset, offset + bytes, parameters) == false) {
2016  i = length - 1;
2017  }
2018 
2019  if (i < (length - 1)) {
2020  offset += bytes;
2021  offset += this->bytes(offset);
2022  }
2023  }
2024 }
2025 
2026 bool MessagePack::resize(uint32_t offset, uint32_t size) NO_EXCEPTIONS {
2027  if (UNLIKELY(offset == UINT32_MAX)) {
2028  return false;
2029  }
2030 
2031  switch (this->buffer_memory[this->buffer_offset + offset]) {
2032  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
2033  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
2034  if (size < 16) {
2035  this->buffer_memory[this->buffer_offset + offset] = 0x80 | size;
2036 
2037  return true;
2038  }
2039  break;
2040 
2041  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed vector. */
2042  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
2043  if (size < 16) {
2044  this->buffer_memory[this->buffer_offset + offset] = 0x90 | size;
2045 
2046  return true;
2047  }
2048  break;
2049 
2050  case 0xdc: /* Vector with 16 bit length. */
2051  if (size < 65536) {
2052  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(size));
2053 
2054  return true;
2055  }
2056  break;
2057 
2058  case 0xdd: /* Vector with 32 bit length. */
2059  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(size));
2060 
2061  return true;
2062 
2063  case 0xde: /* Object with 16 bit length. */
2064  if (size < 65536) {
2065  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(size));
2066 
2067  return true;
2068  }
2069  break;
2070 
2071  case 0xdf: /* Object with 32 bit length. */
2072  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(size));
2073 
2074  return true;
2075  }
2076  return false;
2077 }
2078 
2079 bool MessagePack::recast(uint32_t offset, uint32_t type) NO_EXCEPTIONS {
2080  if (UNLIKELY(offset == UINT32_MAX)) {
2081  return false;
2082  }
2083  uint32_t count;
2084 
2085  switch (this->buffer_memory[this->buffer_offset + offset]) {
2086  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
2087  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
2088  count = this->buffer_memory[this->buffer_offset + offset] & 0x0f;
2089 
2090  switch (type) {
2091  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
2092  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
2093  return true;
2094 
2095  case 0xde: /* Object with 16 bit length. */
2096  if (UNLIKELY(this->expand(offset + 1, 2) == false)) {
2097  return false;
2098  } else {
2099  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(count));
2100 
2101  this->buffer_memory[this->buffer_offset + offset] = 0xde;
2102  }
2103  return true;
2104 
2105  case 0xdf: /* Object with 32 bit length. */
2106  if (UNLIKELY(this->expand(offset + 1, 4) == false)) {
2107  return false;
2108  } else {
2109  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(count));
2110 
2111  this->buffer_memory[this->buffer_offset + offset] = 0xdf;
2112  }
2113  return true;
2114  }
2115  break;
2116 
2117  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed vector. */
2118  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
2119  count = this->buffer_memory[this->buffer_offset + offset] & 0x0f;
2120 
2121  switch (type) {
2122  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed vector. */
2123  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
2124  return true;
2125 
2126  case 0xdc: /* Vector with 16 bit length. */
2127  if (UNLIKELY(this->expand(offset + 1, 2) == false)) {
2128  return false;
2129  } else {
2130  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(count));
2131 
2132  this->buffer_memory[this->buffer_offset + offset] = 0xdc;
2133  }
2134  return true;
2135 
2136  case 0xdd: /* Vector with 32 bit length. */
2137  if (UNLIKELY(this->expand(offset + 1, 4) == false)) {
2138  return false;
2139  } else {
2140  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(count));
2141 
2142  this->buffer_memory[this->buffer_offset + offset] = 0xdd;
2143  }
2144  return true;
2145  }
2146  break;
2147 
2148  case 0xc0:
2149  count = 0;
2150 
2151  switch (type) {
2152  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
2153  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
2154  this->buffer_memory[this->buffer_offset + offset] = type;
2155 
2156  return true;
2157 
2158  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed vector. */
2159  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
2160  this->buffer_memory[this->buffer_offset + offset] = type;
2161 
2162  return true;
2163 
2164  case 0xdc: /* Vector with 16 bit length. */
2165  if (UNLIKELY(this->expand(offset + 1, 2) == false)) {
2166  return false;
2167  }
2168  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = 0;
2169  this->buffer_memory[this->buffer_offset + offset] = type;
2170 
2171  return true;
2172 
2173  case 0xdd: /* Vector with 32 bit length. */
2174  if (UNLIKELY(this->expand(offset + 1, 4) == false)) {
2175  return false;
2176  }
2177  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = 0;
2178  this->buffer_memory[this->buffer_offset + offset] = type;
2179 
2180  return true;
2181 
2182  case 0xde: /* Object with 16 bit length. */
2183  if (UNLIKELY(this->expand(offset + 1, 2) == false)) {
2184  return false;
2185  }
2186  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = 0;
2187  this->buffer_memory[this->buffer_offset + offset] = type;
2188 
2189  return true;
2190 
2191  case 0xdf: /* Object with 32 bit length. */
2192  if (UNLIKELY(this->expand(offset + 1, 4) == false)) {
2193  return false;
2194  }
2195  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = 0;
2196  this->buffer_memory[this->buffer_offset + offset] = type;
2197 
2198  return true;
2199  }
2200  break;
2201 
2202  case 0xdc: /* Vector with 16 bit length. */
2203  count = __builtin_bswap16(*(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
2204 
2205  switch (type) {
2206  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed object. */
2207  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
2208  if (count > 16) {
2209  if (UNLIKELY(this->reduce(offset + 1, 2) == false)) {
2210  return false;
2211  }
2212  this->buffer_memory[this->buffer_offset + offset] = 0x90 | count;
2213 
2214  return true;
2215  }
2216  break;
2217 
2218  case 0xdc: /* Vector with 16 bit length. */
2219  return true;
2220 
2221  case 0xdd: /* Vector with 32 bit length. */
2222  if (UNLIKELY(this->expand(offset + 1, 2) == false)) {
2223  return false;
2224  } else {
2225  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(count));
2226 
2227  this->buffer_memory[this->buffer_offset + offset] = 0xdd;
2228  }
2229  return true;
2230  }
2231  break;
2232 
2233  case 0xdd: /* Vector with 32 bit length. */
2234  count = __builtin_bswap32(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
2235 
2236  switch (type) {
2237  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: /* Fixed object. */
2238  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
2239  if (count < 16) {
2240  if (UNLIKELY(this->reduce(offset + 1, 4) == false)) {
2241  return false;
2242  }
2243  this->buffer_memory[this->buffer_offset + offset] = 0x90 | count;
2244 
2245  return true;
2246  }
2247  break;
2248 
2249  case 0xdc: /* Vector with 16 bit length. */
2250  if (count < 65536) {
2251  if (UNLIKELY(this->reduce(offset + 1, 2) == false)) {
2252  return false;
2253  } else {
2254  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(count));
2255 
2256  this->buffer_memory[this->buffer_offset + offset] = 0xdc;
2257  }
2258  return true;
2259  }
2260  break;
2261 
2262  case 0xdd: /* Vector with 32 bit length. */
2263  return true;
2264  }
2265  break;
2266 
2267  case 0xde: /* Object with 16 bit length. */
2268  count = __builtin_bswap16(*(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
2269 
2270  switch (type) {
2271  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
2272  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
2273  if (count > 16) {
2274  if (UNLIKELY(this->reduce(offset + 1, 2) == false)) {
2275  return false;
2276  }
2277  this->buffer_memory[this->buffer_offset + offset] = 0x80 | count;
2278 
2279  return true;
2280  }
2281  break;
2282 
2283  case 0xde: /* Object with 16 bit length. */
2284  return true;
2285 
2286  case 0xdf: /* Object with 32 bit length. */
2287  if (UNLIKELY(this->expand(offset + 1, 2) == false)) {
2288  return false;
2289  } else {
2290  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(count));
2291 
2292  this->buffer_memory[this->buffer_offset + offset] = 0xdf;
2293  }
2294  return true;
2295  }
2296  break;
2297 
2298  case 0xdf: /* Object with 32 bit length. */
2299  count = __builtin_bswap32(*(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))));
2300 
2301  switch (type) {
2302  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
2303  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
2304  if (count < 16) {
2305  if (UNLIKELY(this->reduce(offset + 1, 4) == false)) {
2306  return false;
2307  }
2308  this->buffer_memory[this->buffer_offset + offset] = 0x80 | count;
2309 
2310  return true;
2311  }
2312  break;
2313 
2314  case 0xde: /* Object with 16 bit length. */
2315  if (count < 65536) {
2316  if (UNLIKELY(this->reduce(offset + 1, 2) == false)) {
2317  return false;
2318  } else {
2319  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(count));
2320 
2321  this->buffer_memory[this->buffer_offset + offset] = 0xde;
2322  }
2323  return true;
2324  }
2325  break;
2326 
2327  case 0xdf: /* Object with 32 bit length. */
2328  return true;
2329  }
2330  break;
2331  }
2332  return false;
2333 }
2334 
2335 bool MessagePack::expand(uint32_t offset, uint32_t length) NO_EXCEPTIONS {
2336  if (UNLIKELY(offset == UINT32_MAX)) {
2337  return false;
2338  }
2339  uint32_t resize = CEIL_256(this->buffer_length - this->buffer_unused + length);
2340 
2341  if (this->buffer_unused < length) {
2342  if (resizable == false) {
2343  return false;
2344  }
2345  uint8_t * buffer = reinterpret_cast<uint8_t *>(::aligned_alloc(256, resize));
2346 
2347  if (UNLIKELY(buffer == NULL)) {
2348  return false;
2349  }
2350  ::memcpy(buffer, this->buffer_memory, this->buffer_length);
2351  SAFE_FREE(this->buffer_memory);
2352 
2353  this->buffer_unused = (resize - this->buffer_length) + this->buffer_unused;
2354 
2355  this->buffer_length = resize;
2356  this->buffer_memory = buffer;
2357  }
2358  ::memmove(&(this->buffer_memory[this->buffer_offset + offset + length]), &(this->buffer_memory[this->buffer_offset + offset]), this->buffer_length - this->buffer_offset - offset - length);
2359 
2360  this->buffer_unused -= length;
2361 
2362  return true;
2363 }
2364 
2365 bool MessagePack::reduce(uint32_t offset, uint32_t length) NO_EXCEPTIONS {
2366  if (UNLIKELY(offset == UINT32_MAX)) {
2367  return false;
2368  }
2369  uint32_t resize = CEIL_256(this->buffer_length - this->buffer_unused - length);
2370 
2371  if (((this->buffer_length - this->buffer_offset - resize) + this->buffer_unused) > 0) {
2372  ::memmove(&(this->buffer_memory[this->buffer_offset + offset]), &(this->buffer_memory[this->buffer_offset + offset + length]), this->buffer_length - (this->buffer_offset + offset + length));
2373  }
2374 
2375  if ((resize < this->buffer_length) && (resize > 0)) {
2376  if (resizable == false) {
2377  return false;
2378  }
2379  uint8_t * buffer = reinterpret_cast<uint8_t *>(::aligned_alloc(256, resize));
2380 
2381  if (UNLIKELY(buffer == NULL)) {
2382  return false;
2383  }
2384  ::memcpy(buffer, this->buffer_memory, resize);
2385  SAFE_FREE(this->buffer_memory);
2386 
2387  this->buffer_unused = (this->buffer_length - resize) + this->buffer_unused;
2388 
2389  this->buffer_length = resize;
2390  this->buffer_memory = buffer;
2391  } else {
2392  this->buffer_unused += length;
2393  }
2394  return true;
2395 }
2396 
2397 void MessagePack::print(bool debug) NO_EXCEPTIONS {
2398  if (debug) {
2399  printf("Message Pack\n");
2400  printf(" Buffer: %p\n", this->buffer_memory);
2401  printf(" Length: %u\n", this->buffer_length);
2402  printf(" Offset: %u\n", this->buffer_offset);
2403  printf(" Unused: %u\n", this->buffer_unused);
2404  printf("\n");
2405  printf(" Header\n");
2406  printf(" ");
2407 
2408  for (uint32_t i = 0; i < this->buffer_offset; i++) {
2409  printf("%02x ", this->buffer_memory[i]);
2410 
2411  if (((i + 1) % 8) == 0) {
2412  printf("\n ");
2413  }
2414  }
2415  printf("\n");
2416 
2417  printf(" Content\n");
2418  printf(" ");
2419 
2420  for (uint32_t i = this->buffer_offset; i < (this->buffer_length - this->buffer_unused); i++) {
2421  printf("%02x ", this->buffer_memory[i]);
2422 
2423  if (((i + 1) % 8) == 0) {
2424  printf("\n ");
2425  }
2426  }
2427  printf("\n");
2428 
2429  printf(" Unused\n");
2430  printf(" ");
2431 
2432  for (uint32_t i = (this->buffer_length - this->buffer_unused); i < this->buffer_length; i++) {
2433  printf("%02x ", this->buffer_memory[i]);
2434 
2435  if (((i + 1) % 8) == 0) {
2436  printf("\n ");
2437  }
2438  }
2439  printf("\n");
2440  printf("\n");
2441  printf("JSON Format\n ");
2442  }
2443  printf("%s", json(0).c_str());
2444  printf("\n\n");
2445 }
2446 
2447 std::string MessagePack::json(uint32_t offset) NO_EXCEPTIONS {
2448  std::string buffer, tmp;
2449  uint32_t n = 0;
2450 
2451  bool b = false;
2452  int64_t s = 0;
2453  uint64_t u = 0;
2454  double d = 0.0;
2455 
2456  switch (this->typeof(offset)) {
2457  case MessagePack::TYPE_NULL:
2458  buffer.append("null");
2459  break;
2460 
2461  case MessagePack::TYPE_VECTOR:
2462  buffer.append("[ ");
2463 
2464  this->scan(offset, [this, & n, & buffer](uint32_t i, uint32_t v) {
2465  if (n != 0) {
2466  buffer.append(", ");
2467  }
2468  n += 1;
2469 
2470  buffer.append(json(v));
2471 
2472  return true;
2473  });
2474  buffer.append(" ]");
2475 
2476  break;
2477 
2478  case MessagePack::TYPE_OBJECT:
2479  buffer.append("{ ");
2480 
2481  this->scan(offset, [this, & n, & buffer](uint32_t i, uint32_t v) {
2482  if (n != 0) {
2483  buffer.append(", ");
2484  }
2485  n += 1;
2486 
2487  buffer.append(json(i));
2488  buffer.append(": ");
2489  buffer.append(json(v));
2490 
2491  return true;
2492  });
2493 
2494  buffer.append(" }");
2495  break;
2496 
2497  case MessagePack::TYPE_STRING:
2498  this->decode(tmp, offset);
2499 
2500  buffer.push_back('"');
2501  buffer.append(tmp);
2502  buffer.push_back('"');
2503  break;
2504 
2505  case MessagePack::TYPE_BOOLEAN:
2506  this->decode(b, offset);
2507 
2508  buffer.append((b) ? "true" : "false");
2509  break;
2510 
2511  case MessagePack::TYPE_SIGNED:
2512  this->decode(s, offset);
2513 
2514  buffer.append(std::to_string(s));
2515  break;
2516 
2517  case MessagePack::TYPE_UNSIGNED:
2518  this->decode(u, offset);
2519 
2520  buffer.append(std::to_string(u));
2521  break;
2522 
2523  case MessagePack::TYPE_FLOAT:
2524  this->decode(d, offset);
2525 
2526  buffer.append(std::to_string(d));
2527  break;
2528 
2529  case MessagePack::TYPE_BINARY:
2530  buffer.append("\"(binary)\"");
2531  break;
2532 
2533  case MessagePack::TYPE_EXTENSION:
2534  buffer.append("\"(extension)\"");
2535  break;
2536 
2537  case MessagePack::TYPE_UNKNOWN:
2538  buffer.append("\"(unknown)\"");
2539  break;
2540  }
2541 
2542  return buffer;
2543 }
2544 
2545 uint32_t MessagePack::append(uint32_t offset, const char * value) NO_EXCEPTIONS {
2546  if (UNLIKELY(offset == UINT32_MAX)) {
2547  return 0;
2548  }
2549  uint32_t bytes = ::strlen(value);
2550  uint32_t zeros = 0;
2551 
2552  /* Determine the length of the value. */
2553  switch (CLZ32(bytes)) {
2554  case 32: case 31: case 30: case 29: case 28:
2555  zeros = 0;
2556  break;
2557 
2558  case 27: case 26: case 25: case 24:
2559  zeros = 1;
2560  break;
2561 
2562  case 23: case 22: case 21: case 20:
2563  case 19: case 18: case 17: case 16:
2564  zeros = 2;
2565  break;
2566 
2567  case 15: case 14: case 13: case 12:
2568  case 11: case 10: case 9: case 8:
2569  case 7: case 6: case 5: case 4:
2570  case 3: case 2: case 1: case 0:
2571  zeros = 4;
2572  break;
2573 
2574  default:
2575  return false;
2576  }
2577 
2578  /* Append the value. */
2579  if (UNLIKELY((this->buffer_offset + offset + zeros + 1 + bytes) > this->buffer_length)) {
2580  return 0;
2581  }
2582 
2583  switch (zeros) {
2584  case 0:
2585  this->buffer_memory[this->buffer_offset + offset] = 0xa0 + bytes;
2586  break;
2587 
2588  case 1:
2589  this->buffer_memory[this->buffer_offset + offset] = 0xd9;
2590  this->buffer_memory[this->buffer_offset + offset + 1] = bytes;
2591  break;
2592 
2593  case 2:
2594  this->buffer_memory[this->buffer_offset + offset] = 0xda;
2595  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(bytes));
2596  break;
2597 
2598  case 4:
2599  this->buffer_memory[this->buffer_offset + offset] = 0xdb;
2600  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(bytes));
2601  break;
2602  }
2603  ::memcpy(&(this->buffer_memory[this->buffer_offset + offset + zeros + 1]), value, bytes);
2604 
2605  return zeros + 1 + bytes;
2606 }
2607 
2608 uint32_t MessagePack::append(uint32_t offset, const std::string & value) NO_EXCEPTIONS {
2609  if (UNLIKELY(offset == UINT32_MAX)) {
2610  return 0;
2611  }
2612  uint32_t bytes = value.size();
2613  uint32_t zeros = 0;
2614 
2615  /* Determine the length of the value. */
2616  switch (CLZ32(bytes)) {
2617  case 32: case 31: case 30: case 29: case 28:
2618  zeros = 0;
2619  break;
2620 
2621  case 27: case 26: case 25: case 24:
2622  zeros = 1;
2623  break;
2624 
2625  case 23: case 22: case 21: case 20:
2626  case 19: case 18: case 17: case 16:
2627  zeros = 2;
2628  break;
2629 
2630  case 15: case 14: case 13: case 12:
2631  case 11: case 10: case 9: case 8:
2632  case 7: case 6: case 5: case 4:
2633  case 3: case 2: case 1: case 0:
2634  zeros = 4;
2635  break;
2636 
2637  default:
2638  return false;
2639  }
2640 
2641  /* Append the value. */
2642  if (UNLIKELY((this->buffer_offset + offset + zeros + 1 + bytes) > this->buffer_length)) {
2643  return 0;
2644  }
2645 
2646  switch (zeros) {
2647  case 0:
2648  this->buffer_memory[this->buffer_offset + offset] = 0xa0 + bytes;
2649  break;
2650 
2651  case 1:
2652  this->buffer_memory[this->buffer_offset + offset] = 0xd9;
2653  this->buffer_memory[this->buffer_offset + offset + 1] = bytes;
2654  break;
2655 
2656  case 2:
2657  this->buffer_memory[this->buffer_offset + offset] = 0xda;
2658  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(bytes));
2659  break;
2660 
2661  case 4:
2662  this->buffer_memory[this->buffer_offset + offset] = 0xdb;
2663  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(bytes));
2664  break;
2665  }
2666  ::memcpy(&(this->buffer_memory[this->buffer_offset + offset + zeros + 1]), value.data(), bytes);
2667 
2668  return zeros + 1 + bytes;
2669 }
2670 
2671 uint32_t MessagePack::append(uint32_t offset, bool value) NO_EXCEPTIONS {
2672  if (UNLIKELY(offset == UINT32_MAX)) {
2673  return 0;
2674  }
2675 
2676  /* Append the value. */
2677  if (UNLIKELY((this->buffer_offset + offset + 1) > this->buffer_length)) {
2678  return 0;
2679  }
2680 
2681  if (value) {
2682  this->buffer_memory[this->buffer_offset + offset] = 0xc3;
2683  } else {
2684  this->buffer_memory[this->buffer_offset + offset] = 0xc2;
2685  }
2686  return 1;
2687 }
2688 
2689 uint32_t MessagePack::append(uint32_t offset, int64_t value) NO_EXCEPTIONS {
2690 #if 1
2691  if (UNLIKELY(offset == UINT32_MAX)) {
2692  return 0;
2693  }
2694  uint32_t zeros = 0;
2695 
2696  /* Determine the size of the target. */
2697  if (value > 0) {
2698  switch (CLZ64(value)) {
2699  case 64: case 63: case 62: case 61: case 60: case 59: case 58: case 57:
2700  zeros = 0;
2701  break;
2702 
2703  case 56: case 55: case 54: case 53: case 52: case 51: case 50: case 49:
2704  zeros = 2;
2705  break;
2706 
2707  case 48:
2708  case 47: case 46: case 45: case 44:
2709  case 43: case 42: case 41: case 40:
2710  case 39: case 38: case 37: case 36:
2711  case 35: case 34: case 33:
2712  zeros = 4;
2713  break;
2714 
2715  default:
2716  zeros = 8;
2717  }
2718  } else {
2719  if (value < -32) {
2720  if (value < INT8_MIN) {
2721  if (value < INT16_MIN) {
2722  if (value < INT32_MIN) {
2723  zeros = 8;
2724  } else {
2725  zeros = 4;
2726  }
2727  } else {
2728  zeros = 2;
2729  }
2730  } else {
2731  zeros = 1;
2732  }
2733  }
2734  }
2735 
2736  /* Update the value. */
2737  if ((this->buffer_offset + offset + 1 + zeros) > this->buffer_length) {
2738  return 0;
2739  }
2740 
2741  switch (zeros) {
2742  case 0:
2743  if (value < 0) {
2744  this->buffer_memory[this->buffer_offset + offset] = static_cast<int8_t>(value) | 0xe0;
2745  } else {
2746  this->buffer_memory[this->buffer_offset + offset] = static_cast<int8_t>(value);
2747  }
2748  break;
2749 
2750  case 1:
2751  this->buffer_memory[this->buffer_offset + offset + 1] = static_cast<int8_t>(value);
2752  this->buffer_memory[this->buffer_offset + offset] = 0xd0;
2753 
2754  break;
2755 
2756  case 2:
2757  *(reinterpret_cast<int16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<int16_t>(value));
2758  this->buffer_memory[this->buffer_offset + offset] = 0xd1;
2759 
2760  break;
2761 
2762  case 4:
2763  *(reinterpret_cast<int32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<int32_t>(value));
2764  this->buffer_memory[this->buffer_offset + offset] = 0xd2;
2765 
2766  break;
2767 
2768  case 8:
2769  *(reinterpret_cast<int64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap64(static_cast<int64_t>(value));
2770  this->buffer_memory[this->buffer_offset + offset] = 0xd3;
2771 
2772  break;
2773  }
2774  return 1 + zeros;
2775 #else
2776  int64_t * encoded = reinterpret_cast<int64_t *>(&(reinterpret_cast<char *>(this->buffer_memory)[this->buffer_offset + offset + 1]));
2777 
2778  reinterpret_cast<char *>(this->buffer_memory)[this->buffer_offset + offset] = 0xd3;
2779  *(encoded) = BSWAP64(value);
2780 
2781  return 9;
2782 #endif
2783 }
2784 
2785 uint32_t MessagePack::append(uint32_t offset, uint64_t value) NO_EXCEPTIONS {
2786  if (UNLIKELY(offset == UINT32_MAX)) {
2787  return 0;
2788  }
2789  uint32_t zeros = 0;
2790 
2791  /* Determine the size of the target. */
2792  switch (CLZ64(value)) {
2793  case 64: case 63: case 62: case 61: case 60: case 59: case 58: case 57:
2794  zeros = 0;
2795  break;
2796 
2797  case 56:
2798  zeros = 1;
2799  break;
2800 
2801  case 55: case 54: case 53: case 52:
2802  case 51: case 50: case 49: case 48:
2803  zeros = 2;
2804  break;
2805 
2806  case 47: case 46: case 45: case 44:
2807  case 43: case 42: case 41: case 40:
2808  case 39: case 38: case 37: case 36:
2809  case 35: case 34: case 33: case 32:
2810  zeros = 4;
2811  break;
2812 
2813  default:
2814  zeros = 8;
2815  }
2816 
2817  /* Update the value. */
2818  if ((this->buffer_offset + offset + 1 + zeros) > this->buffer_length) {
2819  return 0;
2820  }
2821 
2822  switch (zeros) {
2823  case 0:
2824  this->buffer_memory[this->buffer_offset + offset] = static_cast<uint8_t>(value);
2825 
2826  break;
2827 
2828  case 1:
2829  this->buffer_memory[this->buffer_offset + offset + 1] = static_cast<uint8_t>(value);
2830  this->buffer_memory[this->buffer_offset + offset] = 0xcc;
2831 
2832  break;
2833 
2834  case 2:
2835  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(value));
2836  this->buffer_memory[this->buffer_offset + offset] = 0xcd;
2837 
2838  break;
2839 
2840  case 4:
2841  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(value));
2842  this->buffer_memory[this->buffer_offset + offset] = 0xce;
2843 
2844  break;
2845 
2846  case 8:
2847  *(reinterpret_cast<uint64_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap64(static_cast<uint64_t>(value));
2848  this->buffer_memory[this->buffer_offset + offset] = 0xcf;
2849 
2850  break;
2851  }
2852  return 1 + zeros;
2853 }
2854 
2855 uint32_t MessagePack::append(uint32_t offset, double value) NO_EXCEPTIONS {
2856  if ((this->buffer_offset + offset + 1 + sizeof(double)) > this->buffer_length) {
2857  return 0;
2858  }
2859  value = this->swap64(value);
2860 
2861  ::memcpy(&(this->buffer_memory[this->buffer_offset + offset + 1]), &(value), sizeof(double));
2862  this->buffer_memory[this->buffer_offset + offset] = 0xcb;
2863 
2864  return 1 + sizeof(double);
2865 }
2866 
2867 uint32_t MessagePack::append(uint32_t offset) NO_EXCEPTIONS {
2868  if (UNLIKELY(offset == UINT32_MAX)) {
2869  return 0;
2870  }
2871 
2872  /* Append the value. */
2873  if (UNLIKELY((this->buffer_offset + offset + 1) > this->buffer_length)) {
2874  return 0;
2875  }
2876  this->buffer_memory[this->buffer_offset + offset] = 0xc0;
2877 
2878  return 1;
2879 }
2880 
2881 uint32_t MessagePack::append_object(uint32_t offset, uint32_t count) NO_EXCEPTIONS {
2882  uint32_t zeros = 0;
2883 
2884  /* Determine the length of the expansion. */
2885  switch (CLZ32(count)) {
2886  case 32: case 31: case 30: case 29: case 28:
2887  zeros = 0;
2888  break;
2889 
2890  case 27: case 26: case 25: case 24:
2891  case 23: case 22: case 21: case 20:
2892  case 19: case 18: case 17: case 16:
2893  zeros = 2;
2894  break;
2895 
2896  case 15: case 14: case 13: case 12:
2897  case 11: case 10: case 9: case 8:
2898  case 7: case 6: case 5: case 4:
2899  case 3: case 2: case 1: case 0:
2900  zeros = 4;
2901  break;
2902 
2903  default:
2904  return 0;
2905  }
2906 
2907  if ((this->buffer_offset + offset + 1 + zeros) > this->buffer_length) {
2908  return 0;
2909  }
2910 
2911  switch (zeros) {
2912  case 0:
2913  this->buffer_memory[this->buffer_offset + offset] = 0x80 | count;
2914  break;
2915 
2916  case 2:
2917  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(count));
2918  this->buffer_memory[this->buffer_offset + offset] = 0xde;
2919  break;
2920 
2921  case 4:
2922  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(count));
2923  this->buffer_memory[this->buffer_offset + offset] = 0xdf;
2924  break;
2925  }
2926  return 1 + zeros;
2927 }
2928 
2929 uint32_t MessagePack::append_vector(uint32_t offset, uint32_t count) NO_EXCEPTIONS {
2930  uint32_t zeros = 0;
2931 
2932  /* Determine the length of the expansion. */
2933  switch (CLZ32(count)) {
2934  case 32: case 31: case 30: case 29: case 28:
2935  break;
2936 
2937  case 27: case 26: case 25: case 24:
2938  case 23: case 22: case 21: case 20:
2939  case 19: case 18: case 17: case 16:
2940  zeros = 2;
2941  break;
2942 
2943  case 15: case 14: case 13: case 12:
2944  case 11: case 10: case 9: case 8:
2945  case 7: case 6: case 5: case 4:
2946  case 3: case 2: case 1: case 0:
2947  zeros = 4;
2948  break;
2949 
2950  default:
2951  return 0;
2952  }
2953 
2954  if ((this->buffer_offset + offset + 1 + zeros) > this->buffer_length) {
2955  return 0;
2956  }
2957 
2958  switch (zeros) {
2959  case 0:
2960  this->buffer_memory[this->buffer_offset + offset] = 0x90 | count;
2961  break;
2962 
2963  case 2:
2964  *(reinterpret_cast<uint16_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap16(static_cast<uint16_t>(count));
2965  this->buffer_memory[this->buffer_offset + offset] = 0xdc;
2966  break;
2967 
2968  case 4:
2969  *(reinterpret_cast<uint32_t *>(&(this->buffer_memory[this->buffer_offset + offset + 1]))) = __builtin_bswap32(static_cast<uint32_t>(count));
2970  this->buffer_memory[this->buffer_offset + offset] = 0xdd;
2971  break;
2972  }
2973  return 1 + zeros;
2974 }
2975 
2976 uint32_t MessagePack::size(void) NO_EXCEPTIONS {
2977  return this->buffer_length - this->buffer_offset - this->buffer_unused;
2978 }
2979 
2980 uint32_t MessagePack::length(void) NO_EXCEPTIONS {
2981  return this->buffer_length;
2982 }
2983 
2984 uint32_t MessagePack::next(uint32_t offset) NO_EXCEPTIONS {
2985  return offset + bytes(offset);
2986 }
2987 
2988 uint32_t MessagePack::down(uint32_t offset) NO_EXCEPTIONS {
2989  switch (this->buffer_memory[this->buffer_offset + offset]) {
2990  case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: /* Fixed object. */
2991  case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
2992  case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97:
2993  case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
2994  return offset + 1;
2995 
2996  case 0xdc: /* Vector with 16 bit length. */
2997  return offset + 3;
2998 
2999  case 0xdd: /* Vector with 32 bit length. */
3000  return offset + 5;
3001 
3002  case 0xde: /* Object with 16 bit length. */
3003  return offset + 3;
3004 
3005  case 0xdf: /* Object with 32 bit length. */
3006  return offset + 5;
3007  }
3008 
3009  return UINT32_MAX;
3010 }
3011 
3012 uint32_t MessagePack::append_kv(uint32_t offset, const char * key, const char * value) NO_EXCEPTIONS {
3013  uint32_t c1, c2;
3014 
3015  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3016  return 0;
3017  }
3018 
3019  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3020  return 0;
3021  }
3022 
3023  return c1 + c2;
3024 }
3025 
3026 uint32_t MessagePack::append_kv(uint32_t offset, const char * key, const std::string & value) NO_EXCEPTIONS {
3027  uint32_t c1, c2;
3028 
3029  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3030  return 0;
3031  }
3032 
3033  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3034  return 0;
3035  }
3036 
3037  return c1 + c2;
3038 }
3039 
3040 uint32_t MessagePack::append_kv(uint32_t offset, const char * key, bool value) NO_EXCEPTIONS {
3041  uint32_t c1, c2;
3042 
3043  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3044  return 0;
3045  }
3046 
3047  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3048  return 0;
3049  }
3050 
3051  return c1 + c2;
3052 }
3053 
3054 uint32_t MessagePack::append_kv(uint32_t offset, const char * key, int64_t value) NO_EXCEPTIONS {
3055  uint32_t c1, c2;
3056 
3057  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3058  return 0;
3059  }
3060 
3061  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3062  return 0;
3063  }
3064 
3065  return c1 + c2;
3066 }
3067 
3068 uint32_t MessagePack::append_kv(uint32_t offset, const char * key, uint64_t value) NO_EXCEPTIONS {
3069  uint32_t c1, c2;
3070 
3071  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3072  return 0;
3073  }
3074 
3075  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3076  return 0;
3077  }
3078 
3079  return c1 + c2;
3080 }
3081 
3082 uint32_t MessagePack::append_kv(uint32_t offset, const char * key, double value) NO_EXCEPTIONS {
3083  uint32_t c1, c2;
3084 
3085  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3086  return 0;
3087  }
3088 
3089  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3090  return 0;
3091  }
3092 
3093  return c1 + c2;
3094 }
3095 
3096 uint32_t MessagePack::append_kv(uint32_t offset, const char * key) NO_EXCEPTIONS {
3097  uint32_t c1, c2;
3098 
3099  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3100  return 0;
3101  }
3102 
3103  if (UNLIKELY((c2 = append(c1 + offset)) == 0)) {
3104  return 0;
3105  }
3106 
3107  return c1 + c2;
3108 }
3109 
3110 uint32_t MessagePack::append_kv(uint32_t offset, const std::string & key, const char * value) NO_EXCEPTIONS {
3111  uint32_t c1, c2;
3112 
3113  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3114  return 0;
3115  }
3116 
3117  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3118  return 0;
3119  }
3120 
3121  return c1 + c2;
3122 }
3123 
3124 uint32_t MessagePack::append_kv(uint32_t offset, const std::string & key, const std::string & value) NO_EXCEPTIONS {
3125  uint32_t c1, c2;
3126 
3127  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3128  return 0;
3129  }
3130 
3131  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3132  return 0;
3133  }
3134 
3135  return c1 + c2;
3136 }
3137 
3138 uint32_t MessagePack::append_kv(uint32_t offset, const std::string & key, bool value) NO_EXCEPTIONS {
3139  uint32_t c1, c2;
3140 
3141  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3142  return 0;
3143  }
3144 
3145  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3146  return 0;
3147  }
3148 
3149  return c1 + c2;
3150 }
3151 
3152 uint32_t MessagePack::append_kv(uint32_t offset, const std::string & key, int64_t value) NO_EXCEPTIONS {
3153  uint32_t c1, c2;
3154 
3155  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3156  return 0;
3157  }
3158 
3159  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3160  return 0;
3161  }
3162 
3163  return c1 + c2;
3164 }
3165 
3166 uint32_t MessagePack::append_kv(uint32_t offset, const std::string & key, uint64_t value) NO_EXCEPTIONS {
3167  uint32_t c1, c2;
3168 
3169  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3170  return 0;
3171  }
3172 
3173  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3174  return 0;
3175  }
3176 
3177  return c1 + c2;
3178 }
3179 
3180 uint32_t MessagePack::append_kv(uint32_t offset, const std::string & key, double value) NO_EXCEPTIONS {
3181  uint32_t c1, c2;
3182 
3183  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3184  return 0;
3185  }
3186 
3187  if (UNLIKELY((c2 = append(c1 + offset, value)) == 0)) {
3188  return 0;
3189  }
3190 
3191  return c1 + c2;
3192 }
3193 
3194 uint32_t MessagePack::append_kv(uint32_t offset, const std::string & key) NO_EXCEPTIONS {
3195  uint32_t c1, c2;
3196 
3197  if (UNLIKELY((c1 = append(offset, key)) == 0)) {
3198  return 0;
3199  }
3200 
3201  if (UNLIKELY((c2 = append(c1 + offset)) == 0)) {
3202  return 0;
3203  }
3204 
3205  return c1 + c2;
3206 }
3207 
3208 const mpack_table_t MessagePack::mpack_table[256] = {
3209  /* Fixed Positive Integer */
3210  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x00 */
3211  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x01 */
3212  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x02 */
3213  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x03 */
3214  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x04 */
3215  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x05 */
3216  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x06 */
3217  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x07 */
3218  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x08 */
3219  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x09 */
3220  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x0a */
3221  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x0b */
3222  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x0c */
3223  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x0d */
3224  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x0e */
3225  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x0f */
3226 
3227  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x10 */
3228  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x11 */
3229  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x12 */
3230  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x13 */
3231  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x14 */
3232  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x15 */
3233  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x16 */
3234  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x17 */
3235  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x18 */
3236  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x19 */
3237  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x1a */
3238  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xab */
3239  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x1c */
3240  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x1d */
3241  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x1e */
3242  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x1f */
3243 
3244  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x20 */
3245  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x21 */
3246  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x22 */
3247  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x23 */
3248  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x24 */
3249  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x25 */
3250  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x26 */
3251  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x27 */
3252  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x28 */
3253  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x29 */
3254  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x2a */
3255  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x2b */
3256  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x2c */
3257  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x2d */
3258  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x2e */
3259  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x2f */
3260 
3261  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x30 */
3262  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x31 */
3263  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x32 */
3264  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x33 */
3265  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x34 */
3266  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x35 */
3267  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x36 */
3268  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x37 */
3269  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x38 */
3270  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x39 */
3271  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x3a */
3272  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x3b */
3273  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x3c */
3274  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x3d */
3275  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x3e */
3276  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x3f */
3277 
3278  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x40 */
3279  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x41 */
3280  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x42 */
3281  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x43 */
3282  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x44 */
3283  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x45 */
3284  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x46 */
3285  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x47 */
3286  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x48 */
3287  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x49 */
3288  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x4a */
3289  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x4b */
3290  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x4c */
3291  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x4d */
3292  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x4e */
3293  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x4f */
3294 
3295  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x50 */
3296  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x51 */
3297  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x52 */
3298  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x53 */
3299  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x54 */
3300  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x55 */
3301  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x56 */
3302  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x57 */
3303  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x58 */
3304  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x59 */
3305  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x5a */
3306  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x5b */
3307  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x5c */
3308  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x5d */
3309  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x5e */
3310  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x5f */
3311 
3312  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x60 */
3313  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x61 */
3314  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x62 */
3315  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x63 */
3316  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x64 */
3317  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x65 */
3318  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x66 */
3319  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x67 */
3320  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x68 */
3321  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x69 */
3322  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x6a */
3323  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x6b */
3324  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x6c */
3325  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x6d */
3326  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x6e */
3327  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x6f */
3328 
3329  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x70 */
3330  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x71 */
3331  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x72 */
3332  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x73 */
3333  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x74 */
3334  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x75 */
3335  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x76 */
3336  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x77 */
3337  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x78 */
3338  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x79 */
3339  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x7a */
3340  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x7b */
3341  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x7c */
3342  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x7d */
3343  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x7e */
3344  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0x7f */
3345 
3346  /* Fixed Object */
3347  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x80 */
3348  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x81 */
3349  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x82 */
3350  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x83 */
3351  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x84 */
3352  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x85 */
3353  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x86 */
3354  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x87 */
3355  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x88 */
3356  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x89 */
3357  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x8a */
3358  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x8b */
3359  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x8c */
3360  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x8d */
3361  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x8e */
3362  { 1, 0x00, 0x01, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0x8f */
3363 
3364  /* Fixed Vector */
3365  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x90 */
3366  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x91 */
3367  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x92 */
3368  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x93 */
3369  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x94 */
3370  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x95 */
3371  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x96 */
3372  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x97 */
3373  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x98 */
3374  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x99 */
3375  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x9a */
3376  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x9b */
3377  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x9c */
3378  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x9d */
3379  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x9e */
3380  { 1, 0x00, 0x00, 0x0f, 0x00000000, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0x9f */
3381 
3382  /* Fixed String */
3383  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa0 */
3384  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa1 */
3385  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa2 */
3386  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa3 */
3387  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa4 */
3388  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa5 */
3389  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa6 */
3390  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa7 */
3391  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa8 */
3392  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xa9 */
3393  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xaa */
3394  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xab */
3395  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xac */
3396  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xad */
3397  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xae */
3398  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xaf */
3399  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb0 */
3400  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb1 */
3401  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb2 */
3402  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb3 */
3403  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb4 */
3404  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb5 */
3405  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb6 */
3406  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb7 */
3407  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb8 */
3408  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xb9 */
3409  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xba */
3410  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xbb */
3411  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xbc */
3412  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xbd */
3413  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xbe */
3414  { 1, 0x1f, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xbf */
3415 
3416  /* Null */
3417  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_NULL, 0x00, 0x0000 }, /* 0xc0 */
3418 
3419  /* Unused */
3420  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_UNKNOWN, 0x00, 0x0000 }, /* 0xc1 */
3421 
3422  /* Boolean */
3423  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_BOOLEAN, 0x00, 0x0000 }, /* 0xc2 */
3424  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_BOOLEAN, 0x00, 0x0000 }, /* 0xc3 */
3425 
3426  /* Binary */
3427  { 2, 0x00, 0x00, 0x00, 0x00000000, 0xff000000, MessagePack::TYPE_BINARY, 0x18, 0x0000 }, /* 0xc4 */
3428  { 3, 0x00, 0x00, 0x00, 0x00000000, 0xffff0000, MessagePack::TYPE_BINARY, 0x10, 0x0000 }, /* 0xc5 */
3429  { 5, 0x00, 0x00, 0x00, 0x00000000, 0xffffffff, MessagePack::TYPE_BINARY, 0x00, 0x0000 }, /* 0xc6 */
3430 
3431  /* Extension */
3432  { 3, 0x00, 0x00, 0x00, 0x00000000, 0xff000000, MessagePack::TYPE_EXTENSION, 0x18, 0x0000 }, /* 0xc7 */
3433  { 4, 0x00, 0x00, 0x00, 0x00000000, 0xffff0000, MessagePack::TYPE_EXTENSION, 0x10, 0x0000 }, /* 0xc8 */
3434  { 6, 0x00, 0x00, 0x00, 0x00000000, 0xffffffff, MessagePack::TYPE_EXTENSION, 0x00, 0x0000 }, /* 0xc9 */
3435 
3436  /* Floating Point */
3437  { 5, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_FLOAT, 0x00, 0x0000 }, /* 0xca */
3438  { 9, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_FLOAT, 0x00, 0x0000 }, /* 0xcb */
3439 
3440  /* Unsigned Integer */
3441  { 2, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_UNSIGNED, 0x00, 0x0000 }, /* 0xcc */
3442  { 3, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_UNSIGNED, 0x00, 0x0000 }, /* 0xcd */
3443  { 5, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_UNSIGNED, 0x00, 0x0000 }, /* 0xce */
3444  { 9, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_UNSIGNED, 0x00, 0x0000 }, /* 0xcf */
3445 
3446  /* Signed Integer */
3447  { 2, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xd0 */
3448  { 3, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xd1 */
3449  { 5, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xd2 */
3450  { 9, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xd3 */
3451 
3452  /* Fixed Extension */
3453  { 3, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_EXTENSION, 0x00, 0x0000 }, /* 0xd4 */
3454  { 4, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_EXTENSION, 0x00, 0x0000 }, /* 0xd5 */
3455  { 6, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_EXTENSION, 0x00, 0x0000 }, /* 0xd6 */
3456  { 10, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_EXTENSION, 0x00, 0x0000 }, /* 0xd7 */
3457  { 18, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_EXTENSION, 0x00, 0x0000 }, /* 0xd8 */
3458 
3459  /* String */
3460  { 2, 0x00, 0x00, 0x00, 0x00000000, 0xff000000, MessagePack::TYPE_STRING, 0x18, 0x0000 }, /* 0xd9 */
3461  { 3, 0x00, 0x00, 0x00, 0x00000000, 0xffff0000, MessagePack::TYPE_STRING, 0x10, 0x0000 }, /* 0xda */
3462  { 5, 0x00, 0x00, 0x00, 0x00000000, 0xffffffff, MessagePack::TYPE_STRING, 0x00, 0x0000 }, /* 0xdb */
3463 
3464  /* Vector */
3465  { 3, 0x00, 0x00, 0x00, 0xffff0000, 0x00000000, MessagePack::TYPE_VECTOR, 0x10, 0x0000 }, /* 0xdc */
3466  { 5, 0x00, 0x00, 0x00, 0xffffffff, 0x00000000, MessagePack::TYPE_VECTOR, 0x00, 0x0000 }, /* 0xdd */
3467 
3468  /* Object */
3469  { 3, 0x00, 0x01, 0x00, 0xffff0000, 0x00000000, MessagePack::TYPE_OBJECT, 0x10, 0x0000 }, /* 0xde */
3470  { 5, 0x00, 0x01, 0x00, 0xffffffff, 0x00000000, MessagePack::TYPE_OBJECT, 0x00, 0x0000 }, /* 0xdf */
3471 
3472  /* Fixed Negative Integer */
3473  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe0 */
3474  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe1 */
3475  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe2 */
3476  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe3 */
3477  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe4 */
3478  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe5 */
3479  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe6 */
3480  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe7 */
3481  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe8 */
3482  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xe9 */
3483  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xea */
3484  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xeb */
3485  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xec */
3486  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xed */
3487  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xee */
3488  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xef */
3489 
3490  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf0 */
3491  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf1 */
3492  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf2 */
3493  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf3 */
3494  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf4 */
3495  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf5 */
3496  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf6 */
3497  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf7 */
3498  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf8 */
3499  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xf9 */
3500  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xfa */
3501  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xfb */
3502  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xfc */
3503  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xfd */
3504  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 }, /* 0xfe */
3505  { 1, 0x00, 0x00, 0x00, 0x00000000, 0x00000000, MessagePack::TYPE_SIGNED, 0x00, 0x0000 } /* 0xff */
3506 };
3507 
3508 /*
3509 ** vim: noet ts=3 sw=3
3510 */