Sha256: 5795a475d26771b4721fd55cb82fdab8a78dc6309d60de7e410e5df8dd7cce5f

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

#include <msgpack.h>
#include <stdio.h>

void print(char const* buf,size_t len)
{
    size_t i = 0;
    for(; i < len ; ++i)
        printf("%02x ", 0xff & buf[i]);
    printf("\n");
}

int main(void)
{
    msgpack_sbuffer sbuf;
    msgpack_packer pk;
    msgpack_zone mempool;
    msgpack_object deserialized;

    /* msgpack::sbuffer is a simple buffer implementation. */
    msgpack_sbuffer_init(&sbuf);

    /* serialize values into the buffer using msgpack_sbuffer_write callback function. */
    msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);

    msgpack_pack_array(&pk, 3);
    msgpack_pack_int(&pk, 1);
    msgpack_pack_true(&pk);
    msgpack_pack_str(&pk, 7);
    msgpack_pack_str_body(&pk, "example", 7);

    print(sbuf.data, sbuf.size);

    /* deserialize the buffer into msgpack_object instance. */
    /* deserialized object is valid during the msgpack_zone instance alive. */
    msgpack_zone_init(&mempool, 2048);

    msgpack_unpack(sbuf.data, 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;
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
script_core-0.3.2 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.3.0 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.2.7 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.2.6 ext/enterprise_script_service/msgpack/example/c/simple_c.c