MessagePack for C++
unpack_decl.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_DECL_HPP
11 #define MSGPACK_V1_UNPACK_DECL_HPP
12 
13 #include "msgpack/versioning.hpp"
15 #include "msgpack/object.hpp"
16 #include "msgpack/zone.hpp"
17 #include "msgpack/cpp_config.hpp"
18 #include "msgpack/sysdep.hpp"
19 #include "msgpack/parse_return.hpp"
20 
21 #include <memory>
22 #include <stdexcept>
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 #ifdef _msgpack_atomic_counter_header
37 #include _msgpack_atomic_counter_header
38 #endif
39 
40 const size_t COUNTER_SIZE = sizeof(_msgpack_atomic_counter_t);
41 
42 #ifndef MSGPACK_UNPACKER_INIT_BUFFER_SIZE
43 #define MSGPACK_UNPACKER_INIT_BUFFER_SIZE (64*1024)
44 #endif
45 
46 #ifndef MSGPACK_UNPACKER_RESERVE_SIZE
47 #define MSGPACK_UNPACKER_RESERVE_SIZE (32*1024)
48 #endif
49 
50 
51 // backward compatibility
52 #ifndef MSGPACK_UNPACKER_DEFAULT_INITIAL_BUFFER_SIZE
53 #define MSGPACK_UNPACKER_DEFAULT_INITIAL_BUFFER_SIZE MSGPACK_UNPACKER_INIT_BUFFER_SIZE
54 #endif
55 
56 
57 namespace msgpack {
58 
62 
64 
74 typedef bool (*unpack_reference_func)(msgpack::type::object_type type, std::size_t size, void* user_data);
75 
76 struct unpack_error;
77 struct parse_error;
78 struct insufficient_bytes;
79 struct size_overflow;
80 struct array_size_overflow;
81 struct map_size_overflow;
82 struct str_size_overflow;
83 struct bin_size_overflow;
84 struct ext_size_overflow;
85 struct depth_size_overflow;
86 
87 class unpack_limit {
88 public:
90  std::size_t array = 0xffffffff,
91  std::size_t map = 0xffffffff,
92  std::size_t str = 0xffffffff,
93  std::size_t bin = 0xffffffff,
94  std::size_t ext = 0xffffffff,
95  std::size_t depth = 0xffffffff)
96  :array_(array),
97  map_(map),
98  str_(str),
99  bin_(bin),
100  ext_(ext),
101  depth_(depth) {}
102  std::size_t array() const { return array_; }
103  std::size_t map() const { return map_; }
104  std::size_t str() const { return str_; }
105  std::size_t bin() const { return bin_; }
106  std::size_t ext() const { return ext_; }
107  std::size_t depth() const { return depth_; }
108 
109 private:
110  std::size_t array_;
111  std::size_t map_;
112  std::size_t str_;
113  std::size_t bin_;
114  std::size_t ext_;
115  std::size_t depth_;
116 };
117 
118 namespace detail {
119 
120 class unpack_user;
121 
122 void unpack_uint8(uint8_t d, msgpack::object& o);
123 
124 void unpack_uint16(uint16_t d, msgpack::object& o);
125 
126 void unpack_uint32(uint32_t d, msgpack::object& o);
127 
128 void unpack_uint64(uint64_t d, msgpack::object& o);
129 
130 void unpack_int8(int8_t d, msgpack::object& o);
131 
132 void unpack_int16(int16_t d, msgpack::object& o);
133 
134 void unpack_int32(int32_t d, msgpack::object& o);
135 
136 void unpack_int64(int64_t d, msgpack::object& o);
137 
138 void unpack_float(float d, msgpack::object& o);
139 
140 void unpack_double(double d, msgpack::object& o);
141 
142 void unpack_nil(msgpack::object& o);
143 
145 
147 
148 struct unpack_array;
149 
151 
152 struct unpack_map;
153 
155 
156 void unpack_str(unpack_user& u, const char* p, uint32_t l, msgpack::object& o);
157 
158 void unpack_bin(unpack_user& u, const char* p, uint32_t l, msgpack::object& o);
159 
160 void unpack_ext(unpack_user& u, const char* p, std::size_t l, msgpack::object& o);
161 
162 class unpack_stack;
163 
164 void init_count(void* buffer);
165 
166 void decr_count(void* buffer);
167 
168 void incr_count(void* buffer);
169 
170 #if defined(MSGPACK_USE_CPP03)
171 
173 
174 #else // defined(MSGPACK_USE_CPP03)
175 
176 std::atomic<unsigned int> const& get_count(void* buffer);
177 
178 #endif // defined(MSGPACK_USE_CPP03)
179 
180 struct fix_tag {
181  char f1[65]; // FIXME unique size is required. or use is_same meta function.
182 };
183 
184 template <typename T>
185 struct value;
186 
187 template <typename T>
188 typename msgpack::enable_if<sizeof(T) == sizeof(fix_tag)>::type load(uint32_t& dst, const char* n);
189 
190 template <typename T>
191 typename msgpack::enable_if<sizeof(T) == 1>::type load(T& dst, const char* n);
192 
193 template <typename T>
194 typename msgpack::enable_if<sizeof(T) == 2>::type load(T& dst, const char* n);
195 
196 template <typename T>
197 typename msgpack::enable_if<sizeof(T) == 4>::type load(T& dst, const char* n);
198 
199 template <typename T>
200 typename msgpack::enable_if<sizeof(T) == 8>::type load(T& dst, const char* n);
201 
202 class context;
203 
204 } // detail
205 
206 
208 
210 class unpacker;
211 
213 
226  const char* data, std::size_t len, std::size_t& off, bool& referenced,
227  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
228 
230 
242  const char* data, std::size_t len, std::size_t& off,
243  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
244 
246 
258  const char* data, std::size_t len, bool& referenced,
259  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
260 
262 
273  const char* data, std::size_t len,
274  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
275 
276 
278 
290 void unpack(
291  object_handle& result,
292  const char* data, std::size_t len, std::size_t& off, bool& referenced,
293  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
294 
296 
307 void unpack(
308  object_handle& result,
309  const char* data, std::size_t len, std::size_t& off,
310  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
311 
313 
324 void unpack(
325  object_handle& result,
326  const char* data, std::size_t len, bool& referenced,
327  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
328 
330 
340 void unpack(
341  object_handle& result,
342  const char* data, std::size_t len,
343  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
344 
346 
360  msgpack::zone& z,
361  const char* data, std::size_t len, std::size_t& off, bool& referenced,
362  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
363 
365 
378  msgpack::zone& z,
379  const char* data, std::size_t len, std::size_t& off,
380  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
381 
383 
396  msgpack::zone& z,
397  const char* data, std::size_t len, bool& referenced,
398  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
399 
401 
413  msgpack::zone& z,
414  const char* data, std::size_t len,
415  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
416 
417 
419 
431 void unpack(
432  object_handle* result,
433  const char* data, std::size_t len, std::size_t* off = MSGPACK_NULLPTR, bool* referenced = MSGPACK_NULLPTR,
434  unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
435 
436 
437 namespace detail {
438 
440 unpack_imp(const char* data, std::size_t len, std::size_t& off,
441  msgpack::zone& result_zone, msgpack::object& result, bool& referenced,
442  unpack_reference_func f, void* user_data,
443  unpack_limit const& limit);
444 
445 } // detail
446 
447 
449 } // MSGPACK_API_VERSION_NAMESPACE(v1)
451 
452 } // namespace msgpack
453 
454 #endif // MSGPACK_V1_UNPACK_DECL_HPP
Definition: unpack.hpp:318
The class holds object and zone.
Definition: object.hpp:44
Definition: unpack_decl.hpp:87
std::size_t bin() const
Definition: unpack_decl.hpp:105
std::size_t str() const
Definition: unpack_decl.hpp:104
unpack_limit(std::size_t array=0xffffffff, std::size_t map=0xffffffff, std::size_t str=0xffffffff, std::size_t bin=0xffffffff, std::size_t ext=0xffffffff, std::size_t depth=0xffffffff)
Definition: unpack_decl.hpp:89
std::size_t map() const
Definition: unpack_decl.hpp:103
std::size_t depth() const
Definition: unpack_decl.hpp:107
std::size_t array() const
Definition: unpack_decl.hpp:102
std::size_t ext() const
Definition: unpack_decl.hpp:106
Unpacking class for a stream deserialization.
Definition: unpack.hpp:862
Definition: cpp03_zone.hpp:31
void unpack_int32(int32_t d, msgpack::object &o)
Definition: unpack.hpp:90
void unpack_ext(unpack_user &u, const char *p, std::size_t l, msgpack::object &o)
Definition: unpack.hpp:205
void unpack_float(float d, msgpack::object &o)
Definition: unpack.hpp:98
void unpack_false(msgpack::object &o)
Definition: unpack.hpp:110
void unpack_int16(int16_t d, msgpack::object &o)
Definition: unpack.hpp:86
void unpack_str(unpack_user &u, const char *p, uint32_t l, msgpack::object &o)
Definition: unpack.hpp:167
void unpack_nil(msgpack::object &o)
Definition: unpack.hpp:104
void init_count(void *buffer)
Definition: unpack.hpp:241
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:1353
void unpack_uint64(uint64_t d, msgpack::object &o)
Definition: unpack.hpp:79
std::atomic< unsigned int > const & get_count(void *buffer)
Definition: unpack.hpp:278
void unpack_array_item(msgpack::object &c, msgpack::object const &o)
Definition: unpack.hpp:129
void decr_count(void *buffer)
Definition: unpack.hpp:250
void unpack_int64(int64_t d, msgpack::object &o)
Definition: unpack.hpp:94
void unpack_uint8(uint8_t d, msgpack::object &o)
Definition: unpack.hpp:70
void unpack_bin(unpack_user &u, const char *p, uint32_t l, msgpack::object &o)
Definition: unpack.hpp:186
void unpack_int8(int8_t d, msgpack::object &o)
Definition: unpack.hpp:82
void incr_count(void *buffer)
Definition: unpack.hpp:263
void unpack_true(msgpack::object &o)
Definition: unpack.hpp:107
void unpack_map_item(msgpack::object &c, msgpack::object const &k, msgpack::object const &v)
Definition: unpack.hpp:155
void unpack_uint16(uint16_t d, msgpack::object &o)
Definition: unpack.hpp:73
void unpack_double(double d, msgpack::object &o)
Definition: unpack.hpp:101
void unpack_uint32(uint32_t d, msgpack::object &o)
Definition: unpack.hpp:76
msgpack::enable_if< sizeof(T)==sizeof(fix_tag)>::type load(uint32_t &dst, const char *n)
Definition: unpack.hpp:294
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
object_type
Definition: object_fwd_decl.hpp:27
Definition: adaptor_base.hpp:15
object_handle unpacked
Definition: unpack_decl.hpp:207
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
parse_return
Definition: parse_return.hpp:23
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:1397
Definition: unpack_exception.hpp:61
Definition: unpack_exception.hpp:88
Definition: unpack_exception.hpp:106
Definition: unpack_decl.hpp:180
char f1[65]
Definition: unpack_decl.hpp:181
Definition: unpack.hpp:285
Definition: unpack_exception.hpp:97
Definition: unpack_exception.hpp:43
Definition: unpack_exception.hpp:70
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
Definition: unpack_exception.hpp:34
Definition: unpack_exception.hpp:52
Definition: unpack_exception.hpp:79
Definition: unpack_exception.hpp:25
unsigned int _msgpack_atomic_counter_t
Definition: sysdep.hpp:73
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:85
const size_t COUNTER_SIZE
Definition: unpack_decl.hpp:40
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66