summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-13 07:09:45 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-10-13 07:09:45 (GMT)
commit4d4fde41b23815719f8c59e27832e29766c35bf0 (patch) (side-by-side diff)
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.
Diffstat (more/less context) (ignore whitespace changes)
-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 @@
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);
};
struct packinst {
@@ -177,7 +176,7 @@ 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)
{
if (env->buf_base) {
char *arg = packenv_get(env);
@@ -194,14 +193,14 @@ 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)
{
fprintf(env->fp, "%-*.*s", rep, rep, env->buf_base + env->buf_pos);
env->buf_pos += rep;
}
static void
-c_packer(struct packenv *env, struct packspec *spec, int rep)
+c_packer(struct packenv *env, int rep)
{
if (env->buf_base) {
char *arg = packenv_get(env);
@@ -212,125 +211,125 @@ 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)
{
fprintf(env->fp, "%c", env->buf_base[env->buf_pos++]);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
static void
-x_packer(struct packenv *env, struct packspec *spec, int rep)
+x_packer(struct packenv *env, int rep)
{
if (env->buf_base)
env->buf_base[env->buf_pos] = 0;
@@ -338,20 +337,20 @@ 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)
{
fputc(0, env->fp);
}
static void
-X_packer(struct packenv *env, struct packspec *spec, int rep)
+X_packer(struct packenv *env, int rep)
{
if (env->buf_pos)
--env->buf_pos;
}
static void
-at_packer(struct packenv *env, struct packspec *spec, int rep)
+at_packer(struct packenv *env, int rep)
{
if (env->buf_base)
memset(env->buf_base + env->buf_pos, 0, rep);
@@ -359,13 +358,13 @@ 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)
{
env->buf_pos += rep;
}
static void
-dot_packer(struct packenv *env, struct packspec *spec, int rep)
+dot_packer(struct packenv *env, int rep)
{
if (env->buf_base) {
if (rep < env->buf_pos)
@@ -378,27 +377,27 @@ 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)
{
env->buf_pos = 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 },
{ 0 }
};
@@ -494,10 +493,10 @@ packin(struct packinst *pi, struct packenv *env)
for (; pi; pi = pi->next) {
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);
}
}
@@ -509,9 +508,9 @@ packinnext(struct packinst *pi, struct packenv *env)
if (!pi)
return NULL;
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)
return pi;
}
@@ -525,12 +524,12 @@ packout(struct packinst *pi, struct packenv *env)
for (; pi; pi = pi->next) {
if (pi->spec->flags & F_REP)
- pi->spec->unpacker(env, pi->spec, pi->rep);
+ pi->spec->unpacker(env, pi->rep);
else
for (i = 0; i < pi->rep; i++) {
if (i > 0)
fputc(' ', env->fp);
- pi->spec->unpacker(env, pi->spec, 1);
+ pi->spec->unpacker(env, 1);
}
if (pi->next)
fputc(' ', env->fp);

Return to:

Send suggestions and report system problems to the System administrator.