Skip to content

Instantly share code, notes, and snippets.

@choplin
Last active December 29, 2015 23:39
Show Gist options
  • Save choplin/7744006 to your computer and use it in GitHub Desktop.
Save choplin/7744006 to your computer and use it in GitHub Desktop.
#include <msgpack.h>
int main()
{
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
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);
size_t size = sbuf.size;
char *msg = msgpack_sbuffer_release(&sbuf);
msgpack_pack_array(&pk, 3);
msgpack_pack_int(&pk, 1);
/* put binary into buffer directly */
msgpack_sbuffer_write(&sbuf, msg, size);
msgpack_pack_true(&pk);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment