@@ -20,35 +20,37 @@ To use the library in your program, include msgpack.hpp header and link "msgpack
2020
2121
2222## Example
23-
24- #include <msgpack.hpp>
25- #include <vector>
23+ ``` CPP
24+ #include < msgpack.hpp>
25+ #include < vector>
2626
27- int main(void) {
28- // This is target object.
29- std::vector<std::string> target;
30- target.push_back("Hello,");
31- target.push_back("World!");
27+ int main (void) {
28+ // This is target object.
29+ std::vector< std::string > target;
30+ target.push_back("Hello,");
31+ target.push_back("World!");
3232
33- // Serialize it.
34- msgpack::sbuffer sbuf; // simple buffer
35- msgpack::pack(&sbuf, target);
33+ // Serialize it.
34+ msgpack::sbuffer sbuf; // simple buffer
35+ msgpack::pack(&sbuf, target);
3636
37- // Deserialize the serialized data.
38- msgpack::unpacked msg; // includes memory pool and deserialized object
39- msgpack::unpack(&msg, sbuf.data(), sbuf.size());
40- msgpack::object obj = msg.get();
37+ // Deserialize the serialized data.
38+ msgpack::unpacked msg; // includes memory pool and deserialized object
39+ msgpack::unpack(&msg, sbuf.data(), sbuf.size());
40+ msgpack::object obj = msg.get();
4141
42- // Print the deserialized object to stdout.
43- std::cout << obj << std::endl; // ["Hello," "World!"]
42+ // Print the deserialized object to stdout.
43+ std::cout << obj << std::endl; // [ "Hello," "World!"]
4444
45- // Convert the deserialized object to staticaly typed object.
46- std::vector<std::string> result;
47- obj.convert(&result);
45+ // Convert the deserialized object to staticaly typed object.
46+ std::vector< std::string > result;
47+ obj.convert(&result);
4848
49- // If the type is mismatched, it throws msgpack::type_error.
50- obj.as<int>(); // type is mismatched, msgpack::type_error is thrown
51- }
49+ // If the type is mismatched, it throws msgpack::type_error.
50+ obj.as<int >(); // type is mismatched, msgpack::type_error is thrown
51+ }
52+ ```
53+
5254
5355API documents and other example codes are available at the [wiki.](http://redmine.msgpack.org/projects/msgpack/wiki)
5456
0 commit comments