2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <BIT_STRING.h>
10 * BIT STRING specific contents printer.
13 BIT_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
14 asn_app_consume_bytes_f *cb, void *app_key) {
15 const char * const h2c = "0123456789ABCDEF";
17 const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
22 (void)td; /* Unused argument */
25 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
34 for(; buf < end; buf++) {
35 if((buf - st->buf) % 16 == 0 && (st->size > 16)
39 if(cb(scratch, p - scratch, app_key) < 0) return -1;
42 *p++ = h2c[*buf >> 4];
43 *p++ = h2c[*buf & 0x0F];
48 p--; /* Eat the tailing space */
54 /* Dump the incomplete 16-bytes row */
55 if(cb(scratch, p - scratch, app_key) < 0)
60 int ret = snprintf(scratch, sizeof(scratch), " (%d bit%s unused)",
61 st->bits_unused, st->bits_unused == 1 ? "" : "s");
62 assert(ret > 0 && ret < (ssize_t)sizeof(scratch));
63 if(ret > 0 && ret < (ssize_t)sizeof(scratch)
64 && cb(scratch, ret, app_key) < 0)