aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-13 10:09:45 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-10-13 10:09:45 +0300
commit4d4fde41b23815719f8c59e27832e29766c35bf0 (patch)
treeaaa08a10304354f7a4ff8d69c4b5924ef6e84f61
parent6abc995ed0ac0349b8451cfe883d5296da341c66 (diff)
downloadvmod-binlog-4d4fde41b23815719f8c59e27832e29766c35bf0.tar.gz
vmod-binlog-4d4fde41b23815719f8c59e27832e29766c35bf0.tar.bz2
Simplify packer API
* src/pack.c (packspec) <size>: Remove <packer,unpacker>: kick off struct packspec from the arglist. All uses updated.
-rw-r--r--src/pack.c131
1 files changed, 65 insertions, 66 deletions
diff --git a/src/pack.c b/src/pack.c
index 2e7e7a6..701d82a 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -59,10 +59,9 @@
59 59
60struct packspec { 60struct packspec {
61 int ch; 61 int ch;
62 size_t size;
63 int flags; 62 int flags;
64 void (*packer)(struct packenv *, struct packspec *, int); 63 void (*packer)(struct packenv *, int);
65 void (*unpacker)(struct packenv *, struct packspec *, int); 64 void (*unpacker)(struct packenv *, int);
66}; 65};
67 66
68struct packinst { 67struct packinst {
@@ -177,7 +176,7 @@ getsnum(char *s, intmax_t minval, intmax_t maxval, intmax_t *retval)
177 176
178 177
179static void 178static void
180Z_packer(struct packenv *env, struct packspec *spec, int rep) 179Z_packer(struct packenv *env, int rep)
181{ 180{
182 if (env->buf_base) { 181 if (env->buf_base) {
183 char *arg = packenv_get(env); 182 char *arg = packenv_get(env);
@@ -194,14 +193,14 @@ Z_packer(struct packenv *env, struct packspec *spec, int rep)
194} 193}
195 194
196static void 195static void
197Z_unpacker(struct packenv *env, struct packspec *spec, int rep) 196Z_unpacker(struct packenv *env, int rep)
198{ 197{
199 fprintf(env->fp, "%-*.*s", rep, rep, env->buf_base + env->buf_pos); 198 fprintf(env->fp, "%-*.*s", rep, rep, env->buf_base + env->buf_pos);
200 env->buf_pos += rep; 199 env->buf_pos += rep;
201} 200}
202 201
203static void 202static void
204c_packer(struct packenv *env, struct packspec *spec, int rep) 203c_packer(struct packenv *env, int rep)
205{ 204{
206 if (env->buf_base) { 205 if (env->buf_base) {
207 char *arg = packenv_get(env); 206 char *arg = packenv_get(env);
@@ -212,125 +211,125 @@ c_packer(struct packenv *env, struct packspec *spec, int rep)
212} 211}
213 212
214static void 213static void
215c_unpacker(struct packenv *env, struct packspec *spec, int rep) 214c_unpacker(struct packenv *env, int rep)
216{ 215{
217 fprintf(env->fp, "%c", env->buf_base[env->buf_pos++]); 216 fprintf(env->fp, "%c", env->buf_base[env->buf_pos++]);
218} 217}
219 218
220static void 219static void
221s_packer(struct packenv *env, struct packspec *spec, int rep) 220s_packer(struct packenv *env, int rep)
222{ 221{
223 GETSARG(env, int16_t, INT16_MIN, INT16_MAX); 222 GETSARG(env, int16_t, INT16_MIN, INT16_MAX);
224 env->buf_pos += spec->size; 223 env->buf_pos += sizeof(int16_t);
225} 224}
226 225
227static void 226static void
228s_unpacker(struct packenv *env, struct packspec *spec, int rep) 227s_unpacker(struct packenv *env, int rep)
229{ 228{
230 printsnum(env->fp, *(int16_t *) (env->buf_base + env->buf_pos)); 229 printsnum(env->fp, *(int16_t *) (env->buf_base + env->buf_pos));
231 env->buf_pos += spec->size; 230 env->buf_pos += sizeof(int16_t);
232} 231}
233 232
234static void 233static void
235S_packer(struct packenv *env, struct packspec *spec, int rep) 234S_packer(struct packenv *env, int rep)
236{ 235{
237 GETUARG(env, uint16_t, UINT16_MAX); 236 GETUARG(env, uint16_t, UINT16_MAX);
238 env->buf_pos += spec->size; 237 env->buf_pos += sizeof(uint16_t);
239} 238}
240 239
241static void 240static void
242S_unpacker(struct packenv *env, struct packspec *spec, int rep) 241S_unpacker(struct packenv *env, int rep)
243{ 242{
244 printunum(env->fp, *(uint16_t *)(env->buf_base + env->buf_pos)); 243 printunum(env->fp, *(uint16_t *)(env->buf_base + env->buf_pos));
245 env->buf_pos += spec->size; 244 env->buf_pos += sizeof(uint16_t);
246} 245}
247 246
248static void 247static void
249l_packer(struct packenv *env, struct packspec *spec, int rep) 248l_packer(struct packenv *env, int rep)
250{ 249{
251 GETSARG(env, int32_t, INT32_MIN, INT32_MAX); 250 GETSARG(env, int32_t, INT32_MIN, INT32_MAX);
252 env->buf_pos += spec->size; 251 env->buf_pos += sizeof(int32_t);
253} 252}
254 253
255static void 254static void
256l_unpacker(struct packenv *env, struct packspec *spec, int rep) 255l_unpacker(struct packenv *env, int rep)
257{ 256{
258 printsnum(env->fp, *(int32_t *)(env->buf_base + env->buf_pos)); 257 printsnum(env->fp, *(int32_t *)(env->buf_base + env->buf_pos));
259 env->buf_pos += spec->size; 258 env->buf_pos += sizeof(int32_t);
260} 259}
261 260
262static void 261static void
263L_packer(struct packenv *env, struct packspec *spec, int rep) 262L_packer(struct packenv *env, int rep)
264{ 263{
265 GETUARG(env, uint32_t, UINT32_MAX); 264 GETUARG(env, uint32_t, UINT32_MAX);
266 env->buf_pos += spec->size; 265 env->buf_pos += sizeof(uint32_t);
267} 266}
268 267
269static void 268static void
270L_unpacker(struct packenv *env, struct packspec *spec, int rep) 269L_unpacker(struct packenv *env, int rep)
271{ 270{
272 printunum(env->fp, *(uint32_t *)(env->buf_base + env->buf_pos)); 271 printunum(env->fp, *(uint32_t *)(env->buf_base + env->buf_pos));
273 env->buf_pos += spec->size; 272 env->buf_pos += sizeof(uint32_t);
274} 273}
275 274
276static void 275static void
277q_packer(struct packenv *env, struct packspec *spec, int rep) 276q_packer(struct packenv *env, int rep)
278{ 277{
279 GETSARG(env, int64_t, INT64_MIN, INT64_MAX); 278 GETSARG(env, int64_t, INT64_MIN, INT64_MAX);
280 env->buf_pos += spec->size; 279 env->buf_pos += sizeof(int64_t);
281} 280}
282 281
283static void 282static void
284q_unpacker(struct packenv *env, struct packspec *spec, int rep) 283q_unpacker(struct packenv *env, int rep)
285{ 284{
286 printsnum(env->fp, *(int64_t *)(env->buf_base + env->buf_pos)); 285 printsnum(env->fp, *(int64_t *)(env->buf_base + env->buf_pos));
287 env->buf_pos += spec->size; 286 env->buf_pos += sizeof(int64_t);
288} 287}
289 288
290static void 289static void
291Q_packer(struct packenv *env, struct packspec *spec, int rep) 290Q_packer(struct packenv *env, int rep)
292{ 291{
293 GETUARG(env, uint64_t, UINT64_MAX); 292 GETUARG(env, uint64_t, UINT64_MAX);
294 env->buf_pos += spec->size; 293 env->buf_pos += sizeof(uint64_t);
295} 294}
296 295
297static void 296static void
298Q_unpacker(struct packenv *env, struct packspec *spec, int rep) 297Q_unpacker(struct packenv *env, int rep)
299{ 298{
300 printunum(env->fp, *(uint64_t *)(env->buf_base + env->buf_pos)); 299 printunum(env->fp, *(uint64_t *)(env->buf_base + env->buf_pos));
301 env->buf_pos += spec->size; 300 env->buf_pos += sizeof(uint64_t);
302} 301}
303 302
304static void 303static void
305i_packer(struct packenv *env, struct packspec *spec, int rep) 304i_packer(struct packenv *env, int rep)
306{ 305{
307 GETSARG(env, int, INT_MIN, INT_MAX); 306 GETSARG(env, int, INT_MIN, INT_MAX);
308 env->buf_pos += spec->size; 307 env->buf_pos += sizeof(int);
309} 308}
310 309
311static void 310static void
312i_unpacker(struct packenv *env, struct packspec *spec, int rep) 311i_unpacker(struct packenv *env, int rep)
313{ 312{
314 printsnum(env->fp, *(int *)(env->buf_base + env->buf_pos)); 313 printsnum(env->fp, *(int *)(env->buf_base + env->buf_pos));
315 env->buf_pos += spec->size; 314 env->buf_pos += sizeof(int);
316} 315}
317 316
318static void 317static void
319I_packer(struct packenv *env, struct packspec *spec, int rep) 318I_packer(struct packenv *env, int rep)
320{ 319{
321 GETUARG(env, unsigned, UINT_MAX); 320 GETUARG(env, unsigned, UINT_MAX);
322 env->buf_pos += spec->size; 321 env->buf_pos += sizeof(unsigned);
323} 322}
324 323
325static void 324static void
326I_unpacker(struct packenv *env, struct packspec *spec, int rep) 325I_unpacker(struct packenv *env, int rep)
327{ 326{
328 printunum(env->fp, *(unsigned *)(env->buf_base + env->buf_pos)); 327 printunum(env->fp, *(unsigned *)(env->buf_base + env->buf_pos));
329 env->buf_pos += spec->size; 328 env->buf_pos += sizeof(unsigned);
330} 329}
331 330
332static void 331static void
333x_packer(struct packenv *env, struct packspec *spec, int rep) 332x_packer(struct packenv *env, int rep)
334{ 333{
335 if (env->buf_base)