1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements ODR SEQUENCE codec
15 int odr_sequence_begin(ODR o, void *p, int size, const char *name)
17 char **pp = (char**) p;
21 if (o->op->t_class < 0)
23 o->op->t_class = ODR_UNIVERSAL;
24 o->op->t_tag = ODR_SEQUENCE;
26 if (o->direction == ODR_DECODE)
28 if (odr_constructed_begin(o, p, o->op->t_class, o->op->t_tag, name))
30 if (o->direction == ODR_DECODE && size)
31 *pp = (char *)odr_malloc(o, size);
38 int odr_set_begin(ODR o, void *p, int size, const char *name)
40 char **pp = (char**) p;
44 if (o->op->t_class < 0)
46 o->op->t_class = ODR_UNIVERSAL;
47 o->op->t_tag = ODR_SET;
49 if (o->direction == ODR_DECODE)
51 if (odr_constructed_begin(o, p, o->op->t_class, o->op->t_tag, name))
53 if (o->direction == ODR_DECODE && size)
54 *pp = (char *)odr_malloc(o, size);
61 int odr_sequence_end(ODR o)
63 return odr_constructed_end(o);
66 int odr_set_end(ODR o)
68 return odr_constructed_end(o);
71 static int odr_sequence_more(ODR o)
73 return odr_constructed_more(o);
76 static int odr_sequence_x (ODR o, Odr_fun type, void *p, int *num)
78 char ***pp = (char***) p; /* for dereferencing */
86 *pp = (char **)odr_nullval();
87 while (odr_sequence_more(o))
90 if (*num * (int) sizeof(void*) >= size)
92 /* double the buffer size */
93 tmp = (char **)odr_malloc(o, sizeof(void*) *
94 (size += size ? size : 128));
97 memcpy(tmp, *pp, *num * sizeof(void*));
99 * For now, we just throw the old *p away, since we use
100 * nibble memory anyway (disgusting, isn't it?).
105 if (!(*type)(o, (*pp) + *num, 0, 0))
110 case ODR_ENCODE: case ODR_PRINT:
111 for (i = 0; i < *num; i++)
113 if (!(*type)(o, *pp + i, 0, 0))
118 odr_seterror(o, OOTHER, 47);
121 return odr_sequence_end(o);
124 int odr_set_of(ODR o, Odr_fun type, void *p, int *num, const char *name)
126 if (!odr_set_begin(o, p, 0, name)) {
127 if (o->direction == ODR_DECODE)
131 return odr_sequence_x (o, type, p, num);
134 int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num,
137 if (!odr_sequence_begin(o, p, 0, name)) {
138 if (o->direction == ODR_DECODE)
142 return odr_sequence_x (o, type, p, num);
148 * indent-tabs-mode: nil
150 * vim: shiftwidth=4 tabstop=8 expandtab