diff options
| author | frsyuki <frsyuki@users.sourceforge.jp> | 2010-06-01 07:11:01 +0900 |
|---|---|---|
| committer | frsyuki <frsyuki@users.sourceforge.jp> | 2010-06-01 07:11:01 +0900 |
| commit | 5a92c861e377c7db3b240dd3661feed0b58f85e0 (patch) | |
| tree | cf7ae691309e143c3252f7a6c1fa688dd11a5795 /cpp/src/msgpack/vrefbuffer.h | |
| parent | 103b14ea3c8a3f72213295d975328dc2399725eb (diff) | |
| download | msgpack-python-5a92c861e377c7db3b240dd3661feed0b58f85e0.tar.gz | |
cpp: adds msgpack_vrefbuffer_new and msgpack_vrefbuffer_free
Diffstat (limited to 'cpp/src/msgpack/vrefbuffer.h')
| -rw-r--r-- | cpp/src/msgpack/vrefbuffer.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/cpp/src/msgpack/vrefbuffer.h b/cpp/src/msgpack/vrefbuffer.h index a08e0d0..ffb2302 100644 --- a/cpp/src/msgpack/vrefbuffer.h +++ b/cpp/src/msgpack/vrefbuffer.h @@ -19,6 +19,7 @@ #define MSGPACK_VREFBUFFER_H__ #include "msgpack/zone.h" +#include <stdlib.h> #ifndef _WIN32 #include <sys/uio.h> @@ -67,6 +68,9 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf, size_t ref_size, size_t chunk_size); void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf); +static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size); +static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf); + static inline int msgpack_vrefbuffer_write(void* data, const char* buf, unsigned int len); static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref); @@ -83,6 +87,23 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to) void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vref); +msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size) +{ + msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)malloc(sizeof(msgpack_vrefbuffer)); + if(!msgpack_vrefbuffer_init(vbuf, ref_size, chunk_size)) { + free(vbuf); + return NULL; + } + return vbuf; +} + +void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf) +{ + if(vbuf == NULL) { return; } + msgpack_vrefbuffer_destroy(vbuf); + free(vbuf); +} + int msgpack_vrefbuffer_write(void* data, const char* buf, unsigned int len) { msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)data; |
