Exemplo n.º 1
0
bool msgpack_unpack_next(msgpack_unpacked* result,
		const char* data, size_t len, size_t* off)
{
	msgpack_unpacked_destroy(result);

	size_t noff = 0;
	if(off != NULL) { noff = *off; }

	if(len <= noff) {
		return false;
	}

	msgpack_zone* z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);

	template_context ctx;
	template_init(&ctx);

	ctx.user.z = z;
	ctx.user.referenced = false;

	int e = template_execute(&ctx, data, len, &noff);
	if(e <= 0) {
		msgpack_zone_free(z);
		return false;
	}

	if(off != NULL) { *off = noff; }

	result->zone = z;
	result->data = template_data(&ctx);

	return true;
}
Exemplo n.º 2
0
static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
{
	unsigned int i;
	rb_gc_mark(mp->user.stream);
	rb_gc_mark(mp->user.streambuf);
	rb_gc_mark_maybe(template_data(mp));
	for(i=0; i < mp->top; ++i) {
		rb_gc_mark(mp->stack[i].obj);
		rb_gc_mark_maybe(mp->stack[i].map_key);
	}
}
Exemplo n.º 3
0
msgpack_unpack_return
msgpack_unpack_next(msgpack_unpacked* result,
        const char* data, size_t len, size_t* off)
{
    size_t noff = 0;
    msgpack_unpacked_destroy(result);

    if(off != NULL) { noff = *off; }

    if(len <= noff) {
        return MSGPACK_UNPACK_CONTINUE;
    }

    if (!result->zone) {
        result->zone = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
    }

    if (!result->zone) {
        return MSGPACK_UNPACK_NOMEM_ERROR;
    }
    else {
        int e;
        template_context ctx;
        template_init(&ctx);

        ctx.user.z = result->zone;
        ctx.user.referenced = false;

        e = template_execute(&ctx, data, len, &noff);
        if(e < 0) {
            msgpack_zone_free(result->zone);
            result->zone = NULL;
            return MSGPACK_UNPACK_PARSE_ERROR;
        }


        if(e == 0) {
            return MSGPACK_UNPACK_CONTINUE;
        }

        if(off != NULL) { *off = noff; }

        result->data = template_data(&ctx);

        return MSGPACK_UNPACK_SUCCESS;
    }
}
Exemplo n.º 4
0
msgpack_unpack_return
msgpack_unpack(const char* data, size_t len, size_t* off,
               msgpack_zone* result_zone, msgpack_object* result)
{
    size_t noff = 0;
    if(off != NULL) {
        noff = *off;
    }

    if(len <= noff) {
        // FIXME
        return MSGPACK_UNPACK_CONTINUE;
    }

    template_context ctx;
    template_init(&ctx);

    ctx.user.z = result_zone;
    ctx.user.referenced = false;

    int e = template_execute(&ctx, data, len, &noff);
    if(e < 0) {
        return MSGPACK_UNPACK_PARSE_ERROR;
    }

    if(off != NULL) {
        *off = noff;
    }

    if(e == 0) {
        return MSGPACK_UNPACK_CONTINUE;
    }

    *result = template_data(&ctx);

    if(noff < len) {
        return MSGPACK_UNPACK_EXTRA_BYTES;
    }

    return MSGPACK_UNPACK_SUCCESS;
}
Exemplo n.º 5
0
msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac)
{
    return template_data(CTX_CAST(mpac->ctx));
}