summaryrefslogtreecommitdiff
path: root/example/simple.cc
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@vcore.(none)>2009-02-24 16:37:47 +0900
committerfrsyuki <frsyuki@vcore.(none)>2009-02-24 16:37:47 +0900
commitbdd13859b60d06ec6fabdbaccea81cbee189b8bc (patch)
treec76ff69b75cd98c669ead4c25ca1d3fd33b0666a /example/simple.cc
parentaaaaecb8bad862afc66ad5a2772adb78b9082df8 (diff)
downloadmsgpack-python-bdd13859b60d06ec6fabdbaccea81cbee189b8bc.tar.gz
c: msgpack_pack_object
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;
}