Updated v2_0_cpp_adaptor (markdown)

Takatoshi Kondo
2017-01-10 21:48:48 +09:00
parent f3b74edb3a
commit 0a344ef875
+18
@@ -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 <msgpack.hpp>
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.