-
Notifications
You must be signed in to change notification settings - Fork 871
v1_1_c_overview
This document is under construction.
Include msgpack.h header file.
#include <msgpack.h>
Link msgpack library.
When you use UNIX, the library name is libmsgpack.a
. When you use Windows, the library name is msgpack.lib
for static link and msgpack_import.lib
for dynamic link.
When you pack your data, use buffers and a packer.
msgpack_sbuffer sbuf; /* buffer */
msgpack_packer pk; /* packer */
msgpack_sbuffer_init(&sbuf); /* initialize buffer */
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); /* initialize packer */
The buffers store packed byte data. The buffers are used by packer. msgpack-c provides four buffers. sbuffer, fbuffer, zbuffer, and vrefbuffer.
sbuffer
is a simple memory buffer. It uses malloc
, realloc
, and free
. fbuffer
is a file buffer. It uses FILE structure in C standard library. zbuffer
is a compressing buffer using zlib. So packed data is compressed. vrefbuffer
is an iovec based buffer. So packed data is stored as iovec.
All buffers have at least three functions. Initialize, Destroy, and Write.
Buffer | Initialize | Destroy | Write |
---|---|---|---|
sbuffer | msgpack_sbuffer_init | msgpack_sbuffer_destroy | msgpack_sbuffer_write |
zbuffer | msgpack_zbuffer_init | msgpack_zbuffer_destroy | msgpack_zbuffer_write |
vrefbuffer | msgpack_vrefbuffer_init | msgpack_vrefbuffer_destroy | msgpack_vrefbuffer_write |
fbuffer | fopen | fclose | msgpack_fbuffer_write |
When you initialize packer, you pass a pointer to the buffer as the second argument, and pass write function pointer as the third argument. Packer calls the write function through the pointer internally.
The buffers have additional buffer specific functions. Please check the source code.
-
Home
- Q&A
- v2.0.x or later
- v1.1.x - v1.4.x
- v1.0.x