Sha256: 50e30edb2e86bb2c5ca05d528cc542ac451dd6790ff54990a05defdafb9c9e84

Contents?: true

Size: 1.19 KB

Versions: 14

Compression:

Stored size: 1.19 KB

Contents

#include <msgpack.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)
{
    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

14 entries across 14 versions & 1 rubygems

Version Path
script_core-0.2.5 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.2.4 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.2.3 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.2.2 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.2.1 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.2.0 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.1.1 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.1.0 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.0.6 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.0.5 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.0.4 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.0.3 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.0.2 ext/enterprise_script_service/msgpack/example/c/simple_c.c
script_core-0.0.1 ext/enterprise_script_service/msgpack/example/c/simple_c.c