MessagePack for C++
unpack.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ deserializing routine
3 //
4 // Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 #ifndef MSGPACK_V1_UNPACK_HPP
11 #define MSGPACK_V1_UNPACK_HPP
12 
13 #include "msgpack/versioning.hpp"
14 #include "msgpack/unpack_decl.hpp"
15 #include "msgpack/object.hpp"
16 #include "msgpack/zone.hpp"
18 #include "msgpack/unpack_define.h"
19 #include "msgpack/cpp_config.hpp"
20 #include "msgpack/sysdep.h"
21 
22 #include <memory>
23 
24 #if !defined(MSGPACK_USE_CPP03)
25 #include <atomic>
26 #endif
27 
28 
29 #if defined(_MSC_VER)
30 // avoiding confliction std::max, std::min, and macro in windows.h
31 #ifndef NOMINMAX
32 #define NOMINMAX
33 #endif
34 #endif // defined(_MSC_VER)
35 
36 namespace msgpack {
37 
41 
42 namespace detail {
43 
44 class unpack_user {
45 public:
47  void* user_data = MSGPACK_NULLPTR,
48  unpack_limit const& limit = unpack_limit())
49  :m_func(f), m_user_data(user_data), m_limit(limit) {}
50  msgpack::zone const& zone() const { return *m_zone; }
51  msgpack::zone& zone() { return *m_zone; }
52  void set_zone(msgpack::zone& zone) { m_zone = &zone; }
53  bool referenced() const { return m_referenced; }
54  void set_referenced(bool referenced) { m_referenced = referenced; }
55  unpack_reference_func reference_func() const { return m_func; }
56  void* user_data() const { return m_user_data; }
57  unpack_limit const& limit() const { return m_limit; }
58  unpack_limit& limit() { return m_limit; }
59 
60 private:
61  msgpack::zone* m_zone;
62  bool m_referenced;
63  unpack_reference_func m_func;
64  void* m_user_data;
65  unpack_limit m_limit;
66 };
67 
68 inline void unpack_uint8(uint8_t d, msgpack::object& o)
70 
71 inline void unpack_uint16(uint16_t d, msgpack::object& o)
73 
74 inline void unpack_uint32(uint32_t d, msgpack::object& o)
76 
77 inline void unpack_uint64(uint64_t d, msgpack::object& o)
79 
80 inline void unpack_int8(int8_t d, msgpack::object& o)
81 { if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = static_cast<uint64_t>(d); }
82  else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } }
83 
84 inline void unpack_int16(int16_t d, msgpack::object& o)
85 { if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = static_cast<uint64_t>(d); }
86  else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } }
87 
88 inline void unpack_int32(int32_t d, msgpack::object& o)
89 { if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = static_cast<uint64_t>(d); }
90  else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } }
91 
92 inline void unpack_int64(int64_t d, msgpack::object& o)
93 { if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = static_cast<uint64_t>(d); }
94  else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } }
95 
96 inline void unpack_float(float d, msgpack::object& o)
97 { o.type = msgpack::type::FLOAT32; o.via.f64 = d; }
98 
99 inline void unpack_double(double d, msgpack::object& o)
100 { o.type = msgpack::type::FLOAT64; o.via.f64 = d; }
101 
103 { o.type = msgpack::type::NIL; }
104 
106 { o.type = msgpack::type::BOOLEAN; o.via.boolean = true; }
107 
109 { o.type = msgpack::type::BOOLEAN; o.via.boolean = false; }
110 
111 struct unpack_array {
112  void operator()(unpack_user& u, uint32_t n, msgpack::object& o) const {
113  if (n > u.limit().array()) throw msgpack::array_size_overflow("array size overflow");
115  o.via.array.size = 0;
116 
117 #if SIZE_MAX == UINT_MAX
118  if (n > SIZE_MAX/sizeof(msgpack::object))
119  throw msgpack::array_size_overflow("array size overflow");
120 #endif // SIZE_MAX == UINT_MAX
121 
122  size_t size = n*sizeof(msgpack::object);
124  }
125 };
126 
128 {
129 #if defined(__GNUC__) && !defined(__clang__)
130  std::memcpy(&c.via.array.ptr[c.via.array.size++], &o, sizeof(msgpack::object));
131 
132 #else /* __GNUC__ && !__clang__ */
133  c.via.array.ptr[c.via.array.size++] = o;
134 #endif /* __GNUC__ && !__clang__ */
135 }
136 
137 struct unpack_map {
138  void operator()(unpack_user& u, uint32_t n, msgpack::object& o) const {
139  if (n > u.limit().map()) throw msgpack::map_size_overflow("map size overflow");
141  o.via.map.size = 0;
142 
143 #if SIZE_MAX == UINT_MAX
144  if (n > SIZE_MAX/sizeof(msgpack::object_kv))
145  throw msgpack::map_size_overflow("map size overflow");
146 #endif // SIZE_MAX == UINT_MAX
147 
148  size_t size = n*sizeof(msgpack::object_kv);
150  }
151 };
152 
154 {
155 #if defined(__GNUC__) && !defined(__clang__)
156  std::memcpy(&c.via.map.ptr[c.via.map.size].key, &k, sizeof(msgpack::object));
157  std::memcpy(&c.via.map.ptr[c.via.map.size].val, &v, sizeof(msgpack::object));
158 #else /* __GNUC__ && !__clang__ */
159  c.via.map.ptr[c.via.map.size].key = k;
160  c.via.map.ptr[c.via.map.size].val = v;
161 #endif /* __GNUC__ && !__clang__ */
162  ++c.via.map.size;
163 }
164 
165 inline void unpack_str(unpack_user& u, const char* p, uint32_t l, msgpack::object& o)
166 {
168  if (u.reference_func() && u.reference_func()(o.type, l, u.user_data())) {
169  o.via.str.ptr = p;
170  u.set_referenced(true);
171  }
172  else {
173  if (l > u.limit().str()) throw msgpack::str_size_overflow("str size overflow");
174  char* tmp = static_cast<char*>(u.zone().allocate_align(l, MSGPACK_ZONE_ALIGNOF(char)));
175  std::memcpy(tmp, p, l);
176  o.via.str.ptr = tmp;
177  }
178  o.via.str.size = l;
179 }
180 
181 inline void unpack_bin(unpack_user& u, const char* p, uint32_t l, msgpack::object& o)
182 {
184  if (u.reference_func() && u.reference_func()(o.type, l, u.user_data())) {
185  o.via.bin.ptr = p;
186  u.set_referenced(true);
187  }
188  else {
189  if (l > u.limit().bin()) throw msgpack::bin_size_overflow("bin size overflow");
190  char* tmp = static_cast<char*>(u.zone().allocate_align(l, MSGPACK_ZONE_ALIGNOF(char)));
191  std::memcpy(tmp, p, l);
192  o.via.bin.ptr = tmp;
193  }
194  o.via.bin.size = l;
195 }
196 
197 inline void unpack_ext(unpack_user& u, const char* p, std::size_t l, msgpack::object& o)
198 {
200  if (u.reference_func() && u.reference_func()(o.type, l, u.user_data())) {
201  o.via.ext.ptr = p;
202  u.set_referenced(true);
203  }
204  else {
205  if (l > u.limit().ext()) throw msgpack::ext_size_overflow("ext size overflow");
206  char* tmp = static_cast<char*>(u.zone().allocate_align(l, MSGPACK_ZONE_ALIGNOF(char)));
207  std::memcpy(tmp, p, l);
208  o.via.ext.ptr = tmp;
209  }
210  o.via.ext.size = static_cast<uint32_t>(l - 1);
211 }
212 
213 
215 public:
216  msgpack::object const& obj() const { return m_obj; }
217  msgpack::object& obj() { return m_obj; }
218  void set_obj(msgpack::object const& obj) { m_obj = obj; }
219  std::size_t count() const { return m_count; }
220  void set_count(std::size_t count) { m_count = count; }
221  std::size_t decr_count() { return --m_count; }
222  uint32_t container_type() const { return m_container_type; }
223  void set_container_type(uint32_t container_type) { m_container_type = container_type; }
224  msgpack::object const& map_key() const { return m_map_key; }
225  void set_map_key(msgpack::object const& map_key) { m_map_key = map_key; }
226 private:
227  msgpack::object m_obj;
228  std::size_t m_count;
229  uint32_t m_container_type;
230  msgpack::object m_map_key;
231 };
232 
233 inline void init_count(void* buffer)
234 {
235 #if defined(MSGPACK_USE_CPP03)
236  *reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer) = 1;
237 #else // defined(MSGPACK_USE_CPP03)
238  new (buffer) std::atomic<unsigned int>(1);
239 #endif // defined(MSGPACK_USE_CPP03)
240 }
241 
242 inline void decr_count(void* buffer)
243 {
244 #if defined(MSGPACK_USE_CPP03)
245  if(_msgpack_sync_decr_and_fetch(reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer)) == 0) {
246  free(buffer);
247  }
248 #else // defined(MSGPACK_USE_CPP03)
249  if (--*reinterpret_cast<std::atomic<unsigned int>*>(buffer) == 0) {
250  free(buffer);
251  }
252 #endif // defined(MSGPACK_USE_CPP03)
253 }
254 
255 inline void incr_count(void* buffer)
256 {
257 #if defined(MSGPACK_USE_CPP03)
258  _msgpack_sync_incr_and_fetch(reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer));
259 #else // defined(MSGPACK_USE_CPP03)
260  ++*reinterpret_cast<std::atomic<unsigned int>*>(buffer);
261 #endif // defined(MSGPACK_USE_CPP03)
262 }
263 
264 #if defined(MSGPACK_USE_CPP03)
265 inline _msgpack_atomic_counter_t get_count(void* buffer)
266 {
267  return *reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer);
268 }
269 #else // defined(MSGPACK_USE_CPP03)
270 inline std::atomic<unsigned int> const& get_count(void* buffer)
271 {
272  return *reinterpret_cast<std::atomic<unsigned int>*>(buffer);
273 }
274 #endif // defined(MSGPACK_USE_CPP03)
275 
276 template <typename T>
277 struct value {
278  typedef T type;
279 };
280 template <>
281 struct value<fix_tag> {
282  typedef uint32_t type;
283 };
284 
285 template <typename T>
286 inline typename msgpack::enable_if<sizeof(T) == sizeof(fix_tag)>::type load(uint32_t& dst, const char* n) {
287  dst = static_cast<uint32_t>(*reinterpret_cast<const uint8_t*>(n)) & 0x0f;
288 }
289 
290 template <typename T>
291 inline typename msgpack::enable_if<sizeof(T) == 1>::type load(T& dst, const char* n) {
292  dst = static_cast<T>(*reinterpret_cast<const uint8_t*>(n));
293 }
294 
295 template <typename T>
296 inline typename msgpack::enable_if<sizeof(T) == 2>::type load(T& dst, const char* n) {
297  _msgpack_load16(T, n, &dst);
298 }
299 
300 template <typename T>
301 inline typename msgpack::enable_if<sizeof(T) == 4>::type load(T& dst, const char* n) {
302  _msgpack_load32(T, n, &dst);
303 }
304 
305 template <typename T>
306 inline typename msgpack::enable_if<sizeof(T) == 8>::type load(T& dst, const char* n) {
307  _msgpack_load64(T, n, &dst);
308 }
309 
310 class context {
311 public:
312  context(unpack_reference_func f, void* user_data, unpack_limit const& limit)
313  :m_trail(0), m_user(f, user_data, limit), m_cs(MSGPACK_CS_HEADER)
314  {
315  m_stack.reserve(MSGPACK_EMBED_STACK_SIZE);
316  m_stack.push_back(unpack_stack());
317  }
318 
319  void init()
320  {
321  m_cs = MSGPACK_CS_HEADER;
322  m_trail = 0;
323  m_stack.resize(1);
324  m_stack[0].set_obj(msgpack::object());
325  }
326 
327  msgpack::object const& data() const
328  {
329  return m_stack[0].obj();
330  }
331 
333  {
334  return m_user;
335  }
336 
337  unpack_user const& user() const
338  {
339  return m_user;
340  }
341 
342  int execute(const char* data, std::size_t len, std::size_t& off);
343 
344 private:
345  template <typename T>
346  static uint32_t next_cs(T p)
347  {
348  return static_cast<uint32_t>(*p) & 0x1f;
349  }
350 
351  template <typename T, typename Func>
352  int push_aggregate(
353  Func const& f,
354  uint32_t container_type,
355  msgpack::object& obj,
356  const char* load_pos,
357  std::size_t& off) {
358  typename value<T>::type tmp;
359  load<T>(tmp, load_pos);
360  f(m_user, tmp, m_stack.back().obj());
361  if(tmp == 0) {
362  obj = m_stack.back().obj();
363  int ret = push_proc(obj, off);
364  if (ret != 0) return ret;
365  }
366  else {
367  m_stack.back().set_container_type(container_type);
368  m_stack.back().set_count(tmp);
369  if (m_stack.size() <= m_user.limit().depth()) {
370  m_stack.push_back(unpack_stack());
371  }
372  else {
373  throw msgpack::depth_size_overflow("depth size overflow");
374  }
375  m_cs = MSGPACK_CS_HEADER;
376  ++m_current;
377  }
378  return 0;
379  }
380 
381  int push_item(msgpack::object& obj) {
382  bool finish = false;
383  while (!finish) {
384  if(m_stack.size() == 1) {
385  return 1;
386  }
387  unpack_stack& sp = *(m_stack.end() - 2);
388  switch(sp.container_type()) {
389  case MSGPACK_CT_ARRAY_ITEM:
390  unpack_array_item(sp.obj(), obj);
391  if(sp.decr_count() == 0) {
392  obj = sp.obj();
393  m_stack.pop_back();
394  }
395  else {
396  finish = true;
397  }
398  break;
399  case MSGPACK_CT_MAP_KEY:
400  sp.set_map_key(obj);
401  sp.set_container_type(MSGPACK_CT_MAP_VALUE);
402  finish = true;
403  break;
404  case MSGPACK_CT_MAP_VALUE:
405  unpack_map_item(sp.obj(), sp.map_key(), obj);
406  if(sp.decr_count() == 0) {
407  obj = sp.obj();
408  m_stack.pop_back();
409  }
410  else {
411  sp.set_container_type(MSGPACK_CT_MAP_KEY);
412  finish = true;
413  }
414  break;
415  default:
416  return -1;
417  }
418  }
419  return 0;
420  }
421 
422  int push_proc(msgpack::object& obj, std::size_t& off) {
423  int ret = push_item(obj);
424  if (ret > 0) {
425  m_stack[0].set_obj(obj);
426  ++m_current;
427  /*printf("-- finish --\n"); */
428  off = static_cast<std::size_t>(m_current - m_start);
429  }
430  else if (ret < 0) {
431  off = static_cast<std::size_t>(m_current - m_start);
432  }
433  else {
434  m_cs = MSGPACK_CS_HEADER;
435  ++m_current;
436  }
437  return ret;
438  }
439 
440  template <std::size_t N>
441  static void check_ext_size(std::size_t /*size*/) {
442  }
443 
444 private:
445  char const* m_start;
446  char const* m_current;
447 
448  std::size_t m_trail;
449  unpack_user m_user;
450  uint32_t m_cs;
451  std::vector<unpack_stack> m_stack;
452 };
453 
454 template <>
455 inline void context::check_ext_size<4>(std::size_t size) {
456  if (size == 0xffffffff) throw msgpack::ext_size_overflow("ext size overflow");
457 }
458 
459 inline int context::execute(const char* data, std::size_t len, std::size_t& off)
460 {
461  assert(len >= off);
462 
463  m_start = data;
464  m_current = data + off;
465  const char* const pe = data + len;
466  const char* n = MSGPACK_NULLPTR;
467 
468  msgpack::object obj;
469 
470  if(m_current == pe) {
471  off = static_cast<std::size_t>(m_current - m_start);
472  return 0;
473  }
474  bool fixed_trail_again = false;
475  do {
476  if (m_cs == MSGPACK_CS_HEADER) {
477  fixed_trail_again = false;
478  int selector = *reinterpret_cast<const unsigned char*>(m_current);
479  if (0x00 <= selector && selector <= 0x7f) { // Positive Fixnum
480  unpack_uint8(*reinterpret_cast<const uint8_t*>(m_current), obj);
481  int ret = push_proc(obj, off);
482  if (ret != 0) return ret;
483  } else if(0xe0 <= selector && selector <= 0xff) { // Negative Fixnum
484  unpack_int8(*reinterpret_cast<const int8_t*>(m_current), obj);
485  int ret = push_proc(obj, off);
486  if (ret != 0) return ret;
487  } else if (0xc4 <= selector && selector <= 0xdf) {
488  const uint32_t trail[] = {
489  1, // bin 8 0xc4
490  2, // bin 16 0xc5
491  4, // bin 32 0xc6
492  1, // ext 8 0xc7
493  2, // ext 16 0xc8
494  4, // ext 32 0xc9
495  4, // float 32 0xca
496  8, // float 64 0xcb
497  1, // uint 8 0xcc
498  2, // uint 16 0xcd
499  4, // uint 32 0xce
500  8, // uint 64 0xcf
501  1, // int 8 0xd0
502  2, // int 16 0xd1
503  4, // int 32 0xd2
504  8, // int 64 0xd3
505  2, // fixext 1 0xd4
506  3, // fixext 2 0xd5
507  5, // fixext 4 0xd6
508  9, // fixext 8 0xd7
509  17,// fixext 16 0xd8
510  1, // str 8 0xd9
511  2, // str 16 0xda
512  4, // str 32 0xdb
513  2, // array 16 0xdc
514  4, // array 32 0xdd
515  2, // map 16 0xde
516  4, // map 32 0xdf
517  };
518  m_trail = trail[selector - 0xc4];
519  m_cs = next_cs(m_current);
520  fixed_trail_again = true;
521  } else if(0xa0 <= selector && selector <= 0xbf) { // FixStr
522  m_trail = static_cast<uint32_t>(*m_current) & 0x1f;
523  if(m_trail == 0) {
524  unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
525  int ret = push_proc(obj, off);
526  if (ret != 0) return ret;
527  }
528  else {
529  m_cs = MSGPACK_ACS_STR_VALUE;
530  fixed_trail_again = true;
531  }
532 
533  } else if(0x90 <= selector && selector <= 0x9f) { // FixArray
534  int ret = push_aggregate<fix_tag>(
535  unpack_array(), MSGPACK_CT_ARRAY_ITEM, obj, m_current, off);
536  if (ret != 0) return ret;
537  } else if(0x80 <= selector && selector <= 0x8f) { // FixMap
538  int ret = push_aggregate<fix_tag>(
539  unpack_map(), MSGPACK_CT_MAP_KEY, obj, m_current, off);
540  if (ret != 0) return ret;
541  } else if(selector == 0xc2) { // false
542  unpack_false(obj);
543  int ret = push_proc(obj, off);
544  if (ret != 0) return ret;
545  } else if(selector == 0xc3) { // true
546  unpack_true(obj);
547  int ret = push_proc(obj, off);
548  if (ret != 0) return ret;
549  } else if(selector == 0xc0) { // nil
550  unpack_nil(obj);
551  int ret = push_proc(obj, off);
552  if (ret != 0) return ret;
553  } else {
554  off = static_cast<std::size_t>(m_current - m_start);
555  return -1;
556  }
557  // end MSGPACK_CS_HEADER
558  }
559  if (m_cs != MSGPACK_CS_HEADER || fixed_trail_again) {
560  if (fixed_trail_again) {
561  ++m_current;
562  fixed_trail_again = false;
563  }
564  if(static_cast<std::size_t>(pe - m_current) < m_trail) {
565  off = static_cast<std::size_t>(m_current - m_start);
566  return 0;
567  }
568  n = m_current;
569  m_current += m_trail - 1;
570  switch(m_cs) {
571  //case MSGPACK_CS_
572  //case MSGPACK_CS_
573  case MSGPACK_CS_FLOAT: {
574  union { uint32_t i; float f; } mem;
575  load<uint32_t>(mem.i, n);
576  unpack_float(mem.f, obj);
577  int ret = push_proc(obj, off);
578  if (ret != 0) return ret;
579  } break;
580  case MSGPACK_CS_DOUBLE: {
581  union { uint64_t i; double f; } mem;
582  load<uint64_t>(mem.i, n);
583 #if defined(TARGET_OS_IPHONE)
584  // ok
585 #elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi
586  // https://github.com/msgpack/msgpack-perl/pull/1
587  mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
588 #endif
589  unpack_double(mem.f, obj);
590  int ret = push_proc(obj, off);
591  if (ret != 0) return ret;
592  } break;
593  case MSGPACK_CS_UINT_8: {
594  uint8_t tmp;
595  load<uint8_t>(tmp, n);
596  unpack_uint8(tmp, obj);
597  int ret = push_proc(obj, off);
598  if (ret != 0) return ret;
599  } break;
600  case MSGPACK_CS_UINT_16: {
601  uint16_t tmp;
602  load<uint16_t>(tmp, n);
603  unpack_uint16(tmp, obj);
604  int ret = push_proc(obj, off);
605  if (ret != 0) return ret;
606  } break;
607  case MSGPACK_CS_UINT_32: {
608  uint32_t tmp;
609  load<uint32_t>(tmp, n);
610  unpack_uint32(tmp, obj);
611  int ret = push_proc(obj, off);
612  if (ret != 0) return ret;
613  } break;
614  case MSGPACK_CS_UINT_64: {
615  uint64_t tmp;
616  load<uint64_t>(tmp, n);
617  unpack_uint64(tmp, obj);
618  int ret = push_proc(obj, off);
619  if (ret != 0) return ret;
620  } break;
621  case MSGPACK_CS_INT_8: {
622  int8_t tmp;
623  load<int8_t>(tmp, n);
624  unpack_int8(tmp, obj);
625  int ret = push_proc(obj, off);
626  if (ret != 0) return ret;
627  } break;
628  case MSGPACK_CS_INT_16: {
629  int16_t tmp;
630  load<int16_t>(tmp, n);
631  unpack_int16(tmp, obj);
632  int ret = push_proc(obj, off);
633  if (ret != 0) return ret;
634  } break;
635  case MSGPACK_CS_INT_32: {
636  int32_t tmp;
637  load<int32_t>(tmp, n);
638  unpack_int32(tmp, obj);
639  int ret = push_proc(obj, off);
640  if (ret != 0) return ret;
641  } break;
642  case MSGPACK_CS_INT_64: {
643  int64_t tmp;
644  load<int64_t>(tmp, n);
645  unpack_int64(tmp, obj);
646  int ret = push_proc(obj, off);
647  if (ret != 0) return ret;
648  } break;
649  case MSGPACK_CS_FIXEXT_1: {
650  unpack_ext(m_user, n, 1+1, obj);
651  int ret = push_proc(obj, off);
652  if (ret != 0) return ret;
653  } break;
654  case MSGPACK_CS_FIXEXT_2: {
655  unpack_ext(m_user, n, 2+1, obj);
656  int ret = push_proc(obj, off);
657  if (ret != 0) return ret;
658  } break;
659  case MSGPACK_CS_FIXEXT_4: {
660  unpack_ext(m_user, n, 4+1, obj);
661  int ret = push_proc(obj, off);
662  if (ret != 0) return ret;
663  } break;
664  case MSGPACK_CS_FIXEXT_8: {
665  unpack_ext(m_user, n, 8+1, obj);
666  int ret = push_proc(obj, off);
667  if (ret != 0) return ret;
668  } break;
669  case MSGPACK_CS_FIXEXT_16: {
670  unpack_ext(m_user, n, 16+1, obj);
671  int ret = push_proc(obj, off);
672  if (ret != 0) return ret;
673  } break;
674  case MSGPACK_CS_STR_8: {
675  uint8_t tmp;
676  load<uint8_t>(tmp, n);
677  m_trail = tmp;
678  if(m_trail == 0) {
679  unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
680  int ret = push_proc(obj, off);
681  if (ret != 0) return ret;
682  }
683  else {
684  m_cs = MSGPACK_ACS_STR_VALUE;
685  fixed_trail_again = true;
686  }
687  } break;
688  case MSGPACK_CS_BIN_8: {
689  uint8_t tmp;
690  load<uint8_t>(tmp, n);
691  m_trail = tmp;
692  if(m_trail == 0) {
693  unpack_bin(m_user, n, static_cast<uint32_t>(m_trail), obj);
694  int ret = push_proc(obj, off);
695  if (ret != 0) return ret;
696  }
697  else {
698  m_cs = MSGPACK_ACS_BIN_VALUE;
699  fixed_trail_again = true;
700  }
701  } break;
702  case MSGPACK_CS_EXT_8: {
703  uint8_t tmp;
704  load<uint8_t>(tmp, n);
705  m_trail = tmp + 1;
706  if(m_trail == 0) {
707  unpack_ext(m_user, n, m_trail, obj);
708  int ret = push_proc(obj, off);
709  if (ret != 0) return ret;
710  }
711  else {
712  m_cs = MSGPACK_ACS_EXT_VALUE;
713  fixed_trail_again = true;
714  }
715  } break;
716  case MSGPACK_CS_STR_16: {
717  uint16_t tmp;
718  load<uint16_t>(tmp, n);
719  m_trail = tmp;
720  if(m_trail == 0) {
721  unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
722  int ret = push_proc(obj, off);
723  if (ret != 0) return ret;
724  }
725  else {
726  m_cs = MSGPACK_ACS_STR_VALUE;
727  fixed_trail_again = true;
728  }
729  } break;
730  case MSGPACK_CS_BIN_16: {
731  uint16_t tmp;
732  load<uint16_t>(tmp, n);
733  m_trail = tmp;
734  if(m_trail == 0) {
735  unpack_bin(m_user, n, static_cast<uint32_t>(m_trail), obj);
736  int ret = push_proc(obj, off);
737  if (ret != 0) return ret;
738  }
739  else {
740  m_cs = MSGPACK_ACS_BIN_VALUE;
741  fixed_trail_again = true;
742  }
743  } break;
744  case MSGPACK_CS_EXT_16: {
745  uint16_t tmp;
746  load<uint16_t>(tmp, n);
747  m_trail = tmp + 1;
748  if(m_trail == 0) {
749  unpack_ext(m_user, n, m_trail, obj);
750  int ret = push_proc(obj, off);
751  if (ret != 0) return ret;
752  }
753  else {
754  m_cs = MSGPACK_ACS_EXT_VALUE;
755  fixed_trail_again = true;
756  }
757  } break;
758  case MSGPACK_CS_STR_32: {
759  uint32_t tmp;
760  load<uint32_t>(tmp, n);
761  m_trail = tmp;
762  if(m_trail == 0) {
763  unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
764  int ret = push_proc(obj, off);
765  if (ret != 0) return ret;
766  }
767  else {
768  m_cs = MSGPACK_ACS_STR_VALUE;
769  fixed_trail_again = true;
770  }
771  } break;
772  case MSGPACK_CS_BIN_32: {
773  uint32_t tmp;
774  load<uint32_t>(tmp, n);
775  m_trail = tmp;
776  if(m_trail == 0) {
777  unpack_bin(m_user, n, static_cast<uint32_t>(m_trail), obj);
778  int ret = push_proc(obj, off);
779  if (ret != 0) return ret;
780  }
781  else {
782  m_cs = MSGPACK_ACS_BIN_VALUE;
783  fixed_trail_again = true;
784  }
785  } break;
786  case MSGPACK_CS_EXT_32: {
787  uint32_t tmp;
788  load<uint32_t>(tmp, n);
789  check_ext_size<sizeof(std::size_t)>(tmp);
790  m_trail = tmp;
791  ++m_trail;
792  if(m_trail == 0) {
793  unpack_ext(m_user, n, m_trail, obj);
794  int ret = push_proc(obj, off);
795  if (ret != 0) return ret;
796  }
797  else {
798  m_cs = MSGPACK_ACS_EXT_VALUE;
799  fixed_trail_again = true;
800  }
801  } break;
802  case MSGPACK_ACS_STR_VALUE: {
803  unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
804  int ret = push_proc(obj, off);
805  if (ret != 0) return ret;
806  } break;
807  case MSGPACK_ACS_BIN_VALUE: {
808  unpack_bin(m_user, n, static_cast<uint32_t>(m_trail), obj);
809  int ret = push_proc(obj, off);
810  if (ret != 0) return ret;
811  } break;
812  case MSGPACK_ACS_EXT_VALUE: {
813  unpack_ext(m_user, n, m_trail, obj);
814  int ret = push_proc(obj, off);
815  if (ret != 0) return ret;
816  } break;
817  case MSGPACK_CS_ARRAY_16: {
818  int ret = push_aggregate<uint16_t>(
819  unpack_array(), MSGPACK_CT_ARRAY_ITEM, obj, n, off);
820  if (ret != 0) return ret;
821  } break;
822  case MSGPACK_CS_ARRAY_32: {
823  /* FIXME security guard */
824  int ret = push_aggregate<uint32_t>(
825  unpack_array(), MSGPACK_CT_ARRAY_ITEM, obj, n, off);
826  if (ret != 0) return ret;
827  } break;
828  case MSGPACK_CS_MAP_16: {
829  int ret = push_aggregate<uint16_t>(
830  unpack_map(), MSGPACK_CT_MAP_KEY, obj, n, off);
831  if (ret != 0) return ret;
832  } break;
833  case MSGPACK_CS_MAP_32: {
834  /* FIXME security guard */
835  int ret = push_aggregate<uint32_t>(
836  unpack_map(), MSGPACK_CT_MAP_KEY, obj, n, off);
837  if (ret != 0) return ret;
838  } break;
839  default:
840  off = static_cast<std::size_t>(m_current - m_start);
841  return -1;
842  }
843  }
844  } while(m_current != pe);
845 
846  off = static_cast<std::size_t>(m_current - m_start);
847  return 0;
848 }
849 
850 } // detail
851 
852 
854 class unpacker {
855 public:
857 
864  unpacker(unpack_reference_func f = &unpacker::default_reference_func,
865  void* user_data = MSGPACK_NULLPTR,
866  std::size_t initial_buffer_size = MSGPACK_UNPACKER_INIT_BUFFER_SIZE,
867  unpack_limit const& limit = unpack_limit());
868 
869 #if !defined(MSGPACK_USE_CPP03)
870  unpacker(unpacker&& other);
871  unpacker& operator=(unpacker&& other);
872 #endif // !defined(MSGPACK_USE_CPP03)
873 
874  ~unpacker();
875 
876 public:
878 
886 
888 
893  char* buffer();
894 
896 
902  std::size_t buffer_capacity() const;
903 
905 
914  void buffer_consumed(std::size_t size);
915 
917 
930  MSGPACK_DEPRECATED("please use reference version instead")
931  bool next(msgpack::object_handle* result);
932 
934 
947  bool next(msgpack::object_handle& result, bool& referenced);
948 
950 
961  bool next(msgpack::object_handle& result);
962 
964 
967  std::size_t message_size() const;
968 
970  bool execute();
971 
973  msgpack::object const& data();
974 
977 
979  void reset_zone();
980 
982  void reset();
983 
984 public:
986 
992  std::size_t parsed_size() const;
993 
995 
1001  char* nonparsed_buffer();
1002 
1004 
1010  std::size_t nonparsed_size() const;
1011 
1013 
1020  void skip_nonparsed_buffer(std::size_t size);
1021 
1023 
1027  void remove_nonparsed_buffer();
1028 
1029 private:
1030  void expand_buffer(std::size_t size);
1031  int execute_imp();
1032  bool flush_zone();
1033  static bool default_reference_func(msgpack::type::object_type type, std::size_t len, void*);
1034 
1035 private:
1036  char* m_buffer;
1037  std::size_t m_used;
1038  std::size_t m_free;
1039  std::size_t m_off;
1040  std::size_t m_parsed;
1042  std::size_t m_initial_buffer_size;
1043  detail::context m_ctx;
1044 
1045 #if defined(MSGPACK_USE_CPP03)
1046 private:
1047  unpacker(const unpacker&);
1048  unpacker& operator=(const unpacker&);
1049 #else // defined(MSGPACK_USE_CPP03)
1050  unpacker(const unpacker&) = delete;
1051  unpacker& operator=(const unpacker&) = delete;
1052 #endif // defined(MSGPACK_USE_CPP03)
1053 };
1054 
1056  void* user_data,
1057  std::size_t initial_buffer_size,
1058  unpack_limit const& limit)
1059  :m_z(new msgpack::zone), m_ctx(f, user_data, limit)
1060 {
1061  if(initial_buffer_size < COUNTER_SIZE) {
1062  initial_buffer_size = COUNTER_SIZE;
1063  }
1064 
1065  char* buffer = static_cast<char*>(::malloc(initial_buffer_size));
1066  if(!buffer) {
1067  throw std::bad_alloc();
1068  }
1069 
1070  m_buffer = buffer;
1071  m_used = COUNTER_SIZE;
1072  m_free = initial_buffer_size - m_used;
1073  m_off = COUNTER_SIZE;
1074  m_parsed = 0;
1075  m_initial_buffer_size = initial_buffer_size;
1076 
1077  detail::init_count(m_buffer);
1078 
1079  m_ctx.init();
1080  m_ctx.user().set_zone(*m_z);
1081  m_ctx.user().set_referenced(false);
1082 }
1083 
1084 #if !defined(MSGPACK_USE_CPP03)
1085 // Move constructor and move assignment operator
1086 
1088  :m_buffer(other.m_buffer),
1089  m_used(other.m_used),
1090  m_free(other.m_free),
1091  m_off(other.m_off),
1092  m_parsed(other.m_parsed),
1093  m_z(std::move(other.m_z)),
1094  m_initial_buffer_size(other.m_initial_buffer_size),
1095  m_ctx(other.m_ctx) {
1096  other.m_buffer = MSGPACK_NULLPTR;
1097 }
1098 
1100  this->~unpacker();
1101  new (this) unpacker(std::move(other));
1102  return *this;
1103 }
1104 
1105 #endif // !defined(MSGPACK_USE_CPP03)
1106 
1107 
1109 {
1110  // These checks are required for move operations.
1111  if (m_buffer) detail::decr_count(m_buffer);
1112 }
1113 
1114 
1115 inline void unpacker::reserve_buffer(std::size_t size)
1116 {
1117  if(m_free >= size) return;
1118  expand_buffer(size);
1119 }
1120 
1121 inline void unpacker::expand_buffer(std::size_t size)
1122 {
1123  if(m_used == m_off && detail::get_count(m_buffer) == 1
1124  && !m_ctx.user().referenced()) {
1125  // rewind buffer
1126  m_free += m_used - COUNTER_SIZE;
1127  m_used = COUNTER_SIZE;
1128  m_off = COUNTER_SIZE;
1129 
1130  if(m_free >= size) return;
1131  }
1132 
1133  if(m_off == COUNTER_SIZE) {
1134  std::size_t next_size = (m_used + m_free) * 2; // include COUNTER_SIZE
1135  while(next_size < size + m_used) {
1136  std::size_t tmp_next_size = next_size * 2;
1137  if (tmp_next_size <= next_size) {
1138  next_size = size + m_used;
1139  break;
1140  }
1141  next_size = tmp_next_size;
1142  }
1143 
1144  char* tmp = static_cast<char*>(::realloc(m_buffer, next_size));
1145  if(!tmp) {
1146  throw std::bad_alloc();
1147  }
1148 
1149  m_buffer = tmp;
1150  m_free = next_size - m_used;
1151 
1152  } else {
1153  std::size_t next_size = m_initial_buffer_size; // include COUNTER_SIZE
1154  std::size_t not_parsed = m_used - m_off;
1155  while(next_size < size + not_parsed + COUNTER_SIZE) {
1156  std::size_t tmp_next_size = next_size * 2;
1157  if (tmp_next_size <= next_size) {
1158  next_size = size + not_parsed + COUNTER_SIZE;
1159  break;
1160  }
1161  next_size = tmp_next_size;
1162  }
1163 
1164  char* tmp = static_cast<char*>(::malloc(next_size));
1165  if(!tmp) {
1166  throw std::bad_alloc();
1167  }
1168 
1169  detail::init_count(tmp);
1170 
1171  std::memcpy(tmp+COUNTER_SIZE, m_buffer + m_off, not_parsed);
1172 
1173  if(m_ctx.user().referenced()) {
1174  try {
1175  m_z->push_finalizer(&detail::decr_count, m_buffer);
1176  }
1177  catch (...) {
1178  ::free(tmp);
1179  throw;
1180  }
1181  m_ctx.user().set_referenced(false);
1182  } else {
1183  detail::decr_count(m_buffer);
1184  }
1185 
1186  m_buffer = tmp;
1187  m_used = not_parsed + COUNTER_SIZE;
1188  m_free = next_size - m_used;
1189  m_off = COUNTER_SIZE;
1190  }
1191 }
1192 
1193 inline char* unpacker::buffer()
1194 {
1195  return m_buffer + m_used;
1196 }
1197 
1198 inline std::size_t unpacker::buffer_capacity() const
1199 {
1200  return m_free;
1201 }
1202 
1203 inline void unpacker::buffer_consumed(std::size_t size)
1204 {
1205  m_used += size;
1206  m_free -= size;
1207 }
1208 
1209 inline bool unpacker::next(msgpack::object_handle& result, bool& referenced)
1210 {
1211  referenced = false;
1212  int ret = execute_imp();
1213  if(ret < 0) {
1214  throw msgpack::parse_error("parse error");
1215  }
1216 
1217  if(ret == 0) {
1218  result.zone().reset();
1219  result.set(msgpack::object());
1220  return false;
1221 
1222  } else {
1223  referenced = m_ctx.user().referenced();
1224  result.zone().reset( release_zone() );
1225  result.set(data());
1226  reset();
1227  return true;
1228  }
1229 }
1230 
1232 {
1233  bool referenced;
1234  return next(result, referenced);
1235 }
1236 
1238 {
1239  return next(*result);
1240 }
1241 
1242 
1243 inline bool unpacker::execute()
1244 {
1245  int ret = execute_imp();
1246  if(ret < 0) {
1247  throw msgpack::parse_error("parse error");
1248  } else if(ret == 0) {
1249  return false;
1250  } else {
1251  return true;
1252  }
1253 }
1254 
1255 inline int unpacker::execute_imp()
1256 {
1257  std::size_t off = m_off;
1258  int ret = m_ctx.execute(m_buffer, m_used, m_off);
1259  if(m_off > off) {
1260  m_parsed += m_off - off;
1261  }
1262  return ret;
1263 }
1264 
1266 {
1267  return m_ctx.data();
1268 }
1269 
1271 {
1272  if(!flush_zone()) {
1273  return MSGPACK_NULLPTR;
1274  }
1275 
1276  msgpack::zone* r = new msgpack::zone;
1277  msgpack::zone* old = m_z.release();
1278  m_z.reset(r);
1279  m_ctx.user().set_zone(*m_z);
1280 
1281  return old;
1282 }
1283 
1285 {
1286  m_z->clear();
1287 }
1288 
1289 inline bool unpacker::flush_zone()
1290 {
1291  if(m_ctx.user().referenced()) {
1292  try {
1293  m_z->push_finalizer(&detail::decr_count, m_buffer);
1294  } catch (...) {
1295  return false;
1296  }
1297  m_ctx.user().set_referenced(false);
1298 
1299  detail::incr_count(m_buffer);
1300  }
1301 
1302  return true;
1303 }
1304 
1305 inline void unpacker::reset()
1306 {
1307  m_ctx.init();
1308  // don't reset referenced flag
1309  m_parsed = 0;
1310 }
1311 
1312 inline std::size_t unpacker::message_size() const
1313 {
1314  return m_parsed - m_off + m_used;
1315 }
1316 
1317 inline std::size_t unpacker::parsed_size() const
1318 {
1319  return m_parsed;
1320 }
1321 
1323 {
1324  return m_buffer + m_off;
1325 }
1326 
1327 inline std::size_t unpacker::nonparsed_size() const
1328 {
1329  return m_used - m_off;
1330 }
1331 
1332 inline void unpacker::skip_nonparsed_buffer(std::size_t size)
1333 {
1334  m_off += size;
1335 }
1336 
1338 {
1339  m_used = m_off;
1340 }
1341 
1342 namespace detail {
1343 
1344 inline parse_return
1345 unpack_imp(const char* data, std::size_t len, std::size_t& off,
1346  msgpack::zone& result_zone, msgpack::object& result, bool& referenced,
1347  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR,
1348  unpack_limit const& limit = unpack_limit())
1349 {
1350  std::size_t noff = off;
1351 
1352  if(len <= noff) {
1353  // FIXME
1354  return PARSE_CONTINUE;
1355  }
1356 
1357  detail::context ctx(f, user_data, limit);
1358  ctx.init();
1359 
1360  ctx.user().set_zone(result_zone);
1361  ctx.user().set_referenced(false);
1362  referenced = false;
1363 
1364  int e = ctx.execute(data, len, noff);
1365  if(e < 0) {
1366  return PARSE_PARSE_ERROR;
1367  }
1368 
1369  referenced = ctx.user().referenced();
1370  off = noff;
1371 
1372  if(e == 0) {
1373  return PARSE_CONTINUE;
1374  }
1375 
1376  result = ctx.data();
1377 
1378  if(noff < len) {
1379  return PARSE_EXTRA_BYTES;
1380  }
1381 
1382  return PARSE_SUCCESS;
1383 }
1384 
1385 } // detail
1386 
1387 // reference version
1388 
1390  const char* data, std::size_t len, std::size_t& off, bool& referenced,
1391  unpack_reference_func f, void* user_data,
1392  unpack_limit const& limit
1393 )
1394 {
1395  msgpack::object obj;
1397  referenced = false;
1398  std::size_t noff = off;
1400  data, len, noff, *z, obj, referenced, f, user_data, limit);
1401 
1402  switch(ret) {
1403  case PARSE_SUCCESS:
1404  off = noff;
1405  return msgpack::object_handle(obj, msgpack::move(z));
1406  case PARSE_EXTRA_BYTES:
1407  off = noff;
1408  return msgpack::object_handle(obj, msgpack::move(z));
1409  case PARSE_CONTINUE:
1410  throw msgpack::insufficient_bytes("insufficient bytes");
1411  case PARSE_PARSE_ERROR:
1412  default:
1413  throw msgpack::parse_error("parse error");
1414  }
1415  return msgpack::object_handle();
1416 }
1417 
1419  const char* data, std::size_t len, std::size_t& off,
1420  unpack_reference_func f, void* user_data,
1421  unpack_limit const& limit)
1422 {
1423  bool referenced;
1424  return unpack(data, len, off, referenced, f, user_data, limit);
1425 }
1426 
1428  const char* data, std::size_t len, bool& referenced,
1429  unpack_reference_func f, void* user_data,
1430  unpack_limit const& limit)
1431 {
1432  std::size_t off = 0;
1433  return unpack(data, len, off, referenced, f, user_data, limit);
1434 }
1435 
1437  const char* data, std::size_t len,
1438  unpack_reference_func f, void* user_data,
1439  unpack_limit const& limit)
1440 {
1441  bool referenced;
1442  std::size_t off = 0;
1443  return unpack(data, len, off, referenced, f, user_data, limit);
1444 }
1445 
1446 inline void unpack(
1447  msgpack::object_handle& result,
1448  const char* data, std::size_t len, std::size_t& off, bool& referenced,
1449  unpack_reference_func f, void* user_data,
1450  unpack_limit const& limit)
1451 {
1452  msgpack::object obj;
1454  referenced = false;
1455  std::size_t noff = off;
1457  data, len, noff, *z, obj, referenced, f, user_data, limit);
1458 
1459  switch(ret) {
1460  case PARSE_SUCCESS:
1461  off = noff;
1462  result.set(obj);
1463  result.zone() = msgpack::move(z);
1464  return;
1465  case PARSE_EXTRA_BYTES:
1466  off = noff;
1467  result.set(obj);
1468  result.zone() = msgpack::move(z);
1469  return;
1470  case PARSE_CONTINUE:
1471  throw msgpack::insufficient_bytes("insufficient bytes");
1472  case PARSE_PARSE_ERROR:
1473  default:
1474  throw msgpack::parse_error("parse error");
1475  }
1476 }
1477 
1478 inline void unpack(
1479  msgpack::object_handle& result,
1480  const char* data, std::size_t len, std::size_t& off,
1481  unpack_reference_func f, void* user_data,
1482  unpack_limit const& limit)
1483 {
1484  bool referenced;
1485  unpack(result, data, len, off, referenced, f, user_data, limit);
1486 }
1487 
1488 inline void unpack(
1489  msgpack::object_handle& result,
1490  const char* data, std::size_t len, bool& referenced,
1491  unpack_reference_func f, void* user_data,
1492  unpack_limit const& limit)
1493 {
1494  std::size_t off = 0;
1495  unpack(result, data, len, off, referenced, f, user_data, limit);
1496 }
1497 
1498 inline void unpack(
1499  msgpack::object_handle& result,
1500  const char* data, std::size_t len,
1501  unpack_reference_func f, void* user_data,
1502  unpack_limit const& limit)
1503 {
1504  bool referenced;
1505  std::size_t off = 0;
1506  unpack(result, data, len, off, referenced, f, user_data, limit);
1507 }
1508 
1509 
1511  msgpack::zone& z,
1512  const char* data, std::size_t len, std::size_t& off, bool& referenced,
1513  unpack_reference_func f, void* user_data,
1514  unpack_limit const& limit)
1515 {
1516  msgpack::object obj;
1517  std::size_t noff = off;
1518  referenced = false;
1520  data, len, noff, z, obj, referenced, f, user_data, limit);
1521 
1522  switch(ret) {
1523  case PARSE_SUCCESS:
1524  off = noff;
1525  return obj;
1526  case PARSE_EXTRA_BYTES:
1527  off = noff;
1528  return obj;
1529  case PARSE_CONTINUE:
1530  throw msgpack::insufficient_bytes("insufficient bytes");
1531  case PARSE_PARSE_ERROR:
1532  default:
1533  throw msgpack::parse_error("parse error");
1534  }
1535  return obj;
1536 }
1537 
1539  msgpack::zone& z,
1540  const char* data, std::size_t len, std::size_t& off,
1541  unpack_reference_func f, void* user_data,
1542  unpack_limit const& limit)
1543 {
1544  bool referenced;
1545  return unpack(z, data, len, off, referenced, f, user_data, limit);
1546 }
1547 
1549  msgpack::zone& z,
1550  const char* data, std::size_t len, bool& referenced,
1551  unpack_reference_func f, void* user_data,
1552  unpack_limit const& limit)
1553 {
1554  std::size_t off = 0;
1555  return unpack(z, data, len, off, referenced, f, user_data, limit);
1556 }
1557 
1559  msgpack::zone& z,
1560  const char* data, std::size_t len,
1561  unpack_reference_func f, void* user_data,
1562  unpack_limit const& limit)
1563 {
1564  bool referenced;
1565  std::size_t off = 0;
1566  return unpack(z, data, len, off, referenced, f, user_data, limit);
1567 }
1568 
1569 // obsolete
1570 // pointer version
1571 MSGPACK_DEPRECATED("please use reference version instead")
1572 inline void unpack(
1573  msgpack::object_handle* result,
1574  const char* data, std::size_t len, std::size_t* off, bool* referenced,
1575  unpack_reference_func f, void* user_data,
1576  unpack_limit const& limit)
1577 {
1578  if (off)
1579  if (referenced) unpack(*result, data, len, *off, *referenced, f, user_data, limit);
1580  else unpack(*result, data, len, *off, f, user_data, limit);
1581  else
1582  if (referenced) unpack(*result, data, len, *referenced, f, user_data, limit);
1583  else unpack(*result, data, len, f, user_data, limit);
1584 }
1585 
1586 inline bool unpacker::default_reference_func(msgpack::type::object_type /*type*/, std::size_t /*len*/, void*)
1587 {
1588  return true;
1589 }
1590 
1592 } // MSGPACK_API_VERSION_NAMESPACE(v1)
1594 
1595 } // namespace msgpack
1596 
1597 
1598 #endif // MSGPACK_V1_UNPACK_HPP
msgpack::detail::unpack_map_item
void unpack_map_item(msgpack::object &c, msgpack::object const &k, msgpack::object const &v)
Definition: unpack.hpp:153
msgpack::detail::unpack_user::limit
unpack_limit const & limit() const
Definition: unpack.hpp:57
msgpack::detail::unpack_ext
void unpack_ext(unpack_user &u, const char *p, std::size_t l, msgpack::object &o)
Definition: unpack.hpp:197
msgpack::unpack_limit::bin
std::size_t bin() const
Definition: unpack_decl.hpp:105
msgpack::detail::unpack_int64
void unpack_int64(int64_t d, msgpack::object &o)
Definition: unpack.hpp:92
msgpack::detail::unpack_int32
void unpack_int32(int32_t d, msgpack::object &o)
Definition: unpack.hpp:88
msgpack::unpack_limit::ext
std::size_t ext() const
Definition: unpack_decl.hpp:106
msgpack::unpacker::skip_nonparsed_buffer
void skip_nonparsed_buffer(std::size_t size)
Skip the specified size of non-parsed buffer.
Definition: unpack.hpp:1332
msgpack::detail::unpack_user::zone
msgpack::zone & zone()
Definition: unpack.hpp:51
msgpack::detail::unpack_stack::set_count
void set_count(std::size_t count)
Definition: unpack.hpp:220
msgpack::type::STR
@ STR
Definition: object_fwd_decl.hpp:39
msgpack::detail::unpack_int16
void unpack_int16(int16_t d, msgpack::object &o)
Definition: unpack.hpp:84
msgpack::unpacker::buffer
char * buffer()
Get buffer pointer.
Definition: unpack.hpp:1193
msgpack::detail::load
msgpack::enable_if< sizeof(T)==sizeof(fix_tag)>::type load(uint32_t &dst, const char *n)
Definition: unpack.hpp:286
msgpack::detail::context::execute
int execute(const char *data, std::size_t len, std::size_t &off)
Definition: unpack.hpp:459
MSGPACK_UNPACKER_INIT_BUFFER_SIZE
#define MSGPACK_UNPACKER_INIT_BUFFER_SIZE
Definition: unpack_decl.hpp:43
unpack_decl.hpp
msgpack::unpacker::next
bool next(msgpack::object_handle *result)
Unpack one msgpack::object. [obsolete].
Definition: unpack.hpp:1237
msgpack::object_bin::ptr
const char * ptr
Definition: object_fwd.hpp:39
msgpack::detail::context::context
context(unpack_reference_func f, void *user_data, unpack_limit const &limit)
Definition: unpack.hpp:312
msgpack::zone::allocate_align
void * allocate_align(size_t size, size_t align=MSGPACK_ZONE_ALIGN)
Definition: cpp03_zone.hpp:246
msgpack::object::union_type::i64
int64_t i64
Definition: object_fwd.hpp:79
msgpack::unpack_reference_func
bool(* unpack_reference_func)(msgpack::type::object_type type, std::size_t size, void *user_data)
The type of reference or copy judging function.
Definition: unpack_decl.hpp:74
msgpack::object_ext::ptr
const char * ptr
Definition: object_fwd.hpp:46
msgpack::PARSE_PARSE_ERROR
@ PARSE_PARSE_ERROR
Definition: parse_return.hpp:27
msgpack::detail::incr_count
void incr_count(void *buffer)
Definition: unpack.hpp:255
msgpack::detail::unpack_stack::map_key
msgpack::object const & map_key() const
Definition: unpack.hpp:224
msgpack
Definition: adaptor_base.hpp:15
MSGPACK_ZONE_ALIGNOF
#define MSGPACK_ZONE_ALIGNOF(type)
Definition: cpp03_zone_decl.hpp:30
msgpack::object_str::ptr
const char * ptr
Definition: object_fwd.hpp:34
msgpack::str_size_overflow
Definition: unpack_exception.hpp:79
msgpack::unpacker::nonparsed_buffer
char * nonparsed_buffer()
Get the address that is not parsed in the buffer.
Definition: unpack.hpp:1322
msgpack::enable_if
Definition: cpp_config_decl.hpp:56
msgpack::detail::unpack_bin
void unpack_bin(unpack_user &u, const char *p, uint32_t l, msgpack::object &o)
Definition: unpack.hpp:181
msgpack::detail::unpack_user::unpack_user
unpack_user(unpack_reference_func f=MSGPACK_NULLPTR, void *user_data=MSGPACK_NULLPTR, unpack_limit const &limit=unpack_limit())
Definition: unpack.hpp:46
msgpack::depth_size_overflow
Definition: unpack_exception.hpp:106
msgpack::unpack_limit::depth
std::size_t depth() const
Definition: unpack_decl.hpp:107
msgpack::type::object_type
object_type
Definition: object_fwd_decl.hpp:28
msgpack::type::BIN
@ BIN
Definition: object_fwd_decl.hpp:40
msgpack::detail::unpack_map::operator()
void operator()(unpack_user &u, uint32_t n, msgpack::object &o) const
Definition: unpack.hpp:138
msgpack::unpacker::~unpacker
~unpacker()
Definition: unpack.hpp:1108
msgpack::detail::context::user
unpack_user const & user() const
Definition: unpack.hpp:337
msgpack::unpacker::buffer_consumed
void buffer_consumed(std::size_t size)
Notify a buffer consumed information to msgpack::unpacker.
Definition: unpack.hpp:1203
msgpack::detail::unpack_double
void unpack_double(double d, msgpack::object &o)
Definition: unpack.hpp:99
msgpack::object_handle::zone
msgpack::unique_ptr< msgpack::zone > & zone()
Get unique_ptr reference of zone.
Definition: object.hpp:90
msgpack::object_bin::size
uint32_t size
Definition: object_fwd.hpp:38
msgpack::detail::unpack_uint32
void unpack_uint32(uint32_t d, msgpack::object &o)
Definition: unpack.hpp:74
msgpack::object_kv::key
msgpack::object key
Definition: object.hpp:31
msgpack::detail::unpack_int8
void unpack_int8(int8_t d, msgpack::object &o)
Definition: unpack.hpp:80
msgpack::detail::unpack_user::user_data
void * user_data() const
Definition: unpack.hpp:56
msgpack::parse_return
parse_return
Definition: parse_return.hpp:23
msgpack::detail::unpack_user::zone
msgpack::zone const & zone() const
Definition: unpack.hpp:50
msgpack::insufficient_bytes
Definition: unpack_exception.hpp:43
msgpack::PARSE_CONTINUE
@ PARSE_CONTINUE
Definition: parse_return.hpp:26
msgpack::type::FLOAT32
@ FLOAT32
Definition: object_fwd_decl.hpp:33
msgpack::unpacker::nonparsed_size
std::size_t nonparsed_size() const
Get the size of the buffer that is not parsed.
Definition: unpack.hpp:1327
msgpack::detail::unpack_imp
parse_return unpack_imp(const char *data, std::size_t len, std::size_t &off, msgpack::zone &result_zone, msgpack::object &result, bool &referenced, unpack_reference_func f=MSGPACK_NULLPTR, void *user_data=MSGPACK_NULLPTR, unpack_limit const &limit=unpack_limit())
Definition: unpack.hpp:1345
msgpack::detail::unpack_stack::set_map_key
void set_map_key(msgpack::object const &map_key)
Definition: unpack.hpp:225
msgpack::detail::unpack_false
void unpack_false(msgpack::object &o)
Definition: unpack.hpp:108
msgpack::object_handle::set
void set(msgpack::object const &obj)
Definition: object.hpp:64
msgpack::unpacker::reset_zone
void reset_zone()
Definition: unpack.hpp:1284
msgpack::detail::unpack_stack::obj
msgpack::object const & obj() const
Definition: unpack.hpp:216
msgpack::object_ext::size
uint32_t size
Definition: object_fwd.hpp:45
msgpack::unpack
msgpack::object_handle unpack(const char *data, std::size_t len, std::size_t &off, bool &referenced, unpack_reference_func f, void *user_data, unpack_limit const &limit)
Unpack msgpack::object from a buffer.
Definition: unpack.hpp:1389
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
unpack_exception.hpp
msgpack::type::BOOLEAN
@ BOOLEAN
Definition: object_fwd_decl.hpp:30
msgpack::object::via
union_type via
Definition: object_fwd.hpp:93
msgpack::unpacker::message_size
std::size_t message_size() const
Get message size.
Definition: unpack.hpp:1312
msgpack::map_size_overflow
Definition: unpack_exception.hpp:70
msgpack::zone
Definition: cpp03_zone.hpp:22
msgpack::detail::unpack_array_item
void unpack_array_item(msgpack::object &c, msgpack::object const &o)
Definition: unpack.hpp:127
msgpack::detail::unpack_stack::container_type
uint32_t container_type() const
Definition: unpack.hpp:222
msgpack::detail::unpack_user::limit
unpack_limit & limit()
Definition: unpack.hpp:58
msgpack::object_array::ptr
msgpack::object * ptr
Definition: object_fwd.hpp:24
msgpack::detail::unpack_user::set_referenced
void set_referenced(bool referenced)
Definition: unpack.hpp:54
msgpack::detail::get_count
std::atomic< unsigned int > const & get_count(void *buffer)
Definition: unpack.hpp:270
msgpack::detail::context::init
void init()
Definition: unpack.hpp:319
msgpack::detail::unpack_uint64
void unpack_uint64(uint64_t d, msgpack::object &o)
Definition: unpack.hpp:77
msgpack::detail::context::data
msgpack::object const & data() const
Definition: unpack.hpp:327
msgpack::detail::unpack_uint16
void unpack_uint16(uint16_t d, msgpack::object &o)
Definition: unpack.hpp:71
msgpack::detail::unpack_float
void unpack_float(float d, msgpack::object &o)
Definition: unpack.hpp:96
msgpack::detail::unpack_nil
void unpack_nil(msgpack::object &o)
Definition: unpack.hpp:102
msgpack::unpacker::parsed_size
std::size_t parsed_size() const
Get parsed message size.
Definition: unpack.hpp:1317
msgpack::detail::unpack_stack::set_container_type
void set_container_type(uint32_t container_type)
Definition: unpack.hpp:223
msgpack::detail::unpack_str
void unpack_str(unpack_user &u, const char *p, uint32_t l, msgpack::object &o)
Definition: unpack.hpp:165
msgpack::unpack_limit::str
std::size_t str() const
Definition: unpack_decl.hpp:104
msgpack::object::union_type::map
msgpack::object_map map
Definition: object_fwd.hpp:86
msgpack::array_size_overflow
Definition: unpack_exception.hpp:61
msgpack::detail::unpack_stack
Definition: unpack.hpp:214
msgpack::unpacker::reset
void reset()
Definition: unpack.hpp:1305
msgpack::type::FLOAT64
@ FLOAT64
Definition: object_fwd_decl.hpp:34
versioning.hpp
msgpack::type::size
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
MSGPACK_NULLPTR
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:35
msgpack::detail::unpack_array
Definition: unpack.hpp:111
msgpack::object_array::size
uint32_t size
Definition: object_fwd.hpp:23
msgpack::type::NEGATIVE_INTEGER
@ NEGATIVE_INTEGER
Definition: object_fwd_decl.hpp:32
msgpack::detail::unpack_user::set_zone
void set_zone(msgpack::zone &zone)
Definition: unpack.hpp:52
msgpack::object::union_type::array
msgpack::object_array array
Definition: object_fwd.hpp:85
msgpack::detail::value::type
T type
Definition: unpack.hpp:278
msgpack::type::ARRAY
@ ARRAY
Definition: object_fwd_decl.hpp:41
msgpack::unpacker::unpacker
unpacker(unpack_reference_func f=&unpacker::default_reference_func, void *user_data=MSGPACK_NULLPTR, std::size_t initial_buffer_size=MSGPACK_UNPACKER_INIT_BUFFER_SIZE, unpack_limit const &limit=unpack_limit())
Constructor.
Definition: unpack.hpp:1055
msgpack::detail::decr_count
void decr_count(void *buffer)
Definition: unpack.hpp:242
msgpack::object_kv
Definition: object.hpp:30
msgpack::parse_error
Definition: unpack_exception.hpp:34
msgpack::detail::unpack_stack::obj
msgpack::object & obj()
Definition: unpack.hpp:217
msgpack::object::union_type::ext
msgpack::object_ext ext
Definition: object_fwd.hpp:89
msgpack::object_str::size
uint32_t size
Definition: object_fwd.hpp:33
msgpack::type::NIL
@ NIL
Definition: object_fwd_decl.hpp:29
msgpack::unpacker::release_zone
msgpack::zone * release_zone()
Definition: unpack.hpp:1270
msgpack::object_handle
The class holds object and zone.
Definition: object.hpp:44
msgpack::unique_ptr< msgpack::zone >
msgpack::detail::unpack_user
Definition: unpack.hpp:44
msgpack::detail::unpack_uint8
void unpack_uint8(uint8_t d, msgpack::object &o)
Definition: unpack.hpp:68
msgpack::object::union_type::u64
uint64_t u64
Definition: object_fwd.hpp:78
msgpack::detail::context
Definition: unpack.hpp:310
msgpack::object::union_type::bin
msgpack::object_bin bin
Definition: object_fwd.hpp:88
msgpack::detail::unpack_stack::set_obj
void set_obj(msgpack::object const &obj)
Definition: unpack.hpp:218
msgpack::unpacker::buffer_capacity
std::size_t buffer_capacity() const
Get buffer capacity.
Definition: unpack.hpp:1198
msgpack::type::EXT
@ EXT
Definition: object_fwd_decl.hpp:43
msgpack::unpacker::reserve_buffer
void reserve_buffer(std::size_t size=MSGPACK_UNPACKER_RESERVE_SIZE)
Reserve a buffer memory.
Definition: unpack.hpp:1115
msgpack::detail::init_count
void init_count(void *buffer)
Definition: unpack.hpp:233
COUNTER_SIZE
const size_t COUNTER_SIZE
Definition: unpack_decl.hpp:40
msgpack::detail::unpack_user::referenced
bool referenced() const
Definition: unpack.hpp:53
zone.hpp
msgpack::object_map::size
uint32_t size
Definition: object_fwd.hpp:28
msgpack::detail::unpack_stack::decr_count
std::size_t decr_count()
Definition: unpack.hpp:221
msgpack::move
T & move(T &t)
msgpack::detail::value
Definition: unpack.hpp:277
msgpack::object::union_type::boolean
bool boolean
Definition: object_fwd.hpp:77
cpp_config.hpp
msgpack::object::union_type::f64
double f64
Definition: object_fwd.hpp:84
msgpack::unpacker::execute
bool execute()
Definition: unpack.hpp:1243
msgpack::object_kv::val
msgpack::object val
Definition: object.hpp:32
msgpack::unpacker::remove_nonparsed_buffer
void remove_nonparsed_buffer()
Remove nonparsed buffer and reset the current position as a new start point.
Definition: unpack.hpp:1337
msgpack::ext_size_overflow
Definition: unpack_exception.hpp:97
msgpack::detail::unpack_user::reference_func
unpack_reference_func reference_func() const
Definition: unpack.hpp:55
msgpack::detail::context::user
unpack_user & user()
Definition: unpack.hpp:332
MSGPACK_DEPRECATED
#define MSGPACK_DEPRECATED(msg)
Definition: cpp_config.hpp:136
MSGPACK_UNPACKER_RESERVE_SIZE
#define MSGPACK_UNPACKER_RESERVE_SIZE
Definition: unpack_decl.hpp:47
msgpack::unpacker
Unpacking class for a stream deserialization.
Definition: unpack.hpp:854
msgpack::detail::fix_tag
Definition: unpack_decl.hpp:180
msgpack::unpacker::data
msgpack::object const & data()
Definition: unpack.hpp:1265
msgpack::object
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
msgpack::object_map::ptr
msgpack::object_kv * ptr
Definition: object_fwd.hpp:29
msgpack::bin_size_overflow
Definition: unpack_exception.hpp:88
object.hpp
msgpack::detail::value< fix_tag >::type
uint32_t type
Definition: unpack.hpp:282
msgpack::detail::unpack_true
void unpack_true(msgpack::object &o)
Definition: unpack.hpp:105
msgpack::detail::unpack_stack::count
std::size_t count() const
Definition: unpack.hpp:219
msgpack::PARSE_SUCCESS
@ PARSE_SUCCESS
Definition: parse_return.hpp:24
msgpack::unpack_limit::map
std::size_t map() const
Definition: unpack_decl.hpp:103
msgpack::unpack_limit::array
std::size_t array() const
Definition: unpack_decl.hpp:102
msgpack::unpacker::operator=
unpacker & operator=(unpacker &&other)
Definition: unpack.hpp:1099
msgpack::object::type
msgpack::type::object_type type
Definition: object_fwd.hpp:92
msgpack::type::POSITIVE_INTEGER
@ POSITIVE_INTEGER
Definition: object_fwd_decl.hpp:31
msgpack::object::union_type::str
msgpack::object_str str
Definition: object_fwd.hpp:87
msgpack::PARSE_EXTRA_BYTES
@ PARSE_EXTRA_BYTES
Definition: parse_return.hpp:25
msgpack::type::MAP
@ MAP
Definition: object_fwd_decl.hpp:42
msgpack::unpack_limit
Definition: unpack_decl.hpp:87
msgpack::detail::unpack_array::operator()
void operator()(unpack_user &u, uint32_t n, msgpack::object &o) const
Definition: unpack.hpp:112
msgpack::detail::unpack_map
Definition: unpack.hpp:137