File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 11#include <msgpack.h>
22#include <stdio.h>
33
4+ void print (char const * buf , unsigned int len )
5+ {
6+ size_t i = 0 ;
7+ for (; i < len ; ++ i )
8+ printf ("%02x " , 0xff & buf [i ]);
9+ printf ("\n" );
10+ }
11+
412int main (void )
513{
614 msgpack_sbuffer sbuf ;
@@ -20,6 +28,8 @@ int main(void)
2028 msgpack_pack_str (& pk , 7 );
2129 msgpack_pack_str_body (& pk , "example" , 7 );
2230
31+ print (sbuf .data , sbuf .size );
32+
2333 /* deserialize the buffer into msgpack_object instance. */
2434 /* deserialized object is valid during the msgpack_zone instance alive. */
2535 msgpack_zone_init (& mempool , 2048 );
@@ -35,4 +45,3 @@ int main(void)
3545
3646 return 0 ;
3747}
38-
Original file line number Diff line number Diff line change 2121#include < sstream>
2222#include < cassert>
2323
24- # if 0 // When you want to adapt map instead of array, you can enable these macro definition.
25- #define MSGPACK_USE_DEFINE_MAP
26- #define MSGPACK_USE_BOOST
27- # endif
24+ // When you want to adapt map instead of array, you can enable these macro definition.
25+ //
26+ // #define MSGPACK_USE_DEFINE_MAP
27+
2828
2929#include < msgpack.hpp>
3030
@@ -100,6 +100,7 @@ int main() {
100100 }
101101 { // create object with zone
102102 my_class my (" John Smith" , 42 );
103+ my.a = 123 ;
103104 my.set_b (" ABC" );
104105 my.set_c (" DEF" );
105106 msgpack::zone z;
Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ class my_class {
2828public:
2929 my_class () {} // When you want to convert from msgpack::object to my_class,
3030 // my_class should be default constractible.
31+ // If you use C++11, you can adapt non-default constructible
32+ // classes to msgpack::object.
33+ // See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_adaptor#non-default-constructible-class-support-c11-only
3134 my_class (std::string const & name, int age):name_(name), age_(age) {}
3235
3336 friend bool operator ==(my_class const & lhs, my_class const & rhs) {
@@ -39,7 +42,7 @@ class my_class {
3942 int age_;
4043
4144public:
42- MSGPACK_DEFINE (name_, age_);
45+ MSGPACK_DEFINE_MAP (name_, age_);
4346};
4447
4548void print (std::string const & buf) {
You can’t perform that action at this time.
0 commit comments