2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: odr_seq.c,v 1.3 2005-01-15 19:47:14 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;
25 o->t_class = ODR_UNIVERSAL;
26 o->t_tag = ODR_SEQUENCE;
28 if (o->direction == ODR_DECODE)
30 if (odr_constructed_begin(o, p, o->t_class, o->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;
48 o->t_class = ODR_UNIVERSAL;
51 if (o->direction == ODR_DECODE)
53 if (odr_constructed_begin(o, p, o->t_class, o->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:
114 fprintf(stderr, "[seqof: num=%d]", *num);
116 for (i = 0; i < *num; i++)
119 fprintf(stderr, "[seqof: elem #%d]", i);
121 if (!(*type)(o, *pp + i, 0, 0))
126 odr_seterror(o, OOTHER, 47);
129 return odr_sequence_end(o);
132 int odr_set_of(ODR o, Odr_fun type, void *p, int *num, const char *name)
134 if (!odr_set_begin(o, p, 0, name)) {
135 if (o->direction == ODR_DECODE)
139 return odr_sequence_x (o, type, p, num);
142 int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num,
145 if (!odr_sequence_begin(o, p, 0, name)) {
146 if (o->direction == ODR_DECODE)
150 return odr_sequence_x (o, type, p, num);