summaryrefslogtreecommitdiff
path: root/cpp/vrefbuffer.c
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@users.sourceforge.jp>2010-05-25 02:57:37 +0900
committerfrsyuki <frsyuki@users.sourceforge.jp>2010-05-25 02:57:37 +0900
commitfc7da17fa2dbdc6385ad95f6848ee59598164440 (patch)
tree40f4d554925f7e6624a14d9adf5c860ee8717b99 /cpp/vrefbuffer.c
parentdbebe9771b276bd286b2ccdb8ac88dd17a83524c (diff)
downloadmsgpack-python-fc7da17fa2dbdc6385ad95f6848ee59598164440.tar.gz
cpp: add sbuffer::clear() and vrefbuffer::clear()
Diffstat (limited to 'cpp/vrefbuffer.c')
-rw-r--r--cpp/vrefbuffer.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/cpp/vrefbuffer.c b/cpp/vrefbuffer.c
index 136372f..a27b138 100644
--- a/cpp/vrefbuffer.c
+++ b/cpp/vrefbuffer.c
@@ -75,6 +75,25 @@ void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf)
free(vbuf->array);
}
+void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vbuf)
+{
+ msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head->next;
+ msgpack_vrefbuffer_chunk* n;
+ while(c != NULL) {
+ n = c->next;
+ free(c);
+ c = n;
+ }
+
+ msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
+ msgpack_vrefbuffer_chunk* chunk = ib->head;
+ chunk->next = NULL;
+ ib->free = vbuf->chunk_size;
+ ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
+
+ vbuf->tail = vbuf->array;
+}
+
int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
const char* buf, unsigned int len)
{