diff options
| author | UENISHI Kota <kuenishi+github@gmail.com> | 2010-06-03 00:14:19 +0900 |
|---|---|---|
| committer | UENISHI Kota <kuenishi+github@gmail.com> | 2010-06-03 00:14:19 +0900 |
| commit | 8ecaf7ad4ce4185e81fae775332282ed551fa886 (patch) | |
| tree | 68b7fb5c875f5620033ac8fa4e046bfdd51f78d0 /cpp/src/unpack.c | |
| parent | 49f3872d047624b1995b8c60edec8bad35429fd3 (diff) | |
| parent | d4049fe593ae4465e7a258d138c2166571a0f1a7 (diff) | |
| download | msgpack-python-8ecaf7ad4ce4185e81fae775332282ed551fa886.tar.gz | |
Merge branch 'master' of ssh://github.com/msgpack/msgpack
Diffstat (limited to 'cpp/src/unpack.c')
| -rw-r--r-- | cpp/src/unpack.c | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/cpp/src/unpack.c b/cpp/src/unpack.c index 4a42526..0c21780 100644 --- a/cpp/src/unpack.c +++ b/cpp/src/unpack.c @@ -363,20 +363,46 @@ void msgpack_unpacker_reset(msgpack_unpacker* mpac) mpac->parsed = 0; } +bool msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* result) +{ + if(result->zone != NULL) { + msgpack_zone_free(result->zone); + } + + int ret = msgpack_unpacker_execute(mpac); + + if(ret <= 0) { + result->zone = NULL; + memset(&result->data, 0, sizeof(msgpack_object)); + return false; + } + + result->zone = msgpack_unpacker_release_zone(mpac); + result->data = msgpack_unpacker_data(mpac); + msgpack_unpacker_reset(mpac); + + return true; +} + msgpack_unpack_return msgpack_unpack(const char* data, size_t len, size_t* off, - msgpack_zone* z, msgpack_object* result) + 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 = z; + ctx.user.z = result_zone; ctx.user.referenced = false; - size_t noff = 0; - if(off != NULL) { noff = *off; } - int e = template_execute(&ctx, data, len, &noff); if(e < 0) { return MSGPACK_UNPACK_PARSE_ERROR; @@ -397,3 +423,37 @@ msgpack_unpack(const char* data, size_t len, size_t* off, return MSGPACK_UNPACK_SUCCESS; } +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; +} + |
