MessagePack for C++
unpack.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ deserializing routine
3 //
4 // Copyright (C) 2018 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_V3_UNPACK_HPP
11 #define MSGPACK_V3_UNPACK_HPP
12 
13 #include "msgpack/unpack_decl.hpp"
14 #include "msgpack/parse.hpp"
16 
17 namespace msgpack {
18 
22 
24  const char* data, std::size_t len, std::size_t& off, bool& referenced,
25  msgpack::unpack_reference_func f, void* user_data,
26  msgpack::unpack_limit const& limit
27 )
28 {
29  msgpack::object obj;
30  msgpack::unique_ptr<msgpack::zone> z(new msgpack::zone);
31  referenced = false;
33  data, len, off, *z, obj, referenced, f, user_data, limit);
34 
35  switch(ret) {
36  case PARSE_SUCCESS:
37  return msgpack::object_handle(obj, msgpack::move(z));
38  case PARSE_EXTRA_BYTES:
39  return msgpack::object_handle(obj, msgpack::move(z));
40  default:
41  break;
42  }
43  return msgpack::object_handle();
44 }
45 
47  const char* data, std::size_t len, std::size_t& off,
48  msgpack::unpack_reference_func f, void* user_data,
49  msgpack::unpack_limit const& limit)
50 {
51  bool referenced;
52  return msgpack::v3::unpack(data, len, off, referenced, f, user_data, limit);
53 }
54 
56  const char* data, std::size_t len, bool& referenced,
57  msgpack::unpack_reference_func f, void* user_data,
58  msgpack::unpack_limit const& limit)
59 {
60  std::size_t off = 0;
61  return msgpack::v3::unpack(data, len, off, referenced, f, user_data, limit);
62 }
63 
65  const char* data, std::size_t len,
66  msgpack::unpack_reference_func f, void* user_data,
67  msgpack::unpack_limit const& limit)
68 {
69  bool referenced;
70  std::size_t off = 0;
71  return msgpack::v3::unpack(data, len, off, referenced, f, user_data, limit);
72 }
73 
74 inline void unpack(
75  msgpack::object_handle& result,
76  const char* data, std::size_t len, std::size_t& off, bool& referenced,
77  msgpack::unpack_reference_func f, void* user_data,
78  msgpack::unpack_limit const& limit)
79 {
80  msgpack::object obj;
81  msgpack::unique_ptr<msgpack::zone> z(new msgpack::zone);
82  referenced = false;
84  data, len, off, *z, obj, referenced, f, user_data, limit);
85 
86  switch(ret) {
87  case PARSE_SUCCESS:
88  result.set(obj);
89  result.zone() = msgpack::move(z);
90  return;
91  case PARSE_EXTRA_BYTES:
92  result.set(obj);
93  result.zone() = msgpack::move(z);
94  return;
95  default:
96  return;
97  }
98 }
99 
100 inline void unpack(
101  msgpack::object_handle& result,
102  const char* data, std::size_t len, std::size_t& off,
103  msgpack::v3::unpack_reference_func f, void* user_data,
104  msgpack::unpack_limit const& limit)
105 {
106  bool referenced;
107  msgpack::v3::unpack(result, data, len, off, referenced, f, user_data, limit);
108 }
109 
110 inline void unpack(
111  msgpack::object_handle& result,
112  const char* data, std::size_t len, bool& referenced,
113  msgpack::unpack_reference_func f, void* user_data,
114  msgpack::unpack_limit const& limit)
115 {
116  std::size_t off = 0;
117  msgpack::v3::unpack(result, data, len, off, referenced, f, user_data, limit);
118 }
119 
120 inline void unpack(
121  msgpack::object_handle& result,
122  const char* data, std::size_t len,
123  msgpack::unpack_reference_func f, void* user_data,
124  msgpack::unpack_limit const& limit)
125 {
126  bool referenced;
127  std::size_t off = 0;
128  msgpack::v3::unpack(result, data, len, off, referenced, f, user_data, limit);
129 }
130 
131 
132 inline msgpack::object unpack(
133  msgpack::zone& z,
134  const char* data, std::size_t len, std::size_t& off, bool& referenced,
135  msgpack::unpack_reference_func f, void* user_data,
136  msgpack::unpack_limit const& limit)
137 {
138  msgpack::object obj;
139  referenced = false;
141  data, len, off, z, obj, referenced, f, user_data, limit);
142 
143  switch(ret) {
144  case PARSE_SUCCESS:
145  return obj;
146  case PARSE_EXTRA_BYTES:
147  return obj;
148  default:
149  break;
150  }
151  return obj;
152 }
153 
154 inline msgpack::object unpack(
155  msgpack::zone& z,
156  const char* data, std::size_t len, std::size_t& off,
157  msgpack::unpack_reference_func f, void* user_data,
158  msgpack::unpack_limit const& limit)
159 {
160  bool referenced;
161  return msgpack::v3::unpack(z, data, len, off, referenced, f, user_data, limit);
162 }
163 
164 inline msgpack::object unpack(
165  msgpack::zone& z,
166  const char* data, std::size_t len, bool& referenced,
167  msgpack::unpack_reference_func f, void* user_data,
168  msgpack::unpack_limit const& limit)
169 {
170  std::size_t off = 0;
171  return msgpack::v3::unpack(z, data, len, off, referenced, f, user_data, limit);
172 }
173 
174 inline msgpack::object unpack(
175  msgpack::zone& z,
176  const char* data, std::size_t len,
177  msgpack::unpack_reference_func f, void* user_data,
178  msgpack::unpack_limit const& limit)
179 {
180  bool referenced;
181  std::size_t off = 0;
182  return msgpack::v3::unpack(z, data, len, off, referenced, f, user_data, limit);
183 }
184 
186 } // MSGPACK_API_VERSION_NAMESPACE(v3)
188 
189 } // namespace msgpack
190 
191 
192 #endif // MSGPACK_V3_UNPACK_HPP
The class holds object and zone.
Definition: object.hpp:44
msgpack::unique_ptr< msgpack::zone > & zone()
Get unique_ptr reference of zone.
Definition: object.hpp:90
void set(msgpack::object const &obj)
Definition: object.hpp:64
Definition: unpack_decl.hpp:87
Definition: cpp03_zone.hpp:31
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
Definition: adaptor_base.hpp:15
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
void unpack(msgpack::object_handle &result, const char *data, std::size_t len, std::size_t &off, msgpack::v3::unpack_reference_func f, void *user_data, msgpack::unpack_limit const &limit)
Definition: unpack.hpp:100
parse_return
Definition: parse_return.hpp:23
@ PARSE_EXTRA_BYTES
Definition: parse_return.hpp:25
@ PARSE_SUCCESS
Definition: parse_return.hpp:24
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
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66