MessagePack for C++
x3_unpack.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ deserializing routine
3 //
4 // Copyright (C) 2017 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_V2_X3_UNPACK_HPP
11 #define MSGPACK_V2_X3_UNPACK_HPP
12 
13 #if defined(MSGPACK_USE_X3_PARSE)
14 
15 #include <boost/version.hpp>
16 
17 #if BOOST_VERSION >= 106100
18 
19 #include "msgpack/versioning.hpp"
21 #include "msgpack/v2/x3_parse.hpp"
22 
23 namespace msgpack {
24 
28 
29 namespace detail {
30 
31 template <typename Iterator>
32 inline void
33 unpack_imp(Iterator&& begin, Iterator&& end,
34  msgpack::zone& result_zone, msgpack::object& result, bool& referenced,
36  unpack_limit const& limit = unpack_limit())
37 {
38  create_object_visitor v(f, user_data, limit);
39  v.set_zone(result_zone);
40  referenced = false;
41  v.set_referenced(referenced);
42  if (!parse(std::forward<Iterator>(begin), std::forward<Iterator>(end), v)) {
43  throw msgpack::parse_error("parse error");
44  }
45  referenced = v.referenced();
46  result = v.data();
47 }
48 
49 } // namespace detail
50 
51 
52 template <typename Iterator>
54  Iterator&& begin, Iterator&& end,
55  bool& referenced,
57  unpack_limit const& limit = unpack_limit())
58 {
59  msgpack::object obj;
61  referenced = false;
63  std::forward<Iterator>(begin), std::forward<Iterator>(end), *z, obj, referenced, f, user_data, limit);
64  return msgpack::object_handle(obj, msgpack::move(z));
65 }
66 
67 template <typename Iterator>
69  Iterator&& begin, Iterator&& end,
71  unpack_limit const& limit = unpack_limit())
72 {
73  bool referenced;
74  return unpack(std::forward<Iterator>(begin), std::forward<Iterator>(end), referenced, f, user_data, limit);
75 }
76 
77 template <typename Iterator>
78 inline msgpack::object unpack(
79  msgpack::zone& z,
80  Iterator&& begin, Iterator&& end,
81  bool& referenced,
83  unpack_limit const& limit = unpack_limit())
84 {
85  msgpack::object obj;
86  referenced = false;
88  std::forward<Iterator>(begin), std::forward<Iterator>(end), z, obj, referenced, f, user_data, limit);
89  return obj;
90 }
91 
92 template <typename Iterator>
93 inline msgpack::object unpack(
94  msgpack::zone& z,
95  Iterator&& begin, Iterator&& end,
97  unpack_limit const& limit = unpack_limit())
98 {
99  bool referenced;
100  return unpack(
101  z, std::forward<Iterator>(begin), std::forward<Iterator>(end), referenced, f, user_data, limit);
102 }
103 
104 
106 } // MSGPACK_API_VERSION_NAMESPACE(v2)
108 
109 } // namespace msgpack
110 
111 #else // BOOST_VERSION >= 106100
112 
113 #error Boost 1.61.0 or later is required to use x3 parse
114 
115 #endif // BOOST_VERSION >= 106100
116 
117 #endif // defined(MSGPACK_USE_X3_PARSE)
118 
119 #endif // MSGPACK_V2_X3_UNPACK_HPP
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:1339
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_kv * begin(msgpack::object_map &map)
Definition: iterator.hpp:23
Definition: adaptor_base.hpp:15
Definition: unpack_exception.hpp:34
Definition: cpp03_zone.hpp:22
msgpack::object_kv * end(msgpack::object_map &map)
Definition: iterator.hpp:25
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:1383
bool parse(const char *data, size_t len, size_t &off, Visitor &v)
Unpack msgpack formatted data via a visitor.
Definition: parse.hpp:1000
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:35
T & move(T &t)
The class holds object and zone.
Definition: object.hpp:43