mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-19 04:33:27 +02:00
unpack: new msgpack_unpacker_next_with_size() function
This new function is an extension of the original msgpack_unpacker_next() where it now adds third argument to store the number of parsed bytes for the returned buffer upon a MSGPACK_UNPACK_SUCCESS case. This is useful for cases where the caller needs to optimize memory usage in the original buffer,s so upon success retrieval of the object, it can later deprecate the already 'parsed' bytes. For more details about the origins of this function please refer to the following issue on github: https://github.com/msgpack/msgpack-c/issues/514 Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
This commit is contained in:
31
src/unpack.c
31
src/unpack.c
@@ -510,7 +510,8 @@ void msgpack_unpacker_reset(msgpack_unpacker* mpac)
|
||||
mpac->parsed = 0;
|
||||
}
|
||||
|
||||
msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* result)
|
||||
static inline msgpack_unpack_return unpacker_next(msgpack_unpacker* mpac,
|
||||
msgpack_unpacked* result)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -529,11 +530,37 @@ msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpa
|
||||
}
|
||||
result->zone = msgpack_unpacker_release_zone(mpac);
|
||||
result->data = msgpack_unpacker_data(mpac);
|
||||
msgpack_unpacker_reset(mpac);
|
||||
|
||||
return MSGPACK_UNPACK_SUCCESS;
|
||||
}
|
||||
|
||||
msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac,
|
||||
msgpack_unpacked* result)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = unpacker_next(mpac, result);
|
||||
if (ret == MSGPACK_UNPACK_SUCCESS) {
|
||||
msgpack_unpacker_reset(mpac);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
msgpack_unpack_return
|
||||
msgpack_unpacker_next_with_size(msgpack_unpacker* mpac,
|
||||
msgpack_unpacked* result, size_t *p_bytes)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = unpacker_next(mpac, result);
|
||||
if (ret == MSGPACK_UNPACK_SUCCESS) {
|
||||
*p_bytes = mpac->parsed;
|
||||
msgpack_unpacker_reset(mpac);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
msgpack_unpack_return
|
||||
msgpack_unpack(const char* data, size_t len, size_t* off,
|
||||
|
Reference in New Issue
Block a user