Lines Matching refs:zbuf

40     msgpack_zbuffer* zbuf, int level, size_t init_size);
41 static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf);
44 static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf);
46 static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf);
48 static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf);
49 static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf);
51 static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf);
52 static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf);
53 static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf);
62 static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf);
65 static inline bool msgpack_zbuffer_init(msgpack_zbuffer* zbuf, in msgpack_zbuffer_init() argument
68 memset(zbuf, 0, sizeof(msgpack_zbuffer)); in msgpack_zbuffer_init()
69 zbuf->init_size = init_size; in msgpack_zbuffer_init()
70 if(deflateInit(&zbuf->stream, level) != Z_OK) { in msgpack_zbuffer_init()
71 free(zbuf->data); in msgpack_zbuffer_init()
77 static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf) in msgpack_zbuffer_destroy() argument
79 deflateEnd(&zbuf->stream); in msgpack_zbuffer_destroy()
80 free(zbuf->data); in msgpack_zbuffer_destroy()
85 msgpack_zbuffer* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer)); in msgpack_zbuffer_new() local
86 if (zbuf == NULL) return NULL; in msgpack_zbuffer_new()
87 if(!msgpack_zbuffer_init(zbuf, level, init_size)) { in msgpack_zbuffer_new()
88 free(zbuf); in msgpack_zbuffer_new()
91 return zbuf; in msgpack_zbuffer_new()
94 static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf) in msgpack_zbuffer_free() argument
96 if(zbuf == NULL) { return; } in msgpack_zbuffer_free()
97 msgpack_zbuffer_destroy(zbuf); in msgpack_zbuffer_free()
98 free(zbuf); in msgpack_zbuffer_free()
101 static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf) in msgpack_zbuffer_expand() argument
103 size_t used = (char*)zbuf->stream.next_out - zbuf->data; in msgpack_zbuffer_expand()
104 size_t csize = used + zbuf->stream.avail_out; in msgpack_zbuffer_expand()
105 size_t nsize = (csize == 0) ? zbuf->init_size : csize * 2; in msgpack_zbuffer_expand()
107 char* tmp = (char*)realloc(zbuf->data, nsize); in msgpack_zbuffer_expand()
112 zbuf->data = tmp; in msgpack_zbuffer_expand()
113 zbuf->stream.next_out = (Bytef*)(tmp + used); in msgpack_zbuffer_expand()
114 zbuf->stream.avail_out = nsize - used; in msgpack_zbuffer_expand()
121 msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data; in msgpack_zbuffer_write() local
123 zbuf->stream.next_in = (Bytef*)buf; in msgpack_zbuffer_write()
124 zbuf->stream.avail_in = len; in msgpack_zbuffer_write()
126 while(zbuf->stream.avail_in > 0) { in msgpack_zbuffer_write()
127 if(zbuf->stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) { in msgpack_zbuffer_write()
128 if(!msgpack_zbuffer_expand(zbuf)) { in msgpack_zbuffer_write()
133 if(deflate(&zbuf->stream, Z_NO_FLUSH) != Z_OK) { in msgpack_zbuffer_write()
141 static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf) in msgpack_zbuffer_flush() argument
144 switch(deflate(&zbuf->stream, Z_FINISH)) { in msgpack_zbuffer_flush()
146 return zbuf->data; in msgpack_zbuffer_flush()
148 if(!msgpack_zbuffer_expand(zbuf)) { in msgpack_zbuffer_flush()
158 static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf) in msgpack_zbuffer_data() argument
160 return zbuf->data; in msgpack_zbuffer_data()
163 static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf) in msgpack_zbuffer_size() argument
165 return (char*)zbuf->stream.next_out - zbuf->data; in msgpack_zbuffer_size()
168 static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf) in msgpack_zbuffer_reset_buffer() argument
170 zbuf->stream.avail_out += (char*)zbuf->stream.next_out - zbuf->data; in msgpack_zbuffer_reset_buffer()
171 zbuf->stream.next_out = (Bytef*)zbuf->data; in msgpack_zbuffer_reset_buffer()
174 static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf) in msgpack_zbuffer_reset() argument
176 if(deflateReset(&zbuf->stream) != Z_OK) { in msgpack_zbuffer_reset()
179 msgpack_zbuffer_reset_buffer(zbuf); in msgpack_zbuffer_reset()
183 static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf) in msgpack_zbuffer_release_buffer() argument
185 char* tmp = zbuf->data; in msgpack_zbuffer_release_buffer()
186 zbuf->data = NULL; in msgpack_zbuffer_release_buffer()
187 zbuf->stream.next_out = NULL; in msgpack_zbuffer_release_buffer()
188 zbuf->stream.avail_out = 0; in msgpack_zbuffer_release_buffer()