msgpack11.cpp
Go to the documentation of this file.
1 #include "msgpack11.hpp"
2 #include <array>
3 #include <cassert>
4 #include <cmath>
5 #include <cstdlib>
6 #include <cstdio>
7 #include <limits>
8 #include <array>
9 #include <tuple>
10 #include <algorithm>
11 #include <functional>
12 #include <stdexcept>
13 #include <type_traits>
14 #include <cstdint>
15 
16 namespace msgpack11 {
17 
18 static const int max_depth = 200;
19 
20 using std::string;
21 using std::vector;
22 using std::map;
23 using std::make_shared;
24 using std::initializer_list;
25 using std::move;
26 
27 /* Helper for representing null - just a do-nothing struct, plus comparison
28  * operators so the helpers in MsgPackValue work. We can't use nullptr_t because
29  * it may not be orderable.
30  */
31 struct NullStruct {
32  bool operator==(NullStruct) const { return true; }
33  bool operator<(NullStruct) const { return false; }
34 };
35 
36 /* * * * * * * * * * * * * * * * * * * *
37  * MasPackValue
38  */
39 
40 class MsgPackValue {
41 public:
42  virtual bool equals(const MsgPackValue * other) const = 0;
43  virtual bool less(const MsgPackValue * other) const = 0;
44  virtual void dump(std::ostream& os) const = 0;
45  virtual MsgPack::Type type() const = 0;
46  virtual double number_value() const;
47  virtual float float32_value() const;
48  virtual double float64_value() const;
49  virtual int32_t int_value() const;
50  virtual int8_t int8_value() const;
51  virtual int16_t int16_value() const;
52  virtual int32_t int32_value() const;
53  virtual int64_t int64_value() const;
54  virtual uint8_t uint8_value() const;
55  virtual uint16_t uint16_value() const;
56  virtual uint32_t uint32_value() const;
57  virtual uint64_t uint64_value() const;
58  virtual bool bool_value() const;
59  virtual const std::string &string_value() const;
60  virtual const MsgPack::array &array_items() const;
61  virtual const MsgPack::binary &binary_items() const;
62  virtual const MsgPack &operator[](size_t i) const;
63  virtual const MsgPack::object &object_items() const;
64  virtual const MsgPack &operator[](const std::string &key) const;
65  virtual const MsgPack::extension &extension_items() const;
66  virtual ~MsgPackValue() {}
67 };
68 
69 /* * * * * * * * * * * * * * * * * * * *
70  * Serialization
71  */
72 
73 namespace {
74 static const union {
75  uint16_t dummy;
76  uint8_t bytes[2];
77 } endian_check_data { 0x0001 };
78 static const bool is_big_endian = endian_check_data.bytes[0] == 0x00;
79 
80 template< typename T >
81 void dump_data(const T value, std::ostream& os)
82 {
83  union {
84  T packed;
85  std::array<uint8_t, sizeof(T)> bytes;
86  } converter;
87  converter.packed = value;
88 
89  int const n = sizeof(T);
90  int const offsets[] = {(n-1), 0};
91  int const directions[] = {-1, 1};
92  uint8_t const off = offsets[static_cast<int>(is_big_endian)];
93  int const dir = directions[static_cast<int>(is_big_endian)];
94  for(int i = 0; i < n; ++i)
95  {
96  os.put(converter.bytes[off + dir * i]);
97  }
98 }
99 
100 inline void dump(NullStruct, std::ostream& os) {
101  os.put(0xc0);
102 }
103 
104 inline void dump(float value, std::ostream& os) {
105  os.put(0xca);
106  dump_data(value, os);
107 }
108 
109 inline void dump(double value, std::ostream& os) {
110  os.put(0xcb);
111  dump_data(value, os);
112 }
113 
114 inline void dump(uint8_t value, std::ostream& os) {
115  if(128 <= value)
116  {
117  os.put(0xcc);
118  }
119  os.put(value);
120 }
121 
122 inline void dump(uint16_t value, std::ostream& os) {
123  if( value < (1 << 8) )
124  {
125  dump(static_cast<uint8_t>(value), os );
126  }
127  else
128  {
129  os.put(0xcd);
130  dump_data(value, os);
131  }
132 }
133 
134 inline void dump(uint32_t value, std::ostream& os) {
135  if( value < (1 << 16) )
136  {
137  dump(static_cast<uint16_t>(value), os );
138  }
139  else
140  {
141  os.put(0xce);
142  dump_data(value, os);
143  }
144 }
145 
146 inline void dump(uint64_t value, std::ostream& os) {
147  if( value < (1ULL << 32) )
148  {
149  dump(static_cast<uint32_t>(value), os );
150  }
151  else
152  {
153  os.put(0xcf);
154  dump_data(value, os);
155  }
156 }
157 
158 inline void dump(int8_t value, std::ostream& os) {
159  if( value < -32 )
160  {
161  os.put(0xd0);
162  }
163  os.put(value);
164 }
165 
166 inline void dump(int16_t value, std::ostream& os) {
167  if( value < -(1 << 7) )
168  {
169  os.put(0xd1);
170  dump_data(value, os);
171  }
172  else if( value <= 0 )
173  {
174  dump(static_cast<int8_t>(value), os );
175  }
176  else
177  {
178  dump(static_cast<uint16_t>(value), os );
179  }
180 }
181 
182 inline void dump(int32_t value, std::ostream& os) {
183  if( value < -(1 << 15) )
184  {
185  os.put(0xd2);
186  dump_data(value, os);
187  }
188  else if( value <= 0 )
189  {
190  dump(static_cast<int16_t>(value), os );
191  }
192  else
193  {
194  dump(static_cast<uint32_t>(value), os );
195  }
196 }
197 
198 inline void dump(int64_t value, std::ostream& os) {
199  if( value < -(1LL << 31) )
200  {
201  os.put(0xd3);
202  dump_data(value, os);
203  }
204  else if( value <= 0 )
205  {
206  dump(static_cast<int32_t>(value), os );
207  }
208  else
209  {
210  dump(static_cast<uint64_t>(value), os );
211  }
212 }
213 
214 inline void dump(bool value, std::ostream& os) {
215  const uint8_t msgpack_value = (value) ? 0xc3 : 0xc2;
216  os.put(msgpack_value);
217 }
218 
219 inline void dump(const std::string& value, std::ostream& os) {
220  size_t const len = value.size();
221  if(len <= 0x1f)
222  {
223  uint8_t const first_byte = 0xa0 | static_cast<uint8_t>(len);
224  os.put(first_byte);
225  }
226  else if(len <= 0xff)
227  {
228  os.put(0xd9);
229  os.put(static_cast<uint8_t>(len));
230  }
231  else if(len <= 0xffff)
232  {
233  os.put(0xda);
234  dump_data(static_cast<uint16_t>(len), os);
235  }
236  else if(len <= 0xffffffff)
237  {
238  os.put(0xdb);
239  dump_data(static_cast<uint32_t>(len), os);
240  }
241  else
242  {
243  throw std::runtime_error("exceeded maximum data length");
244  }
245 
246  std::for_each(std::begin(value), std::end(value), [&os](char v){
247  dump_data(v, os);
248  });
249 }
250 
251 inline void dump(const MsgPack::array& value, std::ostream& os) {
252  size_t const len = value.size();
253  if(len <= 15)
254  {
255  uint8_t const first_byte = 0x90 | static_cast<uint8_t>(len);
256  os.put(first_byte);
257  }
258  else if(len <= 0xffff)
259  {
260  os.put(0xdc);
261  dump_data(static_cast<uint16_t>(len), os);
262  }
263  else if(len <= 0xffffffff)
264  {
265  os.put(0xdd);
266  dump_data(static_cast<uint32_t>(len), os);
267  }
268  else
269  {
270  throw std::runtime_error("exceeded maximum data length");
271  }
272 
273  std::for_each(std::begin(value), std::end(value), [&os](MsgPack::array::value_type const& v){
274  os << v;
275  });
276 }
277 
278 inline void dump(const MsgPack::object& value, std::ostream& os) {
279  size_t const len = value.size();
280  if(len <= 15)
281  {
282  uint8_t const first_byte = 0x80 | static_cast<uint8_t>(len);
283  os.put(first_byte);
284  }
285  else if(len <= 0xffff)
286  {
287  os.put(0xde);
288  dump_data(static_cast<uint16_t>(len), os);
289  }
290  else if(len <= 0xffffffff)
291  {
292  os.put(0xdf);
293  dump_data(static_cast<uint32_t>(len), os);
294  }
295  else
296  {
297  throw std::runtime_error("too long value.");
298  }
299 
300  std::for_each(std::begin(value), std::end(value), [&os](MsgPack::object::value_type const& v){
301  os << v.first;
302  os << v.second;
303  });
304 }
305 
306 inline void dump(const MsgPack::binary& value, std::ostream& os) {
307  size_t const len = value.size();
308  if(len <= 0xff)
309  {
310  os.put(0xc4);
311  dump_data(static_cast<uint8_t>(len), os);
312  }
313  else if(len <= 0xffff)
314  {
315  os.put(0xc5);
316  dump_data(static_cast<uint16_t>(len), os);
317  }
318  else if(len <= 0xffffffff)
319  {
320  os.put(0xc6);
321  dump_data(static_cast<uint32_t>(len), os);
322  }
323  else
324  {
325  throw std::runtime_error("exceeded maximum data length");
326  }
327  os.write(reinterpret_cast<const char*>(value.data()), value.size());
328 }
329 
330 inline void dump(const MsgPack::extension& value, std::ostream& os) {
331  const uint8_t type = std::get<0>( value );
332  const MsgPack::binary& data = std::get<1>( value );
333  const size_t len = data.size();
334 
335  if(len == 0x01) {
336  os.put(0xd4);
337  }
338  else if(len == 0x02) {
339  os.put(0xd5);
340  }
341  else if(len == 0x04) {
342  os.put(0xd6);
343  }
344  else if(len == 0x08) {
345  os.put(0xd7);
346  }
347  else if(len == 0x10) {
348  os.put(0xd8);
349  }
350  else if(len <= 0xff) {
351  os.put(0xc7);
352  os.put(static_cast<uint8_t>(len));
353  }
354  else if(len <= 0xffff) {
355  os.put(0xc8);
356  dump_data(static_cast<uint16_t>(len), os);
357  }
358  else if(len <= 0xffffffff) {
359  os.put(0xc9);
360  dump_data(static_cast<uint32_t>(len), os);
361  }
362  else {
363  throw std::runtime_error("exceeded maximum data length");
364  }
365 
366  os.put(type);
367  os.write(reinterpret_cast<const char*>(data.data()), data.size());
368 }
369 }
370 
371 std::ostream& operator<<(std::ostream& os, const MsgPack& msgpack) {
372  msgpack.m_ptr->dump(os);
373  return os;
374 }
375 
376 
377 
378 /* * * * * * * * * * * * * * * * * * * *
379  * Value wrappers
380  */
381 
382 template <MsgPack::Type tag, typename T>
383 class Value : public MsgPackValue {
384 protected:
385 
386  // Constructors
387  explicit Value(const T &value) : m_value(value) {}
388  explicit Value(T &&value) : m_value(move(value)) {}
389 
390  // Get type tag
391  MsgPack::Type type() const override {
392  return tag;
393  }
394 
395  // Comparisons
396  bool equals(const MsgPackValue * other) const override {
397  bool const is_same_type = tag == other->type();
398  return is_same_type && (m_value == static_cast<const Value<tag, T> *>(other)->m_value);
399  }
400  bool less(const MsgPackValue * other) const override {
401  bool const is_same_type = tag == other->type();
402  bool const is_less_type = tag < other->type();
403  return is_less_type || (is_same_type && (m_value < static_cast<const Value<tag, T> *>(other)->m_value));
404  }
405 
406  const T m_value;
407  void dump(std::ostream& os) const override { msgpack11::dump(m_value, os); }
408 };
409 
410 bool equal_uint64_int64( uint64_t uint64_value, int64_t int64_value )
411 {
412  bool const is_positive = 0 <= int64_value;
413  bool const is_leq_int64_max = uint64_value <= static_cast<std::uint64_t>(std::numeric_limits<int64_t>::max());
414  return is_positive && is_leq_int64_max && ( uint64_value == static_cast<uint64_t>(int64_value));
415 }
416 
417 bool less_uint64_int64( uint64_t uint64_value, int64_t int64_value )
418 {
419  bool const is_positive = 0 <= int64_value;
420  bool const is_leq_int64_max = uint64_value <= static_cast<std::uint64_t>(std::numeric_limits<int64_t>::max());
421  return is_positive && is_leq_int64_max && ( uint64_value < static_cast<uint64_t>(int64_value));
422 }
423 
424 bool less_int64_uint64( int64_t int64_value, uint64_t uint64_value )
425 {
426  bool const is_negative = int64_value < 0;
427  bool const is_gt_int64_max = static_cast<std::uint64_t>(std::numeric_limits<int64_t>::max()) < uint64_value;
428  return is_negative || is_gt_int64_max || ( static_cast<uint64_t>(int64_value) < uint64_value );
429 }
430 
431 template <MsgPack::Type tag, typename T>
432 class NumberValue : public Value<tag, T> {
433 protected:
434 
435  // Constructors
436  explicit NumberValue(const T &value) : Value<tag, T>(value) {}
437  explicit NumberValue(T &&value) : Value<tag, T>(move(value)) {}
438 
439  bool equals(const MsgPackValue * other) const override {
440  switch( other->type() )
441  {
442  case MsgPack::FLOAT32 : // fall through
443  case MsgPack::FLOAT64 : // fall through
444  case MsgPack::UINT8 : // fall through
445  case MsgPack::UINT16 : // fall through
446  case MsgPack::UINT32 : // fall through
447  case MsgPack::UINT64 : // fall through
448  case MsgPack::INT8 : // fall through
449  case MsgPack::INT16 : // fall through
450  case MsgPack::INT32 : // fall through
451  case MsgPack::INT64 : // fall through
452  {
453  return float64_value() == other->float64_value();
454  } break;
455  default :
456  {
457  return Value<tag,T>::equals( other );
458  } break;
459  }
460  }
461 
462  bool less(const MsgPackValue * other) const override {
463  switch( other->type() )
464  {
465  case MsgPack::FLOAT32 : // fall through
466  case MsgPack::FLOAT64 : // fall through
467  case MsgPack::UINT8 : // fall through
468  case MsgPack::UINT16 : // fall through
469  case MsgPack::UINT32 : // fall through
470  case MsgPack::UINT64 : // fall through
471  case MsgPack::INT8 : // fall through
472  case MsgPack::INT16 : // fall through
473  case MsgPack::INT32 : // fall through
474  case MsgPack::INT64 : // fall through
475  {
476  return float64_value() < other->float64_value();
477  } break;
478  default :
479  {
480  return Value<tag,T>::less( other );
481  } break;
482  }
483  }
484 
485  double number_value() const override { return static_cast<double>( Value<tag,T>::m_value ); }
486  float float32_value() const override { return static_cast<float>( Value<tag,T>::m_value ); }
487  double float64_value() const override { return static_cast<double>( Value<tag,T>::m_value ); }
488  int32_t int_value() const override { return static_cast<int32_t>( Value<tag,T>::m_value ); }
489  int8_t int8_value() const override { return static_cast<int8_t>( Value<tag,T>::m_value ); }
490  int16_t int16_value() const override { return static_cast<int16_t>( Value<tag,T>::m_value ); }
491  int32_t int32_value() const override { return static_cast<int32_t>( Value<tag,T>::m_value ); }
492  int64_t int64_value() const override { return static_cast<int64_t>( Value<tag,T>::m_value ); }
493  uint8_t uint8_value() const override { return static_cast<uint8_t>( Value<tag,T>::m_value ); }
494  uint16_t uint16_value() const override { return static_cast<uint16_t>( Value<tag,T>::m_value ); }
495  uint32_t uint32_value() const override { return static_cast<uint32_t>( Value<tag,T>::m_value ); }
496  uint64_t uint64_value() const override { return static_cast<uint64_t>( Value<tag,T>::m_value ); }
497 };
498 
499 class MsgPackFloat final : public NumberValue<MsgPack::FLOAT32, float> {
500 public:
501  explicit MsgPackFloat(float value) : NumberValue(value) {}
502 };
503 
504 class MsgPackDouble final : public NumberValue<MsgPack::FLOAT64, double> {
505 public:
506  explicit MsgPackDouble(double value) : NumberValue(value) {}
507 };
508 
509 class MsgPackInt8 final : public NumberValue<MsgPack::INT8, int8_t> {
510 public:
511  explicit MsgPackInt8(int8_t value) : NumberValue(value) {}
512 };
513 
514 class MsgPackInt16 final : public NumberValue<MsgPack::INT16, int16_t> {
515 public:
516  explicit MsgPackInt16(int16_t value) : NumberValue(value) {}
517 };
518 
519 class MsgPackInt32 final : public NumberValue<MsgPack::INT32, int32_t> {
520 public:
521  explicit MsgPackInt32(int32_t value) : NumberValue(value) {}
522 };
523 
524 class MsgPackInt64 final : public NumberValue<MsgPack::INT64, int64_t> {
525  bool equals(const MsgPackValue * other) const override
526  {
527  switch( other->type() )
528  {
529  case MsgPack::INT64 :
530  {
531  return int64_value() == other->int64_value();
532  } break;
533  case MsgPack::UINT64 :
534  {
535  return equal_uint64_int64( other->uint64_value(), int64_value() );
536  } break;
537  default :
538  {
540  }
541  }
542  }
543  bool less(const MsgPackValue * other) const override
544  {
545  switch( other->type() )
546  {
547  case MsgPack::INT64 :
548  {
549  return int64_value() < other->int64_value();
550  } break;
551  case MsgPack::UINT64 :
552  {
553  return less_int64_uint64( int64_value(), other->uint64_value() );
554  } break;
555  default :
556  {
558  }
559  }
560  }
561 public:
562  explicit MsgPackInt64(int64_t value) : NumberValue(value) {}
563 };
564 
565 class MsgPackUint8 final : public NumberValue<MsgPack::UINT8, uint8_t> {
566 public:
567  explicit MsgPackUint8(uint8_t value) : NumberValue(value) {}
568 };
569 
570 class MsgPackUint16 final : public NumberValue<MsgPack::UINT16, uint16_t> {
571 public:
572  explicit MsgPackUint16(uint16_t value) : NumberValue(value) {}
573 };
574 
575 class MsgPackUint32 final : public NumberValue<MsgPack::UINT32, uint32_t> {
576 public:
577  explicit MsgPackUint32(uint32_t value) : NumberValue(value) {}
578 };
579 
580 class MsgPackUint64 final : public NumberValue<MsgPack::UINT64, uint64_t> {
581  bool equals(const MsgPackValue * other) const override
582  {
583  switch( other->type() )
584  {
585  case MsgPack::INT64 :
586  {
587  return equal_uint64_int64( uint64_value(), other->int64_value() );
588  } break;
589  case MsgPack::UINT64 :
590  {
591  return uint64_value() == other->uint64_value();
592  } break;
593  default :
594  {
596  }
597  }
598  }
599  bool less(const MsgPackValue * other) const override
600  {
601  switch( other->type() )
602  {
603  case MsgPack::INT64 :
604  {
605  return less_uint64_int64( uint64_value(), other->uint64_value() );
606  } break;
607  case MsgPack::UINT64 :
608  {
609  return uint64_value() < other->uint64_value();
610  } break;
611  default :
612  {
614  }
615  }
616  }
617 public:
618  explicit MsgPackUint64(uint64_t value) : NumberValue(value) {}
619 };
620 
621 class MsgPackBoolean final : public Value<MsgPack::BOOL, bool> {
622  bool bool_value() const override { return m_value; }
623 public:
624  explicit MsgPackBoolean(bool value) : Value(value) {}
625 };
626 
627 class MsgPackString final : public Value<MsgPack::STRING, string> {
628  const string &string_value() const override { return m_value; }
629 public:
630  explicit MsgPackString(const string &value) : Value(value) {}
631  explicit MsgPackString(string &&value) : Value(move(value)) {}
632 };
633 
634 class MsgPackArray final : public Value<MsgPack::ARRAY, MsgPack::array> {
635  const MsgPack::array &array_items() const override { return m_value; }
636  const MsgPack & operator[](size_t i) const override;
637 public:
638  explicit MsgPackArray(const MsgPack::array &value) : Value(value) {}
639  explicit MsgPackArray(MsgPack::array &&value) : Value(move(value)) {}
640 };
641 
642 class MsgPackBinary final : public Value<MsgPack::BINARY, MsgPack::binary> {
643  const MsgPack::binary &binary_items() const override { return m_value; }
644 public:
645  explicit MsgPackBinary(const MsgPack::binary &value) : Value(value) {}
646  explicit MsgPackBinary(MsgPack::binary &&value) : Value(move(value)) {}
647 };
648 
649 class MsgPackObject final : public Value<MsgPack::OBJECT, MsgPack::object> {
650  const MsgPack::object &object_items() const override { return m_value; }
651  const MsgPack & operator[](const string &key) const override;
652 public:
653  explicit MsgPackObject(const MsgPack::object &value) : Value(value) {}
654  explicit MsgPackObject(MsgPack::object &&value) : Value(move(value)) {}
655 };
656 
657 class MsgPackExtension final : public Value<MsgPack::EXTENSION, MsgPack::extension> {
658  const MsgPack::extension &extension_items() const override { return m_value; }
659 public:
660  explicit MsgPackExtension(const MsgPack::extension &value) : Value(value) {}
661  explicit MsgPackExtension(MsgPack::extension &&value) : Value(move(value)) {}
662 };
663 
664 class MsgPackNull final : public Value<MsgPack::NUL, NullStruct> {
665 public:
666  MsgPackNull() : Value({}) {}
667 };
668 
669 /* * * * * * * * * * * * * * * * * * * *
670  * Static globals - static-init-safe
671  */
672 struct Statics {
673  const std::shared_ptr<MsgPackValue> null = make_shared<MsgPackNull>();
674  const std::shared_ptr<MsgPackValue> t = make_shared<MsgPackBoolean>(true);
675  const std::shared_ptr<MsgPackValue> f = make_shared<MsgPackBoolean>(false);
676  const string empty_string;
677  const vector<MsgPack> empty_vector;
678  const map<MsgPack, MsgPack> empty_map;
681  Statics() {}
682 };
683 
684 static const Statics & statics() {
685  static const Statics s {};
686  return s;
687 }
688 
689 static const MsgPack & static_null() {
690  // This has to be separate, not in Statics, because MsgPack() accesses statics().null.
691  static const MsgPack msgpack_null;
692  return msgpack_null;
693 }
694 
695 /* * * * * * * * * * * * * * * * * * * *
696  * Constructors
697  */
698 
699 MsgPack::MsgPack() noexcept : m_ptr(statics().null) {}
700 MsgPack::MsgPack(std::nullptr_t) noexcept : m_ptr(statics().null) {}
701 MsgPack::MsgPack(float value) : m_ptr(make_shared<MsgPackFloat>(value)) {}
702 MsgPack::MsgPack(double value) : m_ptr(make_shared<MsgPackDouble>(value)) {}
703 MsgPack::MsgPack(int8_t value) : m_ptr(make_shared<MsgPackInt8>(value)) {}
704 MsgPack::MsgPack(int16_t value) : m_ptr(make_shared<MsgPackInt16>(value)) {}
705 MsgPack::MsgPack(int32_t value) : m_ptr(make_shared<MsgPackInt32>(value)) {}
706 MsgPack::MsgPack(int64_t value) : m_ptr(make_shared<MsgPackInt64>(value)) {}
707 MsgPack::MsgPack(uint8_t value) : m_ptr(make_shared<MsgPackUint8>(value)) {}
708 MsgPack::MsgPack(uint16_t value) : m_ptr(make_shared<MsgPackUint16>(value)) {}
709 MsgPack::MsgPack(uint32_t value) : m_ptr(make_shared<MsgPackUint32>(value)) {}
710 MsgPack::MsgPack(uint64_t value) : m_ptr(make_shared<MsgPackUint64>(value)) {}
711 MsgPack::MsgPack(bool value) : m_ptr(value ? statics().t : statics().f) {}
712 MsgPack::MsgPack(const string &value) : m_ptr(make_shared<MsgPackString>(value)) {}
713 MsgPack::MsgPack(string &&value) : m_ptr(make_shared<MsgPackString>(move(value))) {}
714 MsgPack::MsgPack(const char * value) : m_ptr(make_shared<MsgPackString>(value)) {}
715 MsgPack::MsgPack(const MsgPack::array &values) : m_ptr(make_shared<MsgPackArray>(values)) {}
716 MsgPack::MsgPack(MsgPack::array &&values) : m_ptr(make_shared<MsgPackArray>(move(values))) {}
717 MsgPack::MsgPack(const MsgPack::object &values) : m_ptr(make_shared<MsgPackObject>(values)) {}
718 MsgPack::MsgPack(MsgPack::object &&values) : m_ptr(make_shared<MsgPackObject>(move(values))) {}
719 MsgPack::MsgPack(const MsgPack::binary &values) : m_ptr(make_shared<MsgPackBinary>(values)) {}
720 MsgPack::MsgPack(MsgPack::binary &&values) : m_ptr(make_shared<MsgPackBinary>(move(values))) {}
721 MsgPack::MsgPack(const MsgPack::extension &values) : m_ptr(make_shared<MsgPackExtension>(values)) {}
722 MsgPack::MsgPack(MsgPack::extension &&values) : m_ptr(make_shared<MsgPackExtension>(move(values))) {}
723 
724 /* * * * * * * * * * * * * * * * * * * *
725  * Accessors
726  */
727 
728 MsgPack::Type MsgPack::type() const { return m_ptr->type(); }
729 double MsgPack::number_value() const { return m_ptr->float64_value(); }
730 float MsgPack::float32_value() const { return m_ptr->float32_value(); }
731 double MsgPack::float64_value() const { return m_ptr->float64_value(); }
732 int32_t MsgPack::int_value() const { return m_ptr->int32_value(); }
733 int8_t MsgPack::int8_value() const { return m_ptr->int8_value(); }
734 int16_t MsgPack::int16_value() const { return m_ptr->int16_value(); }
735 int32_t MsgPack::int32_value() const { return m_ptr->int32_value(); }
736 int64_t MsgPack::int64_value() const { return m_ptr->int64_value(); }
737 uint8_t MsgPack::uint8_value() const { return m_ptr->uint8_value(); }
738 uint16_t MsgPack::uint16_value() const { return m_ptr->uint16_value(); }
739 uint32_t MsgPack::uint32_value() const { return m_ptr->uint32_value(); }
740 uint64_t MsgPack::uint64_value() const { return m_ptr->uint64_value(); }
741 bool MsgPack::bool_value() const { return m_ptr->bool_value(); }
742 const string & MsgPack::string_value() const { return m_ptr->string_value(); }
743 const vector<MsgPack>& MsgPack::array_items() const { return m_ptr->array_items(); }
744 const MsgPack::binary& MsgPack::binary_items() const { return m_ptr->binary_items(); }
745 const MsgPack::extension& MsgPack::extension_items() const { return m_ptr->extension_items(); }
746 const map<MsgPack, MsgPack> & MsgPack::object_items() const { return m_ptr->object_items(); }
747 const MsgPack & MsgPack::operator[] (size_t i) const { return (*m_ptr)[i]; }
748 const MsgPack & MsgPack::operator[] (const string &key) const { return (*m_ptr)[key]; }
749 
750 double MsgPackValue::number_value() const { return 0.0; }
751 float MsgPackValue::float32_value() const { return 0.0f; }
752 double MsgPackValue::float64_value() const { return 0.0; }
753 int32_t MsgPackValue::int_value() const { return 0; }
754 int8_t MsgPackValue::int8_value() const { return 0; }
755 int16_t MsgPackValue::int16_value() const { return 0; }
756 int32_t MsgPackValue::int32_value() const { return 0; }
757 int64_t MsgPackValue::int64_value() const { return 0; }
758 uint8_t MsgPackValue::uint8_value() const { return 0; }
759 uint16_t MsgPackValue::uint16_value() const { return 0; }
760 uint32_t MsgPackValue::uint32_value() const { return 0; }
761 uint64_t MsgPackValue::uint64_value() const { return 0; }
762 bool MsgPackValue::bool_value() const { return false; }
763 const string & MsgPackValue::string_value() const { return statics().empty_string; }
764 const vector<MsgPack> & MsgPackValue::array_items() const { return statics().empty_vector; }
765 const map<MsgPack, MsgPack> & MsgPackValue::object_items() const { return statics().empty_map; }
768 const MsgPack & MsgPackValue::operator[] (size_t) const { return static_null(); }
769 const MsgPack & MsgPackValue::operator[] (const string &) const { return static_null(); }
770 
771 const MsgPack & MsgPackObject::operator[] (const string &key) const {
772  auto iter = m_value.find(key);
773  return (iter == m_value.end()) ? static_null() : iter->second;
774 }
775 const MsgPack & MsgPackArray::operator[] (size_t i) const {
776  if (i >= m_value.size()) return static_null();
777  else return m_value[i];
778 }
779 
780 /* * * * * * * * * * * * * * * * * * * *
781  * Comparison
782  */
783 
784 bool MsgPack::operator== (const MsgPack &other) const {
785  return m_ptr->equals(other.m_ptr.get());
786 }
787 
788 bool MsgPack::operator< (const MsgPack &other) const {
789  return m_ptr->less(other.m_ptr.get());
790 }
791 
792 namespace {
793 /* MsgPackParser
794  *
795  * Object that tracks all state of an in-progress parse.
796  */
797 namespace MsgPackParser {
798  MsgPack parse_msgpack(std::istream& is, int depth);
799 
800  template< typename T >
801  void read_bytes(std::istream& is, T& bytes)
802  {
803  static_assert(std::is_fundamental<T>::value,
804  "byte read not guaranteed for non-primitive types");
805  int n = sizeof(T);
806 
807  int const offsets[] = {(n-1), 0};
808  int const directions[] = {-1, 1};
809 
810  uint8_t* dst_ptr = reinterpret_cast<uint8_t*>(&bytes) + offsets[static_cast<int>(is_big_endian)];
811  int const dir = directions[static_cast<int>(is_big_endian)];
812  for(int i = 0; i < n; ++i)
813  {
814  *dst_ptr = is.get();
815  dst_ptr += dir;
816  }
817 
818  // NB: if the read fails it's prefered to return 0 rather than
819  // corrupted value, for example in the case of reading data size.
820  if (is.fail() || is.eof()) {
821  bytes = 0;
822  }
823  }
824 
825  /* fail(msg, err_ret = MsgPack())
826  *
827  * Mark this parse as m_failed.
828  */
829  MsgPack fail(std::istream& is) {
830  is.setstate(std::ios::failbit);
831  return MsgPack();
832  }
833 
834  MsgPack parse_invalid(std::istream& is, uint8_t, int) {
835  return fail(is);
836  }
837 
838  MsgPack parse_nil(std::istream&, uint8_t, int) {
839  return MsgPack();
840  }
841 
842  MsgPack parse_bool(std::istream&, uint8_t first_byte, int) {
843  return MsgPack(first_byte == 0xc3);
844  }
845 
846  template< typename T >
847  MsgPack parse_arith(std::istream& is, uint8_t, int) {
848  T tmp;
849  read_bytes(is, tmp);
850  return MsgPack(tmp);
851  }
852 
853  inline std::string parse_string_impl(std::istream& is, uint32_t bytes) {
854  std::string ret;
855  ret.resize(bytes);
856  is.read(&ret[0], bytes);
857  return ret;
858  }
859 
860  template< typename T >
861  MsgPack parse_string(std::istream& is, uint8_t, int) {
862  T bytes;
863  read_bytes(is, bytes);
864  return MsgPack(parse_string_impl(is, static_cast<uint32_t>(bytes)));
865  }
866 
867  MsgPack::array parse_array_impl(std::istream& is, uint32_t bytes, int depth) {
868  MsgPack::array res;
869  res.reserve(bytes);
870 
871  for(uint32_t i = 0; i < bytes; ++i) {
872  res.push_back(parse_msgpack(is, depth));
873  }
874  return res;
875  }
876 
877  template< typename T >
878  MsgPack parse_array(std::istream& is, uint8_t, int depth) {
879  T bytes;
880  read_bytes(is, bytes);
881  return MsgPack(parse_array_impl(is, static_cast<uint32_t>(bytes), depth));
882  }
883 
884  MsgPack::object parse_object_impl(std::istream& is, uint32_t bytes, int depth) {
885  MsgPack::object res;
886 
887  for(uint32_t i = 0; i < bytes; ++i) {
888  MsgPack key = parse_msgpack(is, depth);
889  MsgPack value = parse_msgpack(is, depth);
890  res.insert(std::make_pair(std::move(key), std::move(value)));
891  }
892  return res;
893  }
894 
895  template< typename T >
896  MsgPack parse_object(std::istream& is, uint8_t, int depth) {
897  T bytes;
898  read_bytes(is, bytes);
899  return MsgPack(parse_object_impl(is, static_cast<uint32_t>(bytes), depth));
900  }
901 
902  MsgPack::binary parse_binary_impl(std::istream& is, uint32_t bytes) {
903  MsgPack::binary ret;
904  ret.resize(bytes);
905  is.read(reinterpret_cast<char*>(ret.data()), bytes);
906  return ret;
907  }
908 
909  template< typename T >
910  MsgPack parse_binary(std::istream& is, uint8_t, int) {
911  T bytes;
912  read_bytes(is, bytes);
913  return MsgPack(parse_binary_impl(is, static_cast<uint32_t>(bytes)));
914  }
915 
916  template< typename T >
917  MsgPack parse_extension(std::istream& is, uint8_t, int) {
918  T bytes;
919  read_bytes(is, bytes);
920  uint8_t type;
921  read_bytes(is, type);
922  const MsgPack::binary data = parse_binary_impl(is, static_cast<uint32_t>(bytes));
923  return MsgPack(std::make_tuple(type, std::move(data)));
924  }
925 
926  MsgPack parse_pos_fixint(std::istream&, uint8_t first_byte, int) {
927  return MsgPack( first_byte );
928  }
929 
930  MsgPack parse_fixobject(std::istream& is, uint8_t first_byte, int depth) {
931  uint32_t const bytes = first_byte & 0x0f;
932  return MsgPack(parse_object_impl(is, bytes, depth));
933  }
934 
935  MsgPack parse_fixarray(std::istream& is, uint8_t first_byte, int depth) {
936  uint32_t const bytes = first_byte & 0x0f;
937  return MsgPack(parse_array_impl(is, bytes, depth));
938  }
939 
940  MsgPack parse_fixstring(std::istream& is, uint8_t first_byte, int) {
941  uint32_t const bytes = first_byte & 0x1f;
942  return MsgPack(parse_string_impl(is, bytes));
943  }
944 
945  MsgPack parse_neg_fixint(std::istream&, uint8_t first_byte, int) {
946  return MsgPack(*reinterpret_cast<int8_t*>(&first_byte));
947  }
948 
949  MsgPack parse_fixext(std::istream& is, uint8_t first_byte, int) {
950  uint8_t type;
951  read_bytes(is, type);
952  uint32_t const BYTES = 1 << (first_byte - 0xd4u);
953  const MsgPack::binary data = parse_binary_impl(is, BYTES);
954  return MsgPack(std::make_tuple(type, std::move(data)));
955  }
956 
957  /* parse_msgpack()
958  *
959  * Parse a JSON object.
960  */
961  MsgPack parse_msgpack(std::istream& is, int depth) {
962  static const std::array< MsgPack(*)(std::istream&, uint8_t, int), 256 > parsers = [](){
963  using parser_template_element_type = std::tuple<uint8_t, MsgPack(*)(std::istream&,uint8_t,int)>;
964  std::array< parser_template_element_type, 36 > const parser_template{{
965  parser_template_element_type{ 0x7fu, &MsgPackParser::parse_pos_fixint},
966  parser_template_element_type{ 0x8fu, &MsgPackParser::parse_fixobject},
967  parser_template_element_type{ 0x9fu, &MsgPackParser::parse_fixarray},
968  parser_template_element_type{ 0xbfu, &MsgPackParser::parse_fixstring},
969  parser_template_element_type{ 0xc0u, &MsgPackParser::parse_nil},
970  parser_template_element_type{ 0xc1u, &MsgPackParser::parse_invalid},
971  parser_template_element_type{ 0xc3u, &MsgPackParser::parse_bool},
972  parser_template_element_type{ 0xc4u, &MsgPackParser::parse_binary<uint8_t>},
973  parser_template_element_type{ 0xc5u, &MsgPackParser::parse_binary<uint16_t>},
974  parser_template_element_type{ 0xc6u, &MsgPackParser::parse_binary<uint32_t>},
975  parser_template_element_type{ 0xc7u, &MsgPackParser::parse_extension<uint8_t>},
976  parser_template_element_type{ 0xc8u, &MsgPackParser::parse_extension<uint16_t>},
977  parser_template_element_type{ 0xc9u, &MsgPackParser::parse_extension<uint32_t>},
978  parser_template_element_type{ 0xcau, &MsgPackParser::parse_arith<float>},
979  parser_template_element_type{ 0xcbu, &MsgPackParser::parse_arith<double>},
980  parser_template_element_type{ 0xccu, &MsgPackParser::parse_arith<uint8_t>},
981  parser_template_element_type{ 0xcdu, &MsgPackParser::parse_arith<uint16_t>},
982  parser_template_element_type{ 0xceu, &MsgPackParser::parse_arith<uint32_t>},
983  parser_template_element_type{ 0xcfu, &MsgPackParser::parse_arith<uint64_t>},
984  parser_template_element_type{ 0xd0u, &MsgPackParser::parse_arith<int8_t>},
985  parser_template_element_type{ 0xd1u, &MsgPackParser::parse_arith<int16_t>},
986  parser_template_element_type{ 0xd2u, &MsgPackParser::parse_arith<int32_t>},
987  parser_template_element_type{ 0xd3u, &MsgPackParser::parse_arith<int64_t>},
988  parser_template_element_type{ 0xd8u, &MsgPackParser::parse_fixext},
989  parser_template_element_type{ 0xd9u, &MsgPackParser::parse_string<uint8_t>},
990  parser_template_element_type{ 0xdau, &MsgPackParser::parse_string<uint16_t>},
991  parser_template_element_type{ 0xdbu, &MsgPackParser::parse_string<uint32_t>},
992  parser_template_element_type{ 0xdcu, &MsgPackParser::parse_array<uint16_t>},
993  parser_template_element_type{ 0xddu, &MsgPackParser::parse_array<uint32_t>},
994  parser_template_element_type{ 0xdeu, &MsgPackParser::parse_object<uint16_t>},
995  parser_template_element_type{ 0xdfu, &MsgPackParser::parse_object<uint32_t>},
996  parser_template_element_type{ 0xffu, &MsgPackParser::parse_neg_fixint}
997  }};
998 
999  std::array< MsgPack(*)(std::istream&, uint8_t, int), 256 > parsers;
1000  int i = 0;
1001  std::for_each(std::begin(parser_template),
1002  std::end(parser_template),
1003  [&parsers,&i]( parser_template_element_type const& element ) {
1004  int upto = std::get<0>( element );
1005  auto parser = std::get<1>( element );
1006  while(i <= upto)
1007  {
1008  parsers[i] = parser;
1009  ++i;
1010  }
1011  });
1012  return parsers;
1013  }();
1014 
1015  if (max_depth < depth) {
1016  // "exceeded maximum nesting depth."
1017  return fail(is);
1018  }
1019 
1020  uint8_t const first_byte = is.get();
1021  // check for fail/eof after get() as eof only set after read past the end
1022  if (is.fail() || is.eof()) {
1023  return fail(is);
1024  }
1025 
1026  MsgPack ret = (*parsers[first_byte])(is, first_byte, depth + 1);
1027 
1028  if (is.fail() || is.eof()) {
1029  return fail(is);
1030  }
1031  return ret;
1032  }
1033 };
1034 
1035 }//namespace {
1036 
1037 std::istream& operator>>(std::istream& is, MsgPack& msgpack) {
1038  msgpack = MsgPackParser::parse_msgpack(is, 0);
1039  return is;
1040 }
1041 
1042 MsgPack MsgPack::parse(std::istream& is) {
1043  return MsgPackParser::parse_msgpack(is, 0);
1044 }
1045 
1046 MsgPack MsgPack::parse(std::istream& is, std::string &err) {
1047  MsgPack ret = MsgPack::parse(is);
1048  if (is.eof()) {
1049  err = "end of buffer.";
1050  } else if (is.fail()) {
1051  err = "format error.";
1052  }
1053  return ret;
1054 }
1055 
1056 MsgPack MsgPack::parse(const std::string &in, string &err) {
1057  std::stringstream ss(in);
1058  return MsgPack::parse(ss, err);
1059 }
1060 
1061 // Documented in msgpack.hpp
1062 vector<MsgPack> MsgPack::parse_multi(const string &in,
1063  std::string::size_type &parser_stop_pos,
1064  string &err) {
1065  std::stringstream ss(in);
1066 
1067  vector<MsgPack> msgpack_vec;
1068  while (static_cast<size_t>(ss.tellg()) != in.size() && !ss.eof() && !ss.fail()) {
1069  auto next = MsgPack::parse(ss, err);
1070  if (!ss.fail()) {
1071  msgpack_vec.emplace_back(std::move(next));
1072  parser_stop_pos = ss.tellg();
1073  }
1074  }
1075 
1076  return msgpack_vec;
1077 }
1078 
1079 /* * * * * * * * * * * * * * * * * * * *
1080  * Shape-checking
1081  */
1082 
1083 bool MsgPack::has_shape(const shape & types, string & err) const {
1084  if (!is_object()) {
1085  err = "expected MessagePack object";
1086  return false;
1087  }
1088 
1089  for (auto & item : types) {
1090  if ((*this)[item.first].type() != item.second) {
1091  err = "bad type for " + item.first;
1092  return false;
1093  }
1094  }
1095 
1096  return true;
1097 }
1098 
1099 } // namespace msgpack11
msgpack11::MsgPack::int64_value
int64_t int64_value() const
Definition: msgpack11.cpp:736
msgpack11::MsgPack::shape
std::initializer_list< std::pair< std::string, Type > > shape
Definition: msgpack11.hpp:234
msgpack11::MsgPackExtension::MsgPackExtension
MsgPackExtension(MsgPack::extension &&value)
Definition: msgpack11.cpp:661
msgpack11::MsgPack::string_value
const std::string & string_value() const
Definition: msgpack11.cpp:742
msgpack11
Definition: msgpack11.cpp:16
msgpack11::operator>>
std::istream & operator>>(std::istream &is, MsgPack &msgpack)
Definition: msgpack11.cpp:1037
msgpack11::MsgPackBoolean::MsgPackBoolean
MsgPackBoolean(bool value)
Definition: msgpack11.cpp:624
msgpack11::Statics::t
const std::shared_ptr< MsgPackValue > t
Definition: msgpack11.cpp:674
msgpack11::MsgPack::UINT16
@ UINT16
Definition: msgpack11.hpp:44
msgpack11::NumberValue::int32_value
int32_t int32_value() const override
Definition: msgpack11.cpp:491
msgpack11::MsgPackObject::MsgPackObject
MsgPackObject(const MsgPack::object &value)
Definition: msgpack11.cpp:653
msgpack11::Statics::f
const std::shared_ptr< MsgPackValue > f
Definition: msgpack11.cpp:675
msgpack11::max_depth
static const int max_depth
Definition: msgpack11.cpp:18
msgpack11::NumberValue::uint16_value
uint16_t uint16_value() const override
Definition: msgpack11.cpp:494
msgpack11::MsgPackValue
Definition: msgpack11.cpp:40
msgpack11::MsgPack::uint16_value
uint16_t uint16_value() const
Definition: msgpack11.cpp:738
msgpack11::MsgPackArray
Definition: msgpack11.cpp:634
bytes
uint8_t bytes[2]
Definition: msgpack11.cpp:76
msgpack11::MsgPack::Type
Type
Definition: msgpack11.hpp:33
msgpack11::MsgPackInt64::equals
bool equals(const MsgPackValue *other) const override
Definition: msgpack11.cpp:525
msgpack11::MsgPackString::MsgPackString
MsgPackString(const string &value)
Definition: msgpack11.cpp:630
msgpack11::statics
static const Statics & statics()
Definition: msgpack11.cpp:684
msgpack11::MsgPackString::string_value
const string & string_value() const override
Definition: msgpack11.cpp:628
msgpack11::MsgPackValue::int16_value
virtual int16_t int16_value() const
Definition: msgpack11.cpp:755
msgpack11::MsgPack::int8_value
int8_t int8_value() const
Definition: msgpack11.cpp:733
msgpack11::Value
Definition: msgpack11.cpp:383
msgpack11::NumberValue::less
bool less(const MsgPackValue *other) const override
Definition: msgpack11.cpp:462
msgpack11::MsgPackBinary::MsgPackBinary
MsgPackBinary(MsgPack::binary &&value)
Definition: msgpack11.cpp:646
msgpack11::NumberValue::int_value
int32_t int_value() const override
Definition: msgpack11.cpp:488
msgpack11::MsgPackArray::array_items
const MsgPack::array & array_items() const override
Definition: msgpack11.cpp:635
msgpack11::MsgPack::UINT64
@ UINT64
Definition: msgpack11.hpp:46
msgpack11::MsgPackExtension::MsgPackExtension
MsgPackExtension(const MsgPack::extension &value)
Definition: msgpack11.cpp:660
s
XmlRpcServer s
msgpack11::MsgPack::operator==
bool operator==(const MsgPack &rhs) const
Definition: msgpack11.cpp:784
msgpack11::MsgPackInt32::MsgPackInt32
MsgPackInt32(int32_t value)
Definition: msgpack11.cpp:521
msgpack11::MsgPackInt8
Definition: msgpack11.cpp:509
msgpack11::MsgPackObject
Definition: msgpack11.cpp:649
msgpack11::MsgPackFloat::MsgPackFloat
MsgPackFloat(float value)
Definition: msgpack11.cpp:501
test_server.type
type
Definition: test_server.py:210
msgpack11::MsgPack::INT32
@ INT32
Definition: msgpack11.hpp:41
msgpack11::MsgPack::extension
std::tuple< int8_t, binary > extension
Definition: msgpack11.hpp:61
msgpack11::MsgPackValue::less
virtual bool less(const MsgPackValue *other) const =0
test_server.default
default
Definition: test_server.py:210
msgpack11::NumberValue
Definition: msgpack11.cpp:432
msgpack11::MsgPackDouble
Definition: msgpack11.cpp:504
msgpack11::MsgPack::uint32_value
uint32_t uint32_value() const
Definition: msgpack11.cpp:739
msgpack11::MsgPack::float32_value
float float32_value() const
Definition: msgpack11.cpp:730
msgpack11::MsgPackValue::array_items
virtual const MsgPack::array & array_items() const
Definition: msgpack11.cpp:764
msgpack11::MsgPackUint8::MsgPackUint8
MsgPackUint8(uint8_t value)
Definition: msgpack11.cpp:567
msgpack11::MsgPack::int16_value
int16_t int16_value() const
Definition: msgpack11.cpp:734
msgpack11::operator<<
std::ostream & operator<<(std::ostream &os, const MsgPack &msgpack)
Definition: msgpack11.cpp:371
msgpack11::MsgPack::number_value
double number_value() const
Definition: msgpack11.cpp:729
msgpack11::MsgPackUint32
Definition: msgpack11.cpp:575
msgpack11::MsgPackBinary
Definition: msgpack11.cpp:642
msgpack11::MsgPack::int_value
int32_t int_value() const
Definition: msgpack11.cpp:732
msgpack11::MsgPackBinary::MsgPackBinary
MsgPackBinary(const MsgPack::binary &value)
Definition: msgpack11.cpp:645
msgpack11::MsgPackExtension::extension_items
const MsgPack::extension & extension_items() const override
Definition: msgpack11.cpp:658
msgpack11::MsgPackValue::bool_value
virtual bool bool_value() const
Definition: msgpack11.cpp:762
msgpack11::MsgPack::parse
static MsgPack parse(const std::string &in, std::string &err)
msgpack11::MsgPackFloat
Definition: msgpack11.cpp:499
msgpack11::MsgPack::float64_value
double float64_value() const
Definition: msgpack11.cpp:731
msgpack11::MsgPackUint16
Definition: msgpack11.cpp:570
msgpack11::MsgPackValue::int64_value
virtual int64_t int64_value() const
Definition: msgpack11.cpp:757
msgpack11::MsgPackBoolean::bool_value
bool bool_value() const override
Definition: msgpack11.cpp:622
msgpack11::MsgPack::UINT8
@ UINT8
Definition: msgpack11.hpp:43
msgpack11::MsgPackUint64::MsgPackUint64
MsgPackUint64(uint64_t value)
Definition: msgpack11.cpp:618
msgpack11::NumberValue::uint8_value
uint8_t uint8_value() const override
Definition: msgpack11.cpp:493
msgpack11::MsgPackValue::int8_value
virtual int8_t int8_value() const
Definition: msgpack11.cpp:754
msgpack11::Statics
Definition: msgpack11.cpp:672
msgpack11::MsgPackValue::operator[]
virtual const MsgPack & operator[](size_t i) const
Definition: msgpack11.cpp:768
msgpack11::MsgPackValue::int_value
virtual int32_t int_value() const
Definition: msgpack11.cpp:753
msgpack11::MsgPack::UINT32
@ UINT32
Definition: msgpack11.hpp:45
msgpack11::MsgPackArray::MsgPackArray
MsgPackArray(const MsgPack::array &value)
Definition: msgpack11.cpp:638
msgpack11::MsgPackValue::uint8_value
virtual uint8_t uint8_value() const
Definition: msgpack11.cpp:758
msgpack11::NullStruct::operator<
bool operator<(NullStruct) const
Definition: msgpack11.cpp:33
data
data
msgpack11::Value::less
bool less(const MsgPackValue *other) const override
Definition: msgpack11.cpp:400
f
f
msgpack11::NumberValue::NumberValue
NumberValue(T &&value)
Definition: msgpack11.cpp:437
msgpack11::MsgPackDouble::MsgPackDouble
MsgPackDouble(double value)
Definition: msgpack11.cpp:506
msgpack11::MsgPack::binary
std::vector< uint8_t > binary
Definition: msgpack11.hpp:60
msgpack11::MsgPack::uint8_value
uint8_t uint8_value() const
Definition: msgpack11.cpp:737
msgpack11::MsgPackInt64
Definition: msgpack11.cpp:524
dummy
uint16_t dummy
Definition: msgpack11.cpp:75
msgpack11::MsgPackInt64::less
bool less(const MsgPackValue *other) const override
Definition: msgpack11.cpp:543
msgpack11::NullStruct
Definition: msgpack11.cpp:31
msgpack11::static_null
static const MsgPack & static_null()
Definition: msgpack11.cpp:689
msgpack11::NumberValue::int64_value
int64_t int64_value() const override
Definition: msgpack11.cpp:492
msgpack11::MsgPackValue::equals
virtual bool equals(const MsgPackValue *other) const =0
msgpack11::MsgPack::is_object
bool is_object() const
Definition: msgpack11.hpp:137
msgpack11::less_int64_uint64
bool less_int64_uint64(int64_t int64_value, uint64_t uint64_value)
Definition: msgpack11.cpp:424
msgpack11::MsgPackValue::dump
virtual void dump(std::ostream &os) const =0
msgpack11::Value::Value
Value(const T &value)
Definition: msgpack11.cpp:387
msgpack11::MsgPackInt8::MsgPackInt8
MsgPackInt8(int8_t value)
Definition: msgpack11.cpp:511
msgpack11::MsgPack::bool_value
bool bool_value() const
Definition: msgpack11.cpp:741
msgpack11::MsgPackValue::float32_value
virtual float float32_value() const
Definition: msgpack11.cpp:751
msgpack11.hpp
msgpack11::MsgPackUint64
Definition: msgpack11.cpp:580
msgpack11::NumberValue::uint32_value
uint32_t uint32_value() const override
Definition: msgpack11.cpp:495
msgpack11::MsgPackString
Definition: msgpack11.cpp:627
msgpack11::MsgPackInt64::MsgPackInt64
MsgPackInt64(int64_t value)
Definition: msgpack11.cpp:562
msgpack11::Statics::empty_vector
const vector< MsgPack > empty_vector
Definition: msgpack11.cpp:677
imu_delay_tester.parser
parser
Definition: imu_delay_tester.py:116
msgpack11::MsgPack::INT8
@ INT8
Definition: msgpack11.hpp:39
msgpack11::NumberValue::float64_value
double float64_value() const override
Definition: msgpack11.cpp:487
msgpack11::MsgPackValue::binary_items
virtual const MsgPack::binary & binary_items() const
Definition: msgpack11.cpp:766
msgpack11::MsgPackValue::uint16_value
virtual uint16_t uint16_value() const
Definition: msgpack11.cpp:759
msgpack11::MsgPack::parse_multi
static std::vector< MsgPack > parse_multi(const std::string &in, std::string::size_type &parser_stop_pos, std::string &err)
msgpack11::MsgPackInt32
Definition: msgpack11.cpp:519
msgpack11::Statics::Statics
Statics()
Definition: msgpack11.cpp:681
msgpack11::MsgPack::extension_items
const extension & extension_items() const
Definition: msgpack11.cpp:745
msgpack11::MsgPackObject::MsgPackObject
MsgPackObject(MsgPack::object &&value)
Definition: msgpack11.cpp:654
msgpack11::MsgPackNull::MsgPackNull
MsgPackNull()
Definition: msgpack11.cpp:666
msgpack11::MsgPack::array
std::vector< MsgPack > array
Definition: msgpack11.hpp:56
msgpack11::MsgPackInt16
Definition: msgpack11.cpp:514
msgpack11::MsgPack::MsgPack
MsgPack() noexcept
Definition: msgpack11.cpp:699
msgpack11::MsgPackExtension
Definition: msgpack11.cpp:657
msgpack11::NumberValue::equals
bool equals(const MsgPackValue *other) const override
Definition: msgpack11.cpp:439
msgpack11::MsgPack::type
Type type() const
Definition: msgpack11.cpp:728
msgpack11::MsgPack::INT64
@ INT64
Definition: msgpack11.hpp:42
msgpack11::MsgPack::FLOAT32
@ FLOAT32
Definition: msgpack11.hpp:37
msgpack11::MsgPackUint64::equals
bool equals(const MsgPackValue *other) const override
Definition: msgpack11.cpp:581
msgpack11::MsgPackString::MsgPackString
MsgPackString(string &&value)
Definition: msgpack11.cpp:631
msgpack11::MsgPackBinary::binary_items
const MsgPack::binary & binary_items() const override
Definition: msgpack11.cpp:643
msgpack11::MsgPackValue::object_items
virtual const MsgPack::object & object_items() const
Definition: msgpack11.cpp:765
msgpack11::MsgPackUint16::MsgPackUint16
MsgPackUint16(uint16_t value)
Definition: msgpack11.cpp:572
msgpack11::equal_uint64_int64
bool equal_uint64_int64(uint64_t uint64_value, int64_t int64_value)
Definition: msgpack11.cpp:410
msgpack11::NumberValue::int8_value
int8_t int8_value() const override
Definition: msgpack11.cpp:489
msgpack11::MsgPack::int32_value
int32_t int32_value() const
Definition: msgpack11.cpp:735
msgpack11::NumberValue::uint64_value
uint64_t uint64_value() const override
Definition: msgpack11.cpp:496
msgpack11::MsgPack::has_shape
bool has_shape(const shape &types, std::string &err) const
Definition: msgpack11.cpp:1083
msgpack11::MsgPack::object_items
const object & object_items() const
Definition: msgpack11.cpp:746
msgpack11::MsgPackUint32::MsgPackUint32
MsgPackUint32(uint32_t value)
Definition: msgpack11.cpp:577
msgpack11::MsgPack::INT16
@ INT16
Definition: msgpack11.hpp:40
msgpack11::MsgPack::operator<
bool operator<(const MsgPack &rhs) const
Definition: msgpack11.cpp:788
msgpack11::MsgPackValue::number_value
virtual double number_value() const
Definition: msgpack11.cpp:750
msgpack11::MsgPackValue::float64_value
virtual double float64_value() const
Definition: msgpack11.cpp:752
values
std::vector< double > values
msgpack11::MsgPack::FLOAT64
@ FLOAT64
Definition: msgpack11.hpp:38
msgpack11::Value::type
MsgPack::Type type() const override
Definition: msgpack11.cpp:391
msgpack11::MsgPackValue::string_value
virtual const std::string & string_value() const
Definition: msgpack11.cpp:763
msgpack11::NumberValue::number_value
double number_value() const override
Definition: msgpack11.cpp:485
msgpack11::Value::dump
void dump(std::ostream &os) const override
Definition: msgpack11.cpp:407
msgpack11::NumberValue::int16_value
int16_t int16_value() const override
Definition: msgpack11.cpp:490
msgpack11::MsgPackValue::int32_value
virtual int32_t int32_value() const
Definition: msgpack11.cpp:756
msgpack11::NumberValue::float32_value
float float32_value() const override
Definition: msgpack11.cpp:486
msgpack11::MsgPack::m_ptr
std::shared_ptr< MsgPackValue > m_ptr
Definition: msgpack11.hpp:238
msgpack11::Statics::empty_extension
const MsgPack::extension empty_extension
Definition: msgpack11.cpp:680
msgpack11::MsgPack::object
std::map< MsgPack, MsgPack > object
Definition: msgpack11.hpp:57
msgpack11::MsgPackArray::operator[]
const MsgPack & operator[](size_t i) const override
Definition: msgpack11.cpp:775
msgpack11::MsgPackValue::~MsgPackValue
virtual ~MsgPackValue()
Definition: msgpack11.cpp:66
msgpack11::MsgPack::binary_items
const binary & binary_items() const
Definition: msgpack11.cpp:744
msgpack11::Statics::empty_binary
const MsgPack::binary empty_binary
Definition: msgpack11.cpp:679
msgpack11::Statics::empty_string
const string empty_string
Definition: msgpack11.cpp:676
msgpack11::MsgPackUint8
Definition: msgpack11.cpp:565
msgpack11::MsgPackValue::type
virtual MsgPack::Type type() const =0
msgpack11::Value::m_value
const T m_value
Definition: msgpack11.cpp:406
msgpack11::less_uint64_int64
bool less_uint64_int64(uint64_t uint64_value, int64_t int64_value)
Definition: msgpack11.cpp:417
msgpack11::MsgPackBoolean
Definition: msgpack11.cpp:621
msgpack11::NullStruct::operator==
bool operator==(NullStruct) const
Definition: msgpack11.cpp:32
msgpack11::MsgPackUint64::less
bool less(const MsgPackValue *other) const override
Definition: msgpack11.cpp:599
msgpack11::MsgPack::operator[]
const MsgPack & operator[](size_t i) const
Definition: msgpack11.cpp:747
msgpack11::MsgPackObject::object_items
const MsgPack::object & object_items() const override
Definition: msgpack11.cpp:650
msgpack11::MsgPack::array_items
const array & array_items() const
Definition: msgpack11.cpp:743
msgpack11::MsgPack
Definition: msgpack11.hpp:29
msgpack11::MsgPackObject::operator[]
const MsgPack & operator[](const string &key) const override
Definition: msgpack11.cpp:771
msgpack11::MsgPackNull
Definition: msgpack11.cpp:664
msgpack11::MsgPack::uint64_value
uint64_t uint64_value() const
Definition: msgpack11.cpp:740
msgpack11::MsgPackInt16::MsgPackInt16
MsgPackInt16(int16_t value)
Definition: msgpack11.cpp:516
msgpack11::Statics::empty_map
const map< MsgPack, MsgPack > empty_map
Definition: msgpack11.cpp:678
t
geometry_msgs::TransformStamped t
msgpack11::MsgPackValue::uint32_value
virtual uint32_t uint32_value() const
Definition: msgpack11.cpp:760
msgpack11::MsgPackValue::extension_items
virtual const MsgPack::extension & extension_items() const
Definition: msgpack11.cpp:767
msgpack11::Value::equals
bool equals(const MsgPackValue *other) const override
Definition: msgpack11.cpp:396
msgpack11::NumberValue::NumberValue
NumberValue(const T &value)
Definition: msgpack11.cpp:436
msgpack11::MsgPackValue::uint64_value
virtual uint64_t uint64_value() const
Definition: msgpack11.cpp:761
msgpack11::Value::Value
Value(T &&value)
Definition: msgpack11.cpp:388
msgpack11::MsgPackArray::MsgPackArray
MsgPackArray(MsgPack::array &&value)
Definition: msgpack11.cpp:639


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:09