diff options
author | frsyuki <frsyuki@vcore.(none)> | 2009-02-24 16:37:01 +0900 |
---|---|---|
committer | frsyuki <frsyuki@vcore.(none)> | 2009-02-24 16:37:01 +0900 |
commit | aaaaecb8bad862afc66ad5a2772adb78b9082df8 (patch) | |
tree | da16e60a91e315825eca1a782558b5d8235e54b8 /example | |
parent | 0698304071f3cfb4f86135fcc0423609d8288d6b (diff) | |
download | msgpack-python-aaaaecb8bad862afc66ad5a2772adb78b9082df8.tar.gz |
add example/simple.c
Diffstat (limited to 'example')
-rw-r--r-- | example/simple.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/example/simple.c b/example/simple.c new file mode 100644 index 0000000..df60424 --- /dev/null +++ b/example/simple.c @@ -0,0 +1,37 @@ +#include <msgpack.h> +#include <stdio.h> + +int main(void) +{ + /* msgpack::sbuffer is a simple buffer implementation. */ + msgpack_sbuffer sbuf; + msgpack_sbuffer_init(&sbuf); + + /* serialize values into the buffer using msgpack_sbuffer_write callback function. */ + msgpack_packer pk; + msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); + + msgpack_pack_array(&pk, 3); + msgpack_pack_int(&pk, 1); + msgpack_pack_true(&pk); + msgpack_pack_raw(&pk, 7); + msgpack_pack_raw_body(&pk, "example", 7); + + /* deserialize the buffer into msgpack_object instance. */ + /* deserialized object is valid during the msgpack_zone instance alive. */ + msgpack_zone mempool; + msgpack_zone_init(&mempool, 2048); + + msgpack_object deserialized; + msgpack_unpack(sbuf.ptr, sbuf.size, NULL, &mempool, &deserialized); + + /* print the deserialized object. */ + msgpack_object_print(stdout, deserialized); + puts(""); + + msgpack_zone_destroy(&mempool); + msgpack_sbuffer_destroy(&sbuf); + + return 0; +} + |