2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: odr_seq.c,v 1.7 2007-03-19 21:08:13 adam Exp $
9 * \brief Implements ODR SEQUENCE codec
17 int odr_sequence_begin(ODR o, void *p, int size, const char *name)
19 char **pp = (char**) p;
23 if (o->op->t_class < 0)
25 o->op->t_class = ODR_UNIVERSAL;
26 o->op->t_tag = ODR_SEQUENCE;
28 if (o->direction == ODR_DECODE)
30 if (odr_constructed_begin(o, p, o->op->t_class, o->op->t_tag, name))
32 if (o->direction == ODR_DECODE && size)
33 *pp = (char *)odr_malloc(o, size);
40 int odr_set_begin(ODR o, void *p, int size, const char *name)
42 char **pp = (char**) p;
46 if (o->op->t_class < 0)
48 o->op->t_class = ODR_UNIVERSAL;
49 o->op->t_tag = ODR_SET;
51 if (o->direction == ODR_DECODE)
53 if (odr_constructed_begin(o, p, o->op->t_class, o->op->t_tag, name))
55 if (o->direction == ODR_DECODE && size)
56 *pp = (char *)odr_malloc(o, size);
63 int odr_sequence_end(ODR o)
65 return odr_constructed_end(o);
68 int odr_set_end(ODR o)
70 return odr_constructed_end(o);
73 static int odr_sequence_more(ODR o)
75 return odr_constructed_more(o);
78 static int odr_sequence_x (ODR o, Odr_fun type, void *p, int *num)
80 char ***pp = (char***) p; /* for dereferencing */
88 *pp = (char **)odr_nullval();
89 while (odr_sequence_more(o))
92 if (*num * (int) sizeof(void*) >= size)
94 /* double the buffer size */
95 tmp = (char **)odr_malloc(o, sizeof(void*) *
96 (size += size ? size : 128));
99 memcpy(tmp, *pp, *num * sizeof(void*));
101 * For now, we just throw the old *p away, since we use
102 * nibble memory anyway (disgusting, isn't it?).
107 if (!(*type)(o, (*pp) + *num, 0, 0))
112 case ODR_ENCODE: case ODR_PRINT:
113 for (i = 0; i < *num; i++)
115 if (!(*type)(o, *pp + i, 0, 0))
120 odr_seterror(o, OOTHER, 47);
123 return odr_sequence_end(o);
126 int odr_set_of(ODR o, Odr_fun type, void *p, int *num, const char *name)
128 if (!odr_set_begin(o, p, 0, name)) {
129 if (o->direction == ODR_DECODE)
133 return odr_sequence_x (o, type, p, num);
136 int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num,
139 if (!odr_sequence_begin(o, p, 0, name)) {
140 if (o->direction == ODR_DECODE)
144 return odr_sequence_x (o, type, p, num);
150 * indent-tabs-mode: nil
152 * vim: shiftwidth=4 tabstop=8 expandtab