mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 14:02:40 +02:00
@@ -1,6 +1,14 @@
|
|||||||
#include <msgpack.h>
|
#include <msgpack.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void print(char const* buf, unsigned int len)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
for(; i < len ; ++i)
|
||||||
|
printf("%02x ", 0xff & buf[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
msgpack_sbuffer sbuf;
|
msgpack_sbuffer sbuf;
|
||||||
@@ -20,6 +28,8 @@ int main(void)
|
|||||||
msgpack_pack_str(&pk, 7);
|
msgpack_pack_str(&pk, 7);
|
||||||
msgpack_pack_str_body(&pk, "example", 7);
|
msgpack_pack_str_body(&pk, "example", 7);
|
||||||
|
|
||||||
|
print(sbuf.data, sbuf.size);
|
||||||
|
|
||||||
/* deserialize the buffer into msgpack_object instance. */
|
/* deserialize the buffer into msgpack_object instance. */
|
||||||
/* deserialized object is valid during the msgpack_zone instance alive. */
|
/* deserialized object is valid during the msgpack_zone instance alive. */
|
||||||
msgpack_zone_init(&mempool, 2048);
|
msgpack_zone_init(&mempool, 2048);
|
||||||
@@ -35,4 +45,3 @@ int main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,10 +21,10 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#if 0 // When you want to adapt map instead of array, you can enable these macro definition.
|
// When you want to adapt map instead of array, you can enable these macro definition.
|
||||||
#define MSGPACK_USE_DEFINE_MAP
|
//
|
||||||
#define MSGPACK_USE_BOOST
|
// #define MSGPACK_USE_DEFINE_MAP
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <msgpack.hpp>
|
#include <msgpack.hpp>
|
||||||
|
|
||||||
@@ -100,6 +100,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
{ // create object with zone
|
{ // create object with zone
|
||||||
my_class my("John Smith", 42);
|
my_class my("John Smith", 42);
|
||||||
|
my.a = 123;
|
||||||
my.set_b("ABC");
|
my.set_b("ABC");
|
||||||
my.set_c("DEF");
|
my.set_c("DEF");
|
||||||
msgpack::zone z;
|
msgpack::zone z;
|
||||||
|
@@ -28,6 +28,9 @@ class my_class {
|
|||||||
public:
|
public:
|
||||||
my_class() {} // When you want to convert from msgpack::object to my_class,
|
my_class() {} // When you want to convert from msgpack::object to my_class,
|
||||||
// my_class should be default constractible.
|
// my_class should be default constractible.
|
||||||
|
// If you use C++11, you can adapt non-default constructible
|
||||||
|
// classes to msgpack::object.
|
||||||
|
// See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_adaptor#non-default-constructible-class-support-c11-only
|
||||||
my_class(std::string const& name, int age):name_(name), age_(age) {}
|
my_class(std::string const& name, int age):name_(name), age_(age) {}
|
||||||
|
|
||||||
friend bool operator==(my_class const& lhs, my_class const& rhs) {
|
friend bool operator==(my_class const& lhs, my_class const& rhs) {
|
||||||
@@ -39,7 +42,7 @@ private:
|
|||||||
int age_;
|
int age_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MSGPACK_DEFINE(name_, age_);
|
MSGPACK_DEFINE_MAP(name_, age_);
|
||||||
};
|
};
|
||||||
|
|
||||||
void print(std::string const& buf) {
|
void print(std::string const& buf) {
|
||||||
|
Reference in New Issue
Block a user