From 680ddb155744fe710be8c5467fbc70d4e75b97ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uli=20K=C3=B6hler?= Date: Sat, 17 Aug 2013 03:11:15 +0200 Subject: [PATCH] Add README syntax highlighting --- README.md | 58 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 972f4372..6f2f9d91 100644 --- a/README.md +++ b/README.md @@ -20,35 +20,37 @@ To use the library in your program, include msgpack.hpp header and link "msgpack ## Example +```CPP +#include +#include + +int main(void) { + // This is target object. + std::vector target; + target.push_back("Hello,"); + target.push_back("World!"); + + // Serialize it. + msgpack::sbuffer sbuf; // simple buffer + msgpack::pack(&sbuf, target); + + // Deserialize the serialized data. + msgpack::unpacked msg; // includes memory pool and deserialized object + msgpack::unpack(&msg, sbuf.data(), sbuf.size()); + msgpack::object obj = msg.get(); + + // Print the deserialized object to stdout. + std::cout << obj << std::endl; // ["Hello," "World!"] + + // Convert the deserialized object to staticaly typed object. + std::vector result; + obj.convert(&result); + + // If the type is mismatched, it throws msgpack::type_error. + obj.as(); // type is mismatched, msgpack::type_error is thrown +} +``` - #include - #include - - int main(void) { - // This is target object. - std::vector target; - target.push_back("Hello,"); - target.push_back("World!"); - - // Serialize it. - msgpack::sbuffer sbuf; // simple buffer - msgpack::pack(&sbuf, target); - - // Deserialize the serialized data. - msgpack::unpacked msg; // includes memory pool and deserialized object - msgpack::unpack(&msg, sbuf.data(), sbuf.size()); - msgpack::object obj = msg.get(); - - // Print the deserialized object to stdout. - std::cout << obj << std::endl; // ["Hello," "World!"] - - // Convert the deserialized object to staticaly typed object. - std::vector result; - obj.convert(&result); - - // If the type is mismatched, it throws msgpack::type_error. - obj.as(); // type is mismatched, msgpack::type_error is thrown - } API documents and other example codes are available at the [wiki.](http://redmine.msgpack.org/projects/msgpack/wiki)