From 684bca203ad862f30558429081d1a27681fe4559 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 1 Jun 2010 07:15:58 +0900 Subject: cpp: adds msgpack_unpacker_next and msgpack_unpack_next --- cpp/src/msgpack/unpack.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'cpp/src/msgpack/unpack.h') diff --git a/cpp/src/msgpack/unpack.h b/cpp/src/msgpack/unpack.h index e17d0d8..1f43ab7 100644 --- a/cpp/src/msgpack/unpack.h +++ b/cpp/src/msgpack/unpack.h @@ -20,6 +20,15 @@ #include "msgpack/zone.h" #include "msgpack/object.h" +#include + +#ifndef MSGPACK_UNPACKER_INIT_BUFFER_SIZE +#define MSGPACK_UNPACKER_INIT_BUFFER_SIZE (64*1024) +#endif + +#ifndef MSGPACK_UNPACKER_RESERVE_SIZE +#define MSGPACK_UNPACKER_RESERVE_SIZE (32*1024) +#endif #ifdef __cplusplus extern "C" { @@ -37,6 +46,10 @@ typedef struct msgpack_unpacker { void* ctx; } msgpack_unpacker; +typedef struct msgpack_unpacked { + msgpack_zone* zone; + msgpack_object data; +} msgpack_unpacked; bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size); void msgpack_unpacker_destroy(msgpack_unpacker* mpac); @@ -49,6 +62,13 @@ static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac); static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac); static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size); +bool msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac); + +static inline void msgpack_unpacked_init(msgpack_unpacked* result); +static inline void msgpack_unpacked_destroy(msgpack_unpacked* result); + +static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result); + int msgpack_unpacker_execute(msgpack_unpacker* mpac); @@ -63,6 +83,9 @@ void msgpack_unpacker_reset(msgpack_unpacker* mpac); static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac); +bool msgpack_unpack_next(msgpack_unpacked* result, + const char* data, size_t len, size_t* off); + typedef enum { MSGPACK_UNPACK_SUCCESS = 2, @@ -73,7 +96,7 @@ typedef enum { 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); static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac); @@ -115,6 +138,31 @@ size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac) } +void msgpack_unpacked_init(msgpack_unpacked* result) +{ + memset(result, 0, sizeof(msgpack_unpacked)); +} + +void msgpack_unpacked_destroy(msgpack_unpacked* result) +{ + if(result->zone != NULL) { + msgpack_zone_free(result->zone); + result->zone = NULL; + memset(&result->data, 0, sizeof(msgpack_object)); + } +} + +msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result) +{ + if(result->zone != NULL) { + msgpack_zone* z = result->zone; + result->zone = NULL; + return z; + } + return NULL; +} + + #ifdef __cplusplus } #endif -- cgit v1.2.1 From 3d3af3284e3a5fd03395b6694fd745491509aa64 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Tue, 1 Jun 2010 08:43:30 +0900 Subject: cpp: adds Doxyfile --- cpp/src/msgpack/unpack.h | 117 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 103 insertions(+), 14 deletions(-) (limited to 'cpp/src/msgpack/unpack.h') diff --git a/cpp/src/msgpack/unpack.h b/cpp/src/msgpack/unpack.h index 1f43ab7..82698fc 100644 --- a/cpp/src/msgpack/unpack.h +++ b/cpp/src/msgpack/unpack.h @@ -22,19 +22,34 @@ #include "msgpack/object.h" #include -#ifndef MSGPACK_UNPACKER_INIT_BUFFER_SIZE -#define MSGPACK_UNPACKER_INIT_BUFFER_SIZE (64*1024) -#endif - -#ifndef MSGPACK_UNPACKER_RESERVE_SIZE -#define MSGPACK_UNPACKER_RESERVE_SIZE (32*1024) -#endif - #ifdef __cplusplus extern "C" { #endif +/** + * @defgroup msgpack_unpack Deserializer + * @ingroup msgpack + * @{ + */ + +typedef struct msgpack_unpacked { + msgpack_zone* zone; + msgpack_object data; +} msgpack_unpacked; + +bool msgpack_unpack_next(msgpack_unpacked* result, + const char* data, size_t len, size_t* off); + +/** @} */ + + +/** + * @defgroup msgpack_unpacker Streaming deserializer + * @ingroup msgpack + * @{ + */ + typedef struct msgpack_unpacker { char* buffer; size_t used; @@ -46,27 +61,100 @@ typedef struct msgpack_unpacker { void* ctx; } msgpack_unpacker; -typedef struct msgpack_unpacked { - msgpack_zone* zone; - msgpack_object data; -} msgpack_unpacked; +#ifndef MSGPACK_UNPACKER_INIT_BUFFER_SIZE +#define MSGPACK_UNPACKER_INIT_BUFFER_SIZE (64*1024) +#endif + +/** + * Initializes a streaming deserializer. + * The initialized deserializer must be destroyed by msgpack_unpacker_destroy(msgpack_unpacker*). + */ bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size); + +/** + * Destroys a streaming deserializer initialized by msgpack_unpacker_init(msgpack_unpacker*, size_t). + */ void msgpack_unpacker_destroy(msgpack_unpacker* mpac); + +/** + * Creates a streaming deserializer. + * The created deserializer must be destroyed by msgpack_unpacker_free(msgpack_unpacker*). + */ msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size); + +/** + * Frees a streaming deserializer created by msgpack_unpacker_new(size_t). + */ void msgpack_unpacker_free(msgpack_unpacker* mpac); + +#ifndef MSGPACK_UNPACKER_RESERVE_SIZE +#define MSGPACK_UNPACKER_RESERVE_SIZE (32*1024) +#endif + +/** + * Reserves free space of the internal buffer. + * Use this function to fill the internal buffer with + * msgpack_unpacker_buffer(msgpack_unpacker*), + * msgpack_unpacker_buffer_capacity(const msgpack_unpacker*) and + * msgpack_unpacker_buffer_consumed(msgpack_unpacker*). + */ static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size); + +/** + * Gets pointer to the free space of the internal buffer. + * Use this function to fill the internal buffer with + * msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t), + * msgpack_unpacker_buffer_capacity(const msgpack_unpacker*) and + * msgpack_unpacker_buffer_consumed(msgpack_unpacker*). + */ static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac); + +/** + * Gets size of the free space of the internal buffer. + * Use this function to fill the internal buffer with + * msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t), + * msgpack_unpacker_buffer(const msgpack_unpacker*) and + * msgpack_unpacker_buffer_consumed(msgpack_unpacker*). + */ static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac); + +/** + * Notifies the deserializer that the internal buffer filled. + * Use this function to fill the internal buffer with + * msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t), + * msgpack_unpacker_buffer(msgpack_unpacker*) and + * msgpack_unpacker_buffer_capacity(const msgpack_unpacker*). + */ static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size); + +/** + * Deserializes one object. + * Returns true if it successes. Otherwise false is returned. + * @param pac pointer to an initialized msgpack_unpacked object. + */ bool msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac); +/** + * Initializes a msgpack_unpacked object. + * The initialized object must be destroyed by msgpack_unpacked_destroy(msgpack_unpacker*). + * Use the object with msgpack_unpacker_next(msgpack_unpacker*, msgpack_unpacked*) or + * msgpack_unpack_next(msgpack_unpacked*, const char*, size_t, size_t*). + */ static inline void msgpack_unpacked_init(msgpack_unpacked* result); + +/** + * Destroys a streaming deserializer initialized by msgpack_unpacked(). + */ static inline void msgpack_unpacked_destroy(msgpack_unpacked* result); +/** + * Releases the memory zone from msgpack_unpacked object. + * The released zone must be freed by msgpack_zone_free(msgpack_zone*). + */ static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result); @@ -83,10 +171,10 @@ void msgpack_unpacker_reset(msgpack_unpacker* mpac); static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac); -bool msgpack_unpack_next(msgpack_unpacked* result, - const char* data, size_t len, size_t* off); +/** @} */ +// obsolete typedef enum { MSGPACK_UNPACK_SUCCESS = 2, MSGPACK_UNPACK_EXTRA_BYTES = 1, @@ -94,6 +182,7 @@ typedef enum { MSGPACK_UNPACK_PARSE_ERROR = -1, } msgpack_unpack_return; +// obsolete msgpack_unpack_return msgpack_unpack(const char* data, size_t len, size_t* off, msgpack_zone* result_zone, msgpack_object* result); -- cgit v1.2.1