Moved examples.

Added intrusive and non-intrusive versions of packing and unpacking examples.
This commit is contained in:
Takatoshi Kondo
2014-11-01 18:13:52 +09:00
parent a0ae0289dc
commit 79e7a9810c
13 changed files with 150 additions and 1 deletions

58
example/cpp03/custom.cpp Normal file
View File

@@ -0,0 +1,58 @@
#include <msgpack.hpp>
#include <string>
#include <iostream>
class old_class {
public:
old_class() : value("default") { }
std::string value;
MSGPACK_DEFINE(value);
};
class new_class {
public:
new_class() : value("default"), flag(-1) { }
std::string value;
int flag;
MSGPACK_DEFINE(value, flag);
};
int main(void)
{
{
old_class oc;
new_class nc;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, oc);
msgpack::unpacked result;
msgpack::unpack(result, sbuf.data(), sbuf.size());
msgpack::object obj = result.get();
obj.convert(&nc);
std::cout << obj << " value=" << nc.value << " flag=" << nc.flag << std::endl;
}
{
new_class nc;
old_class oc;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, nc);
msgpack::unpacked result;
msgpack::unpack(result, sbuf.data(), sbuf.size());
msgpack::object obj = result.get();
obj.convert(&oc);
std::cout << obj << " value=" << oc.value << std::endl;
}
}