diff --git a/include/msgpack/unpack.h b/include/msgpack/unpack.h index 0f9aede2..036d575e 100644 --- a/include/msgpack/unpack.h +++ b/include/msgpack/unpack.h @@ -146,6 +146,18 @@ static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, si MSGPACK_DLLEXPORT msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac); +/** + * Deserializes one object and set the number of parsed bytes involved. + * Returns true if it successes. Otherwise false is returned. + * @param mpac pointer to an initialized msgpack_unpacker object. + * @param result pointer to an initialized msgpack_unpacked object. + * @param p_bytes pointer to variable that will be set with the number of parsed bytes. + */ +MSGPACK_DLLEXPORT +msgpack_unpack_return msgpack_unpacker_next_with_size(msgpack_unpacker* mpac, + msgpack_unpacked* result, + size_t *p_bytes); + /** * Initializes a msgpack_unpacked object. * The initialized object must be destroyed by msgpack_unpacked_destroy(msgpack_unpacker*). @@ -267,4 +279,3 @@ static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* resu #endif #endif /* msgpack/unpack.h */ - diff --git a/src/unpack.c b/src/unpack.c index 1bfcebbc..882b0b2c 100644 --- a/src/unpack.c +++ b/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,