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 /src | |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/pack.c | 131 |
1 files changed, 65 insertions, 66 deletions
@@ -61,6 +61,5 @@ struct packspec { int ch; - size_t size; int flags; - void (*packer)(struct packenv *, struct packspec *, int); - void (*unpacker)(struct packenv *, struct packspec *, int); + void (*packer)(struct packenv *, int); + void (*unpacker)(struct packenv *, int); }; @@ -179,3 +178,3 @@ getsnum(char *s, intmax_t minval, intmax_t maxval, intmax_t *retval) static void -Z_packer(struct packenv *env, struct packspec *spec, int rep) +Z_packer(struct packenv *env, int rep) { @@ -196,3 +195,3 @@ Z_packer(struct packenv *env, struct packspec *spec, int rep) static void -Z_unpacker(struct packenv *env, struct packspec *spec, int rep) +Z_unpacker(struct packenv *env, int rep) { @@ -203,3 +202,3 @@ Z_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -c_packer(struct packenv *env, struct packspec *spec, int rep) +c_packer(struct packenv *env, int rep) { @@ -214,3 +213,3 @@ c_packer(struct packenv *env, struct packspec *spec, int rep) static void -c_unpacker(struct packenv *env, struct packspec *spec, int rep) +c_unpacker(struct packenv *env, int rep) { @@ -220,6 +219,6 @@ c_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -s_packer(struct packenv *env, struct packspec *spec, int rep) +s_packer(struct packenv *env, int rep) { GETSARG(env, int16_t, INT16_MIN, INT16_MAX); - env->buf_pos += spec->size; + env->buf_pos += sizeof(int16_t); } @@ -227,6 +226,6 @@ s_packer(struct packenv *env, struct packspec *spec, int rep) static void -s_unpacker(struct packenv *env, struct packspec *spec, int rep) +s_unpacker(struct packenv *env, int rep) { printsnum(env->fp, *(int16_t *) (env->buf_base + env->buf_pos)); - env->buf_pos += spec->size; + env->buf_pos += sizeof(int16_t); } @@ -234,6 +233,6 @@ s_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -S_packer(struct packenv *env, struct packspec *spec, int rep) +S_packer(struct packenv *env, int rep) { GETUARG(env, uint16_t, UINT16_MAX); - env->buf_pos += spec->size; + env->buf_pos += sizeof(uint16_t); } @@ -241,6 +240,6 @@ S_packer(struct packenv *env, struct packspec *spec, int rep) static void -S_unpacker(struct packenv *env, struct packspec *spec, int rep) +S_unpacker(struct packenv *env, int rep) { printunum(env->fp, *(uint16_t *)(env->buf_base + env->buf_pos)); - env->buf_pos += spec->size; + env->buf_pos += sizeof(uint16_t); } @@ -248,6 +247,6 @@ S_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -l_packer(struct packenv *env, struct packspec *spec, int rep) +l_packer(struct packenv *env, int rep) { GETSARG(env, int32_t, INT32_MIN, INT32_MAX); - env->buf_pos += spec->size; + env->buf_pos += sizeof(int32_t); } @@ -255,6 +254,6 @@ l_packer(struct packenv *env, struct packspec *spec, int rep) static void -l_unpacker(struct packenv *env, struct packspec *spec, int rep) +l_unpacker(struct packenv *env, int rep) { printsnum(env->fp, *(int32_t *)(env->buf_base + env->buf_pos)); - env->buf_pos += spec->size; + env->buf_pos += sizeof(int32_t); } @@ -262,6 +261,6 @@ l_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -L_packer(struct packenv *env, struct packspec *spec, int rep) +L_packer(struct packenv *env, int rep) { GETUARG(env, uint32_t, UINT32_MAX); - env->buf_pos += spec->size; + env->buf_pos += sizeof(uint32_t); } @@ -269,6 +268,6 @@ L_packer(struct packenv *env, struct packspec *spec, int rep) static void -L_unpacker(struct packenv *env, struct packspec *spec, int rep) +L_unpacker(struct packenv *env, int rep) { printunum(env->fp, *(uint32_t *)(env->buf_base + env->buf_pos)); - env->buf_pos += spec->size; + env->buf_pos += sizeof(uint32_t); } @@ -276,6 +275,6 @@ L_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -q_packer(struct packenv *env, struct packspec *spec, int rep) +q_packer(struct packenv *env, int rep) { GETSARG(env, int64_t, INT64_MIN, INT64_MAX); - env->buf_pos += spec->size; + env->buf_pos += sizeof(int64_t); } @@ -283,6 +282,6 @@ q_packer(struct packenv *env, struct packspec *spec, int rep) static void -q_unpacker(struct packenv *env, struct packspec *spec, int rep) +q_unpacker(struct packenv *env, int rep) { printsnum(env->fp, *(int64_t *)(env->buf_base + env->buf_pos)); - env->buf_pos += spec->size; + env->buf_pos += sizeof(int64_t); } @@ -290,6 +289,6 @@ q_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -Q_packer(struct packenv *env, struct packspec *spec, int rep) +Q_packer(struct packenv *env, int rep) { GETUARG(env, uint64_t, UINT64_MAX); - env->buf_pos += spec->size; + env->buf_pos += sizeof(uint64_t); } @@ -297,6 +296,6 @@ Q_packer(struct packenv *env, struct packspec *spec, int rep) static void -Q_unpacker(struct packenv *env, struct packspec *spec, int rep) +Q_unpacker(struct packenv *env, int rep) { printunum(env->fp, *(uint64_t *)(env->buf_base + env->buf_pos)); - env->buf_pos += spec->size; + env->buf_pos += sizeof(uint64_t); } @@ -304,6 +303,6 @@ Q_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -i_packer(struct packenv *env, struct packspec *spec, int rep) +i_packer(struct packenv *env, int rep) { GETSARG(env, int, INT_MIN, INT_MAX); - env->buf_pos += spec->size; + env->buf_pos += sizeof(int); } @@ -311,6 +310,6 @@ i_packer(struct packenv *env, struct packspec *spec, int rep) static void -i_unpacker(struct packenv *env, struct packspec *spec, int rep) +i_unpacker(struct packenv *env, int rep) { printsnum(env->fp, *(int *)(env->buf_base + env->buf_pos)); - env->buf_pos += spec->size; + env->buf_pos += sizeof(int); } @@ -318,6 +317,6 @@ i_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -I_packer(struct packenv *env, struct packspec *spec, int rep) +I_packer(struct packenv *env, int rep) { GETUARG(env, unsigned, UINT_MAX); - env->buf_pos += spec->size; + env->buf_pos += sizeof(unsigned); } @@ -325,6 +324,6 @@ I_packer(struct packenv *env, struct packspec *spec, int rep) static void -I_unpacker(struct packenv *env, struct packspec *spec, int rep) +I_unpacker(struct packenv *env, int rep) { printunum(env->fp, *(unsigned *)(env->buf_base + env->buf_pos)); - env->buf_pos += spec->size; + env->buf_pos += sizeof(unsigned); } @@ -332,3 +331,3 @@ I_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -x_packer(struct packenv *env, struct packspec *spec, int rep) +x_packer(struct packenv *env, int rep) { @@ -340,3 +339,3 @@ x_packer(struct packenv *env, struct packspec *spec, int rep) static void -x_unpacker(struct packenv *env, struct packspec *spec, int rep) +x_unpacker(struct packenv *env, int rep) { @@ -346,3 +345,3 @@ x_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -X_packer(struct packenv *env, struct packspec *spec, int rep) +X_packer(struct packenv *env, int rep) { @@ -353,3 +352,3 @@ X_packer(struct packenv *env, struct packspec *spec, int rep) static void -at_packer(struct packenv *env, struct packspec *spec, int rep) +at_packer(struct packenv *env, int rep) { @@ -361,3 +360,3 @@ at_packer(struct packenv *env, struct packspec *spec, int rep) static void -at_unpacker(struct packenv *env, struct packspec *spec, int rep) +at_unpacker(struct packenv *env, int rep) { @@ -367,3 +366,3 @@ at_unpacker(struct packenv *env, struct packspec *spec, int rep) static void -dot_packer(struct packenv *env, struct packspec *spec, int rep) +dot_packer(struct packenv *env, int rep) { @@ -380,3 +379,3 @@ dot_packer(struct packenv *env, struct packspec *spec, int rep) static void -dot_unpacker(struct packenv *env, struct packspec *spec, int rep) +dot_unpacker(struct packenv *env, int rep) { @@ -386,17 +385,17 @@ dot_unpacker(struct packenv *env, struct packspec *spec, int rep) static struct packspec packspec[] = { - { 'Z', 1, F_REP, Z_packer, Z_unpacker }, - { 'c', 1, 0, c_packer, c_unpacker }, - { 's', sizeof(int16_t), 0, s_packer, s_unpacker }, - { 'S', sizeof(uint16_t), 0, S_packer, S_unpacker }, - { 'l', sizeof(int32_t), 0, l_packer, l_unpacker }, - { 'L', sizeof(uint32_t), 0, L_packer, L_unpacker }, - { 'q', sizeof(int64_t), 0, q_packer, q_unpacker }, - { 'Q', sizeof(uint64_t), 0, Q_packer, Q_unpacker }, - { 'i', sizeof(int), 0, i_packer, i_unpacker }, - { 'I', sizeof(unsigned), 0, I_packer, I_unpacker }, + { 'Z', F_REP, Z_packer, Z_unpacker }, + { 'c', 0, c_packer, c_unpacker }, + { 's', 0, s_packer, s_unpacker }, + { 'S', 0, S_packer, S_unpacker }, + { 'l', 0, l_packer, l_unpacker }, + { 'L', 0, L_packer, L_unpacker }, + { 'q', 0, q_packer, q_unpacker }, + { 'Q', 0, Q_packer, Q_unpacker }, + { 'i', 0, i_packer, i_unpacker }, + { 'I', 0, I_packer, I_unpacker }, /* FIXME: n N v V f d */ - { 'x', 1, 0, x_packer, x_unpacker }, - { 'X', 1, 0, X_packer, X_packer }, - { '@', 0, F_REP, at_packer, at_unpacker }, - { '.', 0, F_REP, dot_packer, dot_unpacker }, + { 'x', 0, x_packer, x_unpacker }, + { 'X', 0, X_packer, X_packer }, + { '@', F_REP, at_packer, at_unpacker }, + { '.', F_REP, dot_packer, dot_unpacker }, @@ -496,6 +495,6 @@ packin(struct packinst *pi, struct packenv *env) if (pi->spec->flags & F_REP) - pi->spec->packer(env, pi->spec, pi->rep); + pi->spec->packer(env, pi->rep); else for (i = 0; i < pi->rep; i++) - pi->spec->packer(env, pi->spec, 1); + pi->spec->packer(env, 1); } @@ -511,5 +510,5 @@ packinnext(struct packinst *pi, struct packenv *env) if (pi->spec->flags & F_REP) - pi->spec->packer(env, pi->spec, pi->rep); + pi->spec->packer(env, pi->rep); else { - pi->spec->packer(env, pi->spec, 1); + pi->spec->packer(env, 1); if (++pi->cur < pi->rep) @@ -527,3 +526,3 @@ packout(struct packinst *pi, struct packenv *env) if (pi->spec->flags & F_REP) - pi->spec->unpacker(env, pi->spec, pi->rep); + pi->spec->unpacker(env, pi->rep); else @@ -532,3 +531,3 @@ packout(struct packinst *pi, struct packenv *env) fputc(' ', env->fp); - pi->spec->unpacker(env, pi->spec, 1); + pi->spec->unpacker(env, 1); } |