summaryrefslogtreecommitdiff
path: root/example/simple.cc
diff options
context:
space:
mode:
Diffstat (limited to 'example/simple.cc')
-rw-r--r--example/simple.cc24
1 files changed, 15 insertions, 9 deletions
diff --git a/example/simple.cc b/example/simple.cc
index 74beeae..55ecdf9 100644
--- a/example/simple.cc
+++ b/example/simple.cc
@@ -5,27 +5,33 @@
int main(void)
{
- // this is target object
msgpack::type::tuple<int, bool, std::string> src(1, true, "example");
- // any classes that implements write(const char*,size_t) can be a buffer
+ // serialize the object into the buffer.
+ // any classes that implements write(const char*,size_t) can be a buffer.
std::stringstream buffer;
msgpack::pack(buffer, src);
// send the buffer ...
buffer.seekg(0);
- // deserialize the buffer into msgpack::object type
- msgpack::zone mempool;
+ // deserialize the buffer into msgpack::object instance.
std::string str(buffer.str());
- msgpack::object deserialized =
- msgpack::unpack(str.data(), str.size(), mempool);
- // msgpack::object supports ostream
+ // deserialized object is valid during the msgpack::zone instance alive.
+ msgpack::zone mempool;
+
+ msgpack::object deserialized;
+ msgpack::unpack(str.data(), str.size(), NULL, &mempool, &deserialized);
+
+ // msgpack::object supports ostream.
std::cout << deserialized << std::endl;
- // convert msgpack::object type into the original type
+ // convert msgpack::object instance into the original type.
+ // if the type is mismatched, it throws msgpack::type_error exception.
msgpack::type::tuple<int, bool, std::string> dst;
- msgpack::convert(dst, deserialized);
+ deserialized.convert(&dst);
+
+ return 0;
}