在具有变体数据结构的 C++ 中使用 msgpack

Using msgpack in C++ with variant data structures

在问题 Deserializing a heterogeneous map with MessagePack in C++ an answer refers to a gist which contains an example of based on recursive boost::variant with msgpack. I am trying to replicate this with the latest msgpack-c library version (1.3.0) 中,在编译时出现了一些错误。其中一些与 API 中类型的变化有关(msgpack 类型 DOUBLE 和 RAW 不再存在),其他似乎更基本:

In file included from msgpack-c/include/msgpack.hpp:10:0,
             from variant.cpp:2:
msgpack-c/include/msgpack/object.hpp: In instantiation of ‘const msgpack::v1::object& msgpack::v1::adaptor::convert<T, Enabler>::operator()(const
<... lengthy output snipped for clarity ...>
  msgpack::v1::object&, T&) const [with T = boost::detail::variant::void_>’ has no member named ‘msgpack_unpack’
 v.msgpack_unpack(o.convert());

以及关于没有名为 msgpack_pack 的成员的类似消息。

是否有与最新 msgpack-c 版本兼容的更新要点或示例?

我正在 CentOS7 机器上编译,gcc 版本 4.8.5,boost 1.58,msgpack-c 包含为 header-only,使用以下命令:

g++ --std=c++11 -Imsgpack-c/include -o variant variant.cpp

Is there an updated gist or example of this that i compatible with the latest msgpack-c version?

msgpack-c 存储库中有使用变体的示例。

参见:

https://github.com/msgpack/msgpack-c/blob/cpp_master/example/boost/msgpack_variant_capitalize.cpp https://github.com/msgpack/msgpack-c/blob/cpp_master/example/boost/msgpack_variant_mapbased.cpp

msgpack-c 现在包含变体适配器。它基于以下想法:

Deserializing a heterogeneous map with MessagePack in C++

这是适配器:

https://github.com/msgpack/msgpack-c/blob/cpp_master/include/msgpack/v1/adaptor/boost/msgpack_variant.hpp

以下讨论可能有助于理解变体的概念:

https://github.com/msgpack/msgpack-c/pull/349

为了使用适配器,您需要定义MSGPACK_USE_BOOST。

参见:

https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_use_boost-since-120