8#define MSGPACK_NO_BOOST
9#define MSGPACK_USE_STD_VARIANT_ADAPTOR
10#include "concepts.hpp"
11#include "drop_keys.hpp"
14namespace msgpack::adaptor {
16template <msgpack_concepts::HasMsgPack T>
struct convert<T> {
17 msgpack::object
const& operator()(msgpack::object
const& o, T& v)
const
19 static_assert(std::is_default_constructible_v<T>,
20 "MSGPACK_FIELDS requires default-constructible types (used during unpacking)");
21 v.msgpack([&](
auto&... args) {
22 auto static_checker = [&](
auto&... value_args) {
24 "MSGPACK_FIELDS requires a constructor that can take the types listed in MSGPACK_FIELDS. "
25 "Type or arg count mismatch, or member initializer constructor not available.");
27 std::apply(static_checker, drop_keys(std::tie(args...)));
28 msgpack::type::define_map<
decltype(args)...>{ args... }.msgpack_unpack(o);
35template <msgpack_concepts::HasMsgPack T>
struct pack<T> {
36 template <
typename Stream> packer<Stream>& operator()(msgpack::packer<Stream>& o, T
const& v)
const
38 static_assert(std::is_default_constructible_v<T>,
39 "MSGPACK_FIELDS requires default-constructible types (used during unpacking)");
40 const_cast<T&
>(v).msgpack([&](
auto&... args) {
41 auto static_checker = [&](
auto&... value_args) {
43 "T requires a constructor that can take the fields listed in MSGPACK_FIELDS (T will be "
44 "in template parameters in the compiler stack trace)"
45 "Check the MSGPACK_FIELDS macro usage in T for incompleteness or wrong order."
46 "Alternatively, a matching member initializer constructor might not be available for T "
47 "and should be defined.");
49 std::apply(static_checker, drop_keys(std::tie(args...)));
50 msgpack::type::define_map<
decltype(args)...>{ args... }.msgpack_pack(o);
Definition: concepts.hpp:16