mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-19 12:42:31 +02:00
Added examples for the following updated functions: msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* result); msgpack_unpack_return msgpack_unpack_next(msgpack_unpacked* result, const char* data, size_t len, size_t* off);
This commit is contained in:
44
src/unpack.c
44
src/unpack.c
@@ -390,25 +390,24 @@ void msgpack_unpacker_reset(msgpack_unpacker* mpac)
|
||||
mpac->parsed = 0;
|
||||
}
|
||||
|
||||
bool msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* result)
|
||||
msgpack_unpack_return 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) {
|
||||
if(ret < 0) {
|
||||
result->zone = NULL;
|
||||
memset(&result->data, 0, sizeof(msgpack_object));
|
||||
return false;
|
||||
return MSGPACK_UNPACK_PARSE_ERROR;
|
||||
}
|
||||
|
||||
if(ret == 0) {
|
||||
return MSGPACK_UNPACK_CONTINUE;
|
||||
}
|
||||
result->zone = msgpack_unpacker_release_zone(mpac);
|
||||
result->data = msgpack_unpacker_data(mpac);
|
||||
msgpack_unpacker_reset(mpac);
|
||||
|
||||
return true;
|
||||
return MSGPACK_UNPACK_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +449,8 @@ msgpack_unpack(const char* data, size_t len, size_t* off,
|
||||
return MSGPACK_UNPACK_SUCCESS;
|
||||
}
|
||||
|
||||
bool msgpack_unpack_next(msgpack_unpacked* result,
|
||||
msgpack_unpack_return
|
||||
msgpack_unpack_next(msgpack_unpacked* result,
|
||||
const char* data, size_t len, size_t* off)
|
||||
{
|
||||
msgpack_unpacked_destroy(result);
|
||||
@@ -459,29 +459,39 @@ bool msgpack_unpack_next(msgpack_unpacked* result,
|
||||
if(off != NULL) { noff = *off; }
|
||||
|
||||
if(len <= noff) {
|
||||
return false;
|
||||
return MSGPACK_UNPACK_CONTINUE;
|
||||
}
|
||||
|
||||
msgpack_zone* z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
|
||||
if (!result->zone) {
|
||||
result->zone = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
if (!result->zone) {
|
||||
return MSGPACK_UNPACK_NOMEM_ERROR;
|
||||
}
|
||||
|
||||
template_context ctx;
|
||||
template_init(&ctx);
|
||||
|
||||
ctx.user.z = z;
|
||||
ctx.user.z = result->zone;
|
||||
ctx.user.referenced = false;
|
||||
|
||||
int e = template_execute(&ctx, data, len, &noff);
|
||||
if(e <= 0) {
|
||||
msgpack_zone_free(z);
|
||||
return false;
|
||||
if(e < 0) {
|
||||
msgpack_zone_free(result->zone);
|
||||
result->zone = NULL;
|
||||
return MSGPACK_UNPACK_PARSE_ERROR;
|
||||
}
|
||||
|
||||
if(off != NULL) { *off = noff; }
|
||||
|
||||
result->zone = z;
|
||||
if(e == 0) {
|
||||
return MSGPACK_UNPACK_CONTINUE;
|
||||
}
|
||||
|
||||
result->data = template_data(&ctx);
|
||||
|
||||
return true;
|
||||
return MSGPACK_UNPACK_SUCCESS;
|
||||
}
|
||||
|
||||
#if defined(MSGPACK_OLD_COMPILER_BUS_ERROR_WORKAROUND)
|
||||
|
Reference in New Issue
Block a user