2

In the question 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) and getting a number of errors at compilation time. Some of these are related to changes in types in the API (msgpack types DOUBLE and RAW no longer present), others seem more fundamental:

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());

and similar messages about no member named msgpack_pack.

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

I am compiling on a CentOS7 machine with gcc version 4.8.5, boost 1.58, msgpack-c included as header-only, using the following command:

g++ --std=c++11 -Imsgpack-c/include -o variant variant.cpp
Community
  • 1
  • 1
Tim Nicholls
  • 23
  • 1
  • 5
  • It seems like your question title and question body address quite different topics - the actual question seems to ask how to use msgpack with C++ `variant`s, but the body, instead of expanding on that, basically just asks how to use msgpack. – Cubic Jan 13 '16 at 12:33

1 Answers1

0

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

There are examples that use variant in the msgpack-c repository.

See:

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 contains variant adaptors now. It is based on the following idea:

Deserializing a heterogeneous map with MessagePack in C++

Here is the adaptor:

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

The following discussion may help to understand the concept of variant:

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

In order to use the adaptor, you need to define MSGPACK_USE_BOOST.

See:

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

Takatoshi Kondo
  • 3,111
  • 17
  • 36
  • That's extremely useful, thank you very much! The crucial elements for me were to learn that it is necessary to define MSGPACK_USE_BOOST and that it is possible to use msgpack::type::variant in structs/classes to be encoded to msgpack. – Tim Nicholls Jan 14 '16 at 14:39
  • I just fixed the broken links. – Takatoshi Kondo Jul 02 '21 at 05:50