From 0a344ef875791f68142d4bc9bfb12ea0a2c22816 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Tue, 10 Jan 2017 21:48:48 +0900 Subject: [PATCH] Updated v2_0_cpp_adaptor (markdown) --- v2_0_cpp_adaptor.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/v2_0_cpp_adaptor.md b/v2_0_cpp_adaptor.md index d229495..50a6c89 100644 --- a/v2_0_cpp_adaptor.md +++ b/v2_0_cpp_adaptor.md @@ -141,6 +141,24 @@ I use JSON to help understanding. But actual condition is msgpack format. When you use an array based adaptor, e.g.)MSGPACK_DEFINE_ARRAY, the order of member variables and base classes is important. The index of the msgpack::object array is corresponding to the member variables order. When you use a map based adaptor, e.g.)MSGPACK_DEFINE_MAP, the names of member variables and base classes is important. The keys of the msgpack::object map is corresponding to member variables names and the base classes names. +##### since 2.1.0 +You can also customize the name of the map key using MSGPACK_NVP. +For example, the key of the value `b` is `#b`. You can use any strings even if it can't use as C++ variable name. It helps inter programming language data transportation. + +```cpp +#include + +struct your_class { + int a; + std::string b; + MSGPACK_DEFINE_MAP(a, MSGPACK_NVP("#b", b)); +}; +``` + +```Javascript +{"a":42,"#b":"ABC"} +``` + #### non-intrusive approach When you don't want to modify your class, you can use non-intrusive approach. msgpack-c provides the following four functor class templates. Those templates are in the namespace msgpack::adaptor.