Deserialization from human-readable string
Is there any convinient way to deserialize msgpack object from string like this: [[2,17,1,0,""]] ?
Here is a document: https://github.com/msgpack/msgpack-c/wiki/v_2_0_cpp_json
From JSON string to msgpack::object conversion is not directly supported but to msgpack formatted byte stream is supported by JSON for Modern C++.
See https://github.com/nlohmann/json/blob/bab5826504ac04695c33954c07ff832fc7b4b2c8/doc/binary_formats.md
So you can get msgpack::object using the following step:
- Convert from JSON to msgpack formatted byte stream using JSON for Modern C++
- Convert from msgpack formatted byte stream to msgpack::object using msgpack-c. It is called unpack.
Thank you very much. The string "[[2,17,1,0,""]]" is created by code like this:
stringstream ss; msgpack::object obj; ss << obj; string str = ss.str();
Its sadly that msgpack doesnt have internal backward conversion.
EXT types including timestamp aren't supported but other types output as json. See https://github.com/msgpack/msgpack-c/blob/master/include/msgpack/v1/object.hpp#L396
[[2,17,1,0,""]] is json.
msgpack::object has visitor interface. See https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_visitor. This means you can generate any output format.
json to msgpack::object is different. It is out of scope, so far. In order to implement it, msgpack-c needs to support json parser. Fortunately, some of json parser has msgpack formatted binary data converter. If you want to msgpack::object from json, you can implement it using json library.