Lines Matching refs:zbuf

48     msgpack_zbuffer* zbuf, int level, size_t init_size);
49 static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf);
52 static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf);
54 static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf);
56 static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf);
57 static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf);
59 static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf);
60 static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf);
61 static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf);
70 static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf);
73 static inline bool msgpack_zbuffer_init(msgpack_zbuffer* zbuf, in msgpack_zbuffer_init() argument
76 memset(zbuf, 0, sizeof(msgpack_zbuffer)); in msgpack_zbuffer_init()
77 zbuf->init_size = init_size; in msgpack_zbuffer_init()
78 if(deflateInit(&zbuf->stream, level) != Z_OK) { in msgpack_zbuffer_init()
79 free(zbuf->data); in msgpack_zbuffer_init()
85 static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf) in msgpack_zbuffer_destroy() argument
87 deflateEnd(&zbuf->stream); in msgpack_zbuffer_destroy()
88 free(zbuf->data); in msgpack_zbuffer_destroy()
93 msgpack_zbuffer* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer)); in msgpack_zbuffer_new() local
94 if (zbuf == NULL) return NULL; in msgpack_zbuffer_new()
95 if(!msgpack_zbuffer_init(zbuf, level, init_size)) { in msgpack_zbuffer_new()
96 free(zbuf); in msgpack_zbuffer_new()
99 return zbuf; in msgpack_zbuffer_new()
102 static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf) in msgpack_zbuffer_free() argument
104 if(zbuf == NULL) { return; } in msgpack_zbuffer_free()
105 msgpack_zbuffer_destroy(zbuf); in msgpack_zbuffer_free()
106 free(zbuf); in msgpack_zbuffer_free()
109 static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf) in msgpack_zbuffer_expand() argument
111 size_t used = (char*)zbuf->stream.next_out - zbuf->data; in msgpack_zbuffer_expand()
112 size_t csize = used + zbuf->stream.avail_out; in msgpack_zbuffer_expand()
113 size_t nsize = (csize == 0) ? zbuf->init_size : csize * 2; in msgpack_zbuffer_expand()
115 char* tmp = (char*)realloc(zbuf->data, nsize); in msgpack_zbuffer_expand()
120 zbuf->data = tmp; in msgpack_zbuffer_expand()
121 zbuf->stream.next_out = (Bytef*)(tmp + used); in msgpack_zbuffer_expand()
122 zbuf->stream.avail_out = nsize - used; in msgpack_zbuffer_expand()
129 msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data; in msgpack_zbuffer_write() local
131 zbuf->stream.next_in = (Bytef*)buf; in msgpack_zbuffer_write()
132 zbuf->stream.avail_in = len; in msgpack_zbuffer_write()
134 while(zbuf->stream.avail_in > 0) { in msgpack_zbuffer_write()
135 if(zbuf->stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) { in msgpack_zbuffer_write()
136 if(!msgpack_zbuffer_expand(zbuf)) { in msgpack_zbuffer_write()
141 if(deflate(&zbuf->stream, Z_NO_FLUSH) != Z_OK) { in msgpack_zbuffer_write()
149 static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf) in msgpack_zbuffer_flush() argument
152 switch(deflate(&zbuf->stream, Z_FINISH)) { in msgpack_zbuffer_flush()
154 return zbuf->data; in msgpack_zbuffer_flush()
156 if(!msgpack_zbuffer_expand(zbuf)) { in msgpack_zbuffer_flush()
166 static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf) in msgpack_zbuffer_data() argument
168 return zbuf->data; in msgpack_zbuffer_data()
171 static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf) in msgpack_zbuffer_size() argument
173 return (char*)zbuf->stream.next_out - zbuf->data; in msgpack_zbuffer_size()
176 static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf) in msgpack_zbuffer_reset_buffer() argument
178 zbuf->stream.avail_out += (char*)zbuf->stream.next_out - zbuf->data; in msgpack_zbuffer_reset_buffer()
179 zbuf->stream.next_out = (Bytef*)zbuf->data; in msgpack_zbuffer_reset_buffer()
182 static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf) in msgpack_zbuffer_reset() argument
184 if(deflateReset(&zbuf->stream) != Z_OK) { in msgpack_zbuffer_reset()
187 msgpack_zbuffer_reset_buffer(zbuf); in msgpack_zbuffer_reset()
191 static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf) in msgpack_zbuffer_release_buffer() argument
193 char* tmp = zbuf->data; in msgpack_zbuffer_release_buffer()
194 zbuf->data = NULL; in msgpack_zbuffer_release_buffer()
195 zbuf->stream.next_out = NULL; in msgpack_zbuffer_release_buffer()
196 zbuf->stream.avail_out = 0; in msgpack_zbuffer_release_buffer()