10#ifndef MSGPACK_V2_X3_PARSE_HPP
11#define MSGPACK_V2_X3_PARSE_HPP
13#if defined(MSGPACK_USE_X3_PARSE)
15#include <boost/version.hpp>
17#if BOOST_VERSION >= 106100
23#pragma GCC diagnostic push
24#pragma GCC diagnostic ignored "-Wunused-parameter"
25#pragma GCC diagnostic ignored "-Wconversion"
28#include <boost/config/warning_disable.hpp>
29#include <boost/spirit/home/x3.hpp>
30#include <boost/spirit/home/x3/binary.hpp>
40namespace x3 = boost::spirit::x3;
48 const std::uint8_t value = x3::_attr(
ctx);
49 x3::_val(
ctx) = value;
50 x3::_pass(
ctx) =
from <= value && value <=
to;
52 return x3::byte_ [check];
60const auto mp_nil = x3::byte_(0xc0);
61const auto mp_false = x3::byte_(0xc2);
62const auto mp_true = x3::byte_(0xc3);
63const auto mp_bin8 = x3::byte_(0xc4);
64const auto mp_bin16 = x3::byte_(0xc5);
65const auto mp_bin32 = x3::byte_(0xc6);
66const auto mp_ext8 = x3::byte_(0xc7);
67const auto mp_ext16 = x3::byte_(0xc8);
68const auto mp_ext32 = x3::byte_(0xc9);
71const auto mp_uint8 = x3::byte_(0xcc);
75const auto mp_int8 = x3::byte_(0xd0);
76const auto mp_int16 = x3::byte_(0xd1);
77const auto mp_int32 = x3::byte_(0xd2);
78const auto mp_int64 = x3::byte_(0xd3);
84const auto mp_str8 = x3::byte_(0xd9);
85const auto mp_str16 = x3::byte_(0xda);
86const auto mp_str32 = x3::byte_(0xdb);
89const auto mp_map16 = x3::byte_(0xde);
90const auto mp_map32 = x3::byte_(0xdf);
103x3::rule<class mp_object>
const mp_object(
"mp_object");
104x3::rule<class array_items>
const array_item(
"array_item");
105x3::rule<class map_items>
const map_item(
"map_item");
106x3::rule<class kv>
const kv(
"kv");
115 index_size(std::size_t size, type_t type = type_t::other):
size(
size), type(type) {}
116 std::size_t index = 0;
121template <
typename Visitor>
123 template <
typename Vis>
124 app_specific(Vis&& vis):vis(vis) {}
125 std::vector<index_size> index_sizes;
129template <
typename Visitor>
134const auto more = [](
auto &
ctx) {
139const auto done = [](
auto &
ctx) {
144 case index_size::type_t::array:
147 case index_size::type_t::map:
150 case index_size::type_t::other:
206 std::int8_t val =
static_cast<std::int8_t
>(
_attr(
ctx));
257 std::int8_t val =
static_cast<std::int8_t
>(
_attr(
ctx));
268 std::int16_t val =
static_cast<std::int16_t
>(
_attr(
ctx));
279 std::int32_t val =
static_cast<std::int32_t
>(
_attr(
ctx));
290 std::int64_t val =
static_cast<std::int64_t
>(
_attr(
ctx));
313#if defined(TARGET_OS_IPHONE)
315#elif defined(__arm__) && !(__ARM_EABI__)
317 mem.i = (
mem.i & 0xFFFFFFFFUL) << 32UL | (
mem.i >> 32UL);
336 *(x3::eps [
more] >> x3::char_)
343 auto size =
static_cast<uint32_t>(std::distance(str.begin(), str.end()));
360 *(x3::eps [
more] >> x3::char_)
367 auto size =
static_cast<uint32_t>(std::distance(str.begin(), str.end()));
384 *(x3::eps [
more] >> x3::char_)
391 auto size =
static_cast<uint32_t>(std::distance(str.begin(), str.end()));
408 *(x3::eps [
more] >> x3::char_)
415 auto size =
static_cast<uint32_t>(std::distance(str.begin(), str.end()));
432 *(x3::eps [
more] >> x3::char_)
439 auto size =
static_cast<uint32_t>(std::distance(bin.begin(), bin.end()));
456 *(x3::eps [
more] >> x3::char_)
463 auto size =
static_cast<uint32_t>(std::distance(bin.begin(), bin.end()));
480 *(x3::eps [
more] >> x3::char_)
487 auto size =
static_cast<uint32_t>(std::distance(bin.begin(), bin.end()));
499 app_specific.index_sizes.emplace_back(size, index_size::type_t::array);
513 app_specific.index_sizes.emplace_back(size, index_size::type_t::array);
527 app_specific.index_sizes.emplace_back(size, index_size::type_t::array);
541 app_specific.index_sizes.emplace_back(size, index_size::type_t::map);
555 app_specific.index_sizes.emplace_back(size, index_size::type_t::map);
569 app_specific.index_sizes.emplace_back(size, index_size::type_t::map);
588 *(x3::eps [
more] >> x3::char_)
595 auto size =
static_cast<uint32_t>(std::distance(ext.begin(), ext.end()));
612 *(x3::eps [
more] >> x3::char_)
619 auto size =
static_cast<uint32_t>(std::distance(ext.begin(), ext.end()));
636 *(x3::eps [
more] >> x3::char_)
643 auto size =
static_cast<uint32_t>(std::distance(ext.begin(), ext.end()));
660 *(x3::eps [
more] >> x3::char_)
667 auto size =
static_cast<uint32_t>(std::distance(ext.begin(), ext.end()));
684 *(x3::eps [
more] >> x3::char_)
691 auto size =
static_cast<uint32_t>(std::distance(ext.begin(), ext.end()));
708 *(x3::eps [
more] >> x3::char_)
715 auto size =
static_cast<uint32_t>(std::distance(ext.begin(), ext.end()));
732 *(x3::eps [
more] >> x3::char_)
739 auto size =
static_cast<uint32_t>(std::distance(ext.begin(), ext.end()));
756 *(x3::eps [
more] >> x3::char_)
763 auto size =
static_cast<uint32_t>(std::distance(ext.begin(), ext.end()));
847template <
typename Iterator,
typename Visitor>
849 auto data = detail::make_app_specific(std::forward<Visitor>(
vis));
850 return detail::x3::parse(
851 std::forward<Iterator>(begin),
852 std::forward<Iterator>(end),
853 detail::x3::with<detail::tag_app_specific>(std::ref(data))[detail::rule]
864#pragma GCC diagnostic pop
869#error Boost 1.61.0 or later is required to use x3 parse
std::size_t size(T const &t)
Definition size_equal_only.hpp:24
Definition adaptor_base.hpp:15
void convert(T &v, msgpack::object const &o)
Definition object.hpp:1178
bool parse(const char *data, size_t len, size_t &off, Visitor &v)
Unpack msgpack formatted data via a visitor.
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:66