diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-13 10:09:45 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-13 10:09:45 +0300 |
commit | 4d4fde41b23815719f8c59e27832e29766c35bf0 (patch) | |
tree | aaa08a10304354f7a4ff8d69c4b5924ef6e84f61 | |
parent | 6abc995ed0ac0349b8451cfe883d5296da341c66 (diff) | |
download | vmod-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.c | 131 |
1 files changed, 65 insertions, 66 deletions
@@ -59,10 +59,9 @@ | |||
59 | 59 | ||
60 | struct packspec { | 60 | struct 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 | ||
68 | struct packinst { | 67 | struct packinst { |
@@ -177,7 +176,7 @@ getsnum(char *s, intmax_t minval, intmax_t maxval, intmax_t *retval) | |||
177 | 176 | ||
178 | 177 | ||
179 | static void | 178 | static void |
180 | Z_packer(struct packenv *env, struct packspec *spec, int rep) | 179 | Z_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 | ||
196 | static void | 195 | static void |
197 | Z_unpacker(struct packenv *env, struct packspec *spec, int rep) | 196 | Z_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 | ||
203 | static void | 202 | static void |
204 | c_packer(struct packenv *env, struct packspec *spec, int rep) | 203 | c_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 | ||
214 | static void | 213 | static void |
215 | c_unpacker(struct packenv *env, struct packspec *spec, int rep) | 214 | c_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 | ||
220 | static void | 219 | static void |
221 | s_packer(struct packenv *env, struct packspec *spec, int rep) | 220 | s_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 | ||
227 | static void | 226 | static void |
228 | s_unpacker(struct packenv *env, struct packspec *spec, int rep) | 227 | s_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 | ||
234 | static void | 233 | static void |
235 | S_packer(struct packenv *env, struct packspec *spec, int rep) | 234 | S_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 | ||
241 | static void | 240 | static void |
242 | S_unpacker(struct packenv *env, struct packspec *spec, int rep) | 241 | S_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 | ||
248 | static void | 247 | static void |
249 | l_packer(struct packenv *env, struct packspec *spec, int rep) | 248 | l_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 | ||
255 | static void | 254 | static void |
256 | l_unpacker(struct packenv *env, struct packspec *spec, int rep) | 255 | l_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 | ||
262 | static void | 261 | static void |
263 | L_packer(struct packenv *env, struct packspec *spec, int rep) | 262 | L_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 | ||
269 | static void | 268 | static void |
270 | L_unpacker(struct packenv *env, struct packspec *spec, int rep) | 269 | L_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 | ||
276 | static void | 275 | static void |
277 | q_packer(struct packenv *env, struct packspec *spec, int rep) | 276 | q_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 | ||
283 | static void | 282 | static void |
284 | q_unpacker(struct packenv *env, struct packspec *spec, int rep) | 283 | q_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 | ||
290 | static void | 289 | static void |
291 | Q_packer(struct packenv *env, struct packspec *spec, int rep) | 290 | Q_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 | ||
297 | static void | 296 | static void |
298 | Q_unpacker(struct packenv *env, struct packspec *spec, int rep) | 297 | Q_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 | ||
304 | static void | 303 | static void |
305 | i_packer(struct packenv *env, struct packspec *spec, int rep) | 304 | i_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 | ||
311 | static void | 310 | static void |
312 | i_unpacker(struct packenv *env, struct packspec *spec, int rep) | 311 | i_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 | ||
318 | static void | 317 | static void |
319 | I_packer(struct packenv *env, struct packspec *spec, int rep) | 318 | I_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 | ||
325 | static void | 324 | static void |
326 | I_unpacker(struct packenv *env, struct packspec *spec, int rep) | 325 | I_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 | ||
332 | static void | 331 | static void |
333 | x_packer(struct packenv *env, struct packspec *spec, int rep) | 332 | x_packer(struct packenv *env, int rep) |
334 | { | 333 | { |
335 | if (env->buf_base) |