1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements ODR BITSTRING codec
19 * Top level bitstring string en/decoder.
20 * Returns 1 on success, 0 on error.
22 int odr_bitstring(ODR o, Odr_bitmask **p, int opt, const char *name)
28 if (o->op->t_class < 0)
30 o->op->t_class = ODR_UNIVERSAL;
31 o->op->t_tag = ODR_BITSTRING;
33 res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
37 return odr_missing(o, opt, name);
38 if (o->direction == ODR_PRINT)
40 int i = ODR_BITMASK_SIZE;
43 odr_printf(o, "BITSTRING(len=%d) ",(*p)->top + 1);
45 if (ODR_MASK_GET(*p, i))
47 for (j = 0; j <= i; j++)
49 odr_printf(o, "%c", ODR_MASK_GET(*p, j) ? '1' : '0');
50 if (j && ((j+1)&7) == 0)
56 if (o->direction == ODR_DECODE)
58 *p = (Odr_bitmask *)odr_malloc(o, sizeof(Odr_bitmask));
59 memset((*p)->bits, 0, ODR_BITMASK_SIZE);
63 /* ignoring the cons helps with at least one target.
64 * http://bugzilla.indexdata.dk/cgi-bin/bugzilla/show_bug.cgi?id=24
66 return ber_bitstring(o, *p, 0);
68 return ber_bitstring(o, *p, cons);
74 * c-file-style: "Stroustrup"
75 * indent-tabs-mode: nil
77 * vim: shiftwidth=4 tabstop=8 expandtab