12 #include <boost/optional.hpp> 16 #pragma warning(disable:4583) 17 #pragma warning(disable:4582) 18 #include <boost/variant2/variant.hpp> 21 #include <boost/variant2/variant.hpp> 35 struct convert<boost::optional<T>> {
36 const clmdep_msgpack::object &operator()(
37 const clmdep_msgpack::object &o,
38 boost::optional<T> &v)
const {
39 if (o.type != clmdep_msgpack::type::ARRAY) {
42 if (o.via.array.size == 1) {
44 }
else if (o.via.array.size == 2) {
45 v.reset(o.via.array.ptr[1].as<T>());
54 struct pack<boost::optional<T>> {
55 template <
typename Stream>
56 packer<Stream> &operator()(
57 clmdep_msgpack::packer<Stream> &o,
58 const boost::optional<T> &v)
const {
72 struct object_with_zone<boost::optional<T>> {
74 clmdep_msgpack::object::with_zone &o,
75 const boost::optional<T> &v)
const {
79 o.via.array.ptr =
static_cast<clmdep_msgpack::object*
>(o.zone.allocate_align(
80 sizeof(clmdep_msgpack::object) * o.via.array.size,
81 MSGPACK_ZONE_ALIGNOF(clmdep_msgpack::object)));
82 o.via.array.ptr[0] = clmdep_msgpack::object(
true, o.zone);
83 o.via.array.ptr[1] = clmdep_msgpack::object(*v, o.zone);
86 o.via.array.ptr =
static_cast<clmdep_msgpack::object*
>(o.zone.allocate_align(
87 sizeof(clmdep_msgpack::object) * o.via.array.size,
88 MSGPACK_ZONE_ALIGNOF(clmdep_msgpack::object)));
89 o.via.array.ptr[0] = clmdep_msgpack::object(
false, o.zone);
98 template<
typename... Ts>
99 struct convert<boost::variant2::variant<Ts...>> {
101 const clmdep_msgpack::object &operator()(
102 const clmdep_msgpack::object &o,
103 boost::variant2::variant<Ts...> &v)
const {
104 if (o.type != clmdep_msgpack::type::ARRAY) {
107 if (o.via.array.size != 2) {
110 const auto index = o.via.array.ptr[0].as<uint64_t>();
111 copy_to_variant(index, o, v, std::make_index_sequence<
sizeof...(Ts)>());
117 template <u
int64_t I>
118 static void copy_to_variant_impl(
119 const clmdep_msgpack::object &o,
120 boost::variant2::variant<Ts...> &v) {
122 auto dummy = std::get<I>(std::tuple<Ts...>{});
123 using T = decltype(dummy);
124 v = o.via.array.ptr[1].as<T>();
127 template <uint64_t... Is>
128 static void copy_to_variant(
129 const uint64_t index,
130 const clmdep_msgpack::object &o,
131 boost::variant2::variant<Ts...> &v,
132 std::index_sequence<Is...>) {
133 std::initializer_list<int> ({
134 (index == Is ? copy_to_variant_impl<Is>(o, v), 0 : 0)...
139 template<
typename... Ts>
140 struct pack<boost::variant2::variant<Ts...>> {
141 template <
typename Stream>
142 packer<Stream> &operator()(
143 clmdep_msgpack::packer<Stream> &o,
144 const boost::variant2::variant<Ts...> &v)
const {
146 o.pack(static_cast<uint64_t>(v.index()));
147 boost::variant2::visit([&](
const auto &value) { o.pack(value); }, v);
152 template<
typename... Ts>
153 struct object_with_zone<boost::variant2::variant<Ts...>> {
155 clmdep_msgpack::object::with_zone &o,
156 const boost::variant2::variant<Ts...> &v)
const {
157 o.type = type::ARRAY;
158 o.via.array.size = 2;
159 o.via.array.ptr =
static_cast<clmdep_msgpack::object*
>(o.zone.allocate_align(
160 sizeof(clmdep_msgpack::object) * o.via.array.size,
161 MSGPACK_ZONE_ALIGNOF(clmdep_msgpack::object)));
162 o.via.array.ptr[0] = clmdep_msgpack::object(static_cast<uint64_t>(v.index()), o.zone);
163 boost::variant2::visit([&](
const auto &value) {
164 o.via.array.ptr[1] = clmdep_msgpack::object(value, o.zone);
void throw_exception(const std::exception &e)
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)