mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 02:09:59 +00:00
remove msgpack_unpacker_buffered_size, add msgpack_unpacker_parsed_size
This commit is contained in:
parent
8893523776
commit
5697b9a15d
5 changed files with 26 additions and 19 deletions
12
c/unpack.c
12
c/unpack.c
|
|
@ -197,6 +197,7 @@ bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size)
|
|||
mpac->used = COUNTER_SIZE;
|
||||
mpac->free = initial_buffer_size - mpac->used;
|
||||
mpac->off = COUNTER_SIZE;
|
||||
mpac->parsed = 0;
|
||||
mpac->initial_buffer_size = initial_buffer_size;
|
||||
mpac->z = z;
|
||||
mpac->referenced = false;
|
||||
|
|
@ -305,8 +306,13 @@ bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size)
|
|||
|
||||
int msgpack_unpacker_execute(msgpack_unpacker* mpac)
|
||||
{
|
||||
return template_execute(CTX_CAST(mpac->ctx),
|
||||
size_t off = mpac->off;
|
||||
int ret = template_execute(CTX_CAST(mpac->ctx),
|
||||
mpac->buf, mpac->used, &mpac->off);
|
||||
if(mpac->off > off) {
|
||||
mpac->parsed += mpac->off - off;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac)
|
||||
|
|
@ -347,10 +353,8 @@ bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac)
|
|||
|
||||
void msgpack_unpacker_reset(msgpack_unpacker* mpac)
|
||||
{
|
||||
msgpack_zone* z = mpac->z;
|
||||
template_init(CTX_CAST(mpac->ctx));
|
||||
CTX_CAST(mpac->ctx)->user.z = z;
|
||||
CTX_CAST(mpac->ctx)->user.referenced = &mpac->referenced;
|
||||
mpac->parsed = 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
14
c/unpack.h
14
c/unpack.h
|
|
@ -33,6 +33,7 @@ typedef struct msgpack_unpacker {
|
|||
size_t used;
|
||||
size_t free;
|
||||
size_t off;
|
||||
size_t parsed;
|
||||
msgpack_zone* z;
|
||||
bool referenced;
|
||||
size_t initial_buffer_size;
|
||||
|
|
@ -46,7 +47,6 @@ void msgpack_unpacker_destroy(msgpack_unpacker* mpac);
|
|||
msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size);
|
||||
void msgpack_unpacker_free(msgpack_unpacker* mpac);
|
||||
|
||||
static inline size_t msgpack_unpacker_buffered_size(const msgpack_unpacker* mpac);
|
||||
static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size);
|
||||
static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac);
|
||||
static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac);
|
||||
|
|
@ -61,6 +61,8 @@ msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac);
|
|||
|
||||
void msgpack_unpacker_reset(msgpack_unpacker* mpac);
|
||||
|
||||
static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac);
|
||||
|
||||
|
||||
typedef enum {
|
||||
MSGPACK_UNPACK_SUCCESS = 2,
|
||||
|
|
@ -78,11 +80,6 @@ bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac);
|
|||
|
||||
bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size);
|
||||
|
||||
size_t msgpack_unpacker_buffered_size(const msgpack_unpacker* mpac)
|
||||
{
|
||||
return mpac->used;
|
||||
}
|
||||
|
||||
bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size)
|
||||
{
|
||||
if(mpac->free >= size) { return true; }
|
||||
|
|
@ -105,6 +102,11 @@ void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size)
|
|||
mpac->free -= size;
|
||||
}
|
||||
|
||||
size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac)
|
||||
{
|
||||
return mpac->parsed;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue