BIT_STRING_print.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
8 
9 /*
10  * BIT STRING specific contents printer.
11  */
12 int
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";
16  char scratch[64];
17  const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
18  uint8_t *buf;
19  uint8_t *end;
20  char *p = scratch;
21 
22  (void)td; /* Unused argument */
23 
24  if(!st || !st->buf)
25  return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
26 
27  ilevel++;
28  buf = st->buf;
29  end = buf + st->size;
30 
31  /*
32  * Hexadecimal dump.
33  */
34  for(; buf < end; buf++) {
35  if((buf - st->buf) % 16 == 0 && (st->size > 16)
36  && buf != st->buf) {
37  _i_INDENT(1);
38  /* Dump the string */
39  if(cb(scratch, p - scratch, app_key) < 0) return -1;
40  p = scratch;
41  }
42  *p++ = h2c[*buf >> 4];
43  *p++ = h2c[*buf & 0x0F];
44  *p++ = 0x20;
45  }
46 
47  if(p > scratch) {
48  p--; /* Eat the tailing space */
49 
50  if((st->size > 16)) {
51  _i_INDENT(1);
52  }
53 
54  /* Dump the incomplete 16-bytes row */
55  if(cb(scratch, p - scratch, app_key) < 0)
56  return -1;
57  }
58 
59  if(st->bits_unused) {
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)
65  return -1;
66  }
67 
68  return 0;
69 }
BIT_STRING_s::buf
uint8_t * buf
Definition: BIT_STRING.h:15
BIT_STRING_s::size
size_t size
Definition: BIT_STRING.h:16
BIT_STRING_print
int BIT_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key)
Definition: BIT_STRING_print.c:13
BIT_STRING_s
Definition: BIT_STRING.h:14
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
asn_app_consume_bytes_f
int() asn_app_consume_bytes_f(const void *buffer, size_t size, void *application_specific_key)
Definition: asn_application.h:124
asn_internal.h
_i_INDENT
#define _i_INDENT(nl)
Definition: asn_internal.h:127
BIT_STRING.h
BIT_STRING_s::bits_unused
int bits_unused
Definition: BIT_STRING.h:18


etsi_its_vam_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:30:55