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; }
int msgpack_unpacker_execute(msgpack_unpacker* mpac) { size_t off = mpac->off; int ret = template_execute(CTX_CAST(mpac->ctx), mpac->buffer, mpac->used, &mpac->off); if(mpac->off > off) { mpac->parsed += mpac->off - off; } return ret; }
static VALUE template_execute_do(VALUE argv) { VALUE* args = (VALUE*)argv; msgpack_unpack_t* mp = (msgpack_unpack_t*)args[0]; char* dptr = (char*)args[1]; size_t dlen = (size_t)args[2]; size_t* from = (size_t*)args[3]; int ret = template_execute(mp, dptr, dlen, from); return (VALUE)ret; }
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; } }
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; }