Skip to content

Commit 94ddf1a

Browse files
committed
Merge pull request #342 from redboltz/fix_examles
Fix examles
2 parents 51dd7cb + 5da1abb commit 94ddf1a

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

example/c/simple_c.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
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+
412
int 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-

example/cpp03/class_intrusive.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
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;

example/cpp03/class_intrusive_map.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class my_class {
2828
public:
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

4144
public:
42-
MSGPACK_DEFINE(name_, age_);
45+
MSGPACK_DEFINE_MAP(name_, age_);
4346
};
4447

4548
void print(std::string const& buf) {

0 commit comments

Comments
 (0)