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"
22 #include "msgpack/x3_parse.hpp"
23 
24 namespace msgpack {
25 
29 
30 namespace detail {
31 
32 template <typename Iterator>
33 inline void
34 unpack_imp(Iterator&& begin, Iterator&& end,
35  msgpack::zone& result_zone, msgpack::object& result, bool& referenced,
36  unpack_reference_func f, void* user_data,
37  unpack_limit const& limit)
38 {
39  create_object_visitor v(f, user_data, limit);
40  v.set_zone(result_zone);
41  referenced = false;
42  v.set_referenced(referenced);
43  if (!parse(std::forward<Iterator>(begin), std::forward<Iterator>(end), v)) {
44  throw msgpack::parse_error("parse error");
45  }
46  referenced = v.referenced();
47  result = v.data();
48 }
49 
50 } // namespace detail
51 
52 
53 template <typename Iterator>
55  Iterator&& begin, Iterator&& end,
56  bool& referenced,
57  unpack_reference_func f, void* user_data,
58  unpack_limit const& limit)
59 {
60  msgpack::object obj;
61  msgpack::unique_ptr<msgpack::zone> z(new msgpack::zone);
62  referenced = false;
64  std::forward<Iterator>(begin), std::forward<Iterator>(end), *z, obj, referenced, f, user_data, limit);
65  return msgpack::object_handle(obj, msgpack::move(z));
66 }
67 
68 template <typename Iterator>
70  Iterator&& begin, Iterator&& end,
71  unpack_reference_func f, void* user_data,
72  unpack_limit const& limit)
73 {
74  bool referenced;
75  return unpack(std::forward<Iterator>(begin), std::forward<Iterator>(end), referenced, f, user_data, limit);
76 }
77 
78 template <typename Iterator>
79 inline msgpack::object unpack(
80  msgpack::zone& z,
81  Iterator&& begin, Iterator&& end,
82  bool& referenced,
83  unpack_reference_func f, void* user_data,
84  unpack_limit const& limit)
85 {
86  msgpack::object obj;
87  referenced = false;
89  std::forward<Iterator>(begin), std::forward<Iterator>(end), z, obj, referenced, f, user_data, limit);
90  return obj;
91 }
92 
93 template <typename Iterator>
94 inline msgpack::object unpack(
95  msgpack::zone& z,
96  Iterator&& begin, Iterator&& end,
97  unpack_reference_func f, void* user_data,
98  unpack_limit const& limit)
99 {
100  bool referenced;
101  return unpack(
102  z, std::forward<Iterator>(begin), std::forward<Iterator>(end), referenced, f, user_data, limit);
103 }
104 
105 
107 } // MSGPACK_API_VERSION_NAMESPACE(v2)
109 
110 } // namespace msgpack
111 
112 #else // BOOST_VERSION >= 106100
113 
114 #error Boost 1.61.0 or later is required to use x3 parse
115 
116 #endif // BOOST_VERSION >= 106100
117 
118 #endif // defined(MSGPACK_USE_X3_PARSE)
119 
120 #endif // MSGPACK_V2_X3_UNPACK_HPP
The class holds object and zone.
Definition: object.hpp:44
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
msgpack::object_kv * end(msgpack::object_map &map)
Definition: iterator.hpp:25
msgpack::object_kv * begin(msgpack::object_map &map)
Definition: iterator.hpp:23
bool parse(const char *data, size_t len, size_t &off, Visitor &v)
Unpack msgpack formatted data via a visitor.
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
Definition: unpack_exception.hpp:34
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66