int SET_OF_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { asn_TYPE_member_t *elm = td->elements; const asn_anonymous_set_ *list = _A_CSET_FROM_VOID(sptr); int ret; int i; if(!sptr) return (cb("<absent>", 8, app_key) < 0) ? -1 : 0; /* Dump preamble */ if(cb(td->name, strlen(td->name), app_key) < 0 || cb(" ::= {", 6, app_key) < 0) return -1; for(i = 0; i < list->count; i++) { const void *memb_ptr = list->array[i]; if(!memb_ptr) continue; _i_INDENT(1); ret = elm->type->print_struct(elm->type, memb_ptr, ilevel + 1, cb, app_key); if(ret) return ret; } ilevel--; _i_INDENT(1); return (cb("}", 1, app_key) < 0) ? -1 : 0; }
/* * BIT STRING specific contents printer. */ int BIT_STRING_print(Allocator * allocator, asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { const char * const h2c = "0123456789ABCDEF"; char scratch[64]; const BIT_STRING_t *st = (const BIT_STRING_t *)sptr; uint8_t *buf; uint8_t *end; char *p = scratch; (void)td; /* Unused argument */ if(!st || !st->buf) return (cb(allocator, "<absent>", 8, app_key) < 0) ? -1 : 0; ilevel++; buf = st->buf; end = buf + st->size; /* * Hexadecimal dump. */ for(; buf < end; buf++) { if((buf - st->buf) % 16 == 0 && (st->size > 16) && buf != st->buf) { _i_INDENT(allocator, 1); /* Dump the string */ if(cb(allocator, scratch, p - scratch, app_key) < 0) return -1; p = scratch; } *p++ = h2c[*buf >> 4]; *p++ = h2c[*buf & 0x0F]; *p++ = 0x20; } if(p > scratch) { p--; /* Eat the tailing space */ if((st->size > 16)) { _i_INDENT(allocator, 1); } /* Dump the incomplete 16-bytes row */ if(cb(allocator, scratch, p - scratch, app_key) < 0) return -1; } return 0; }
int SEQUENCE_print(Allocator * allocator, asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { int edx; int ret; if(!sptr) return (cb(allocator, "<absent>", 8, app_key) < 0) ? -1 : 0; /* Dump preamble */ if(cb(allocator, td->name, strlen(td->name), app_key) < 0 || cb(allocator, " ::= {", 6, app_key) < 0) return -1; for(edx = 0; edx < td->elements_count; edx++) { asn_TYPE_member_t *elm = &td->elements[edx]; const void *memb_ptr; if(elm->flags & ATF_POINTER) { memb_ptr = *(const void * const *)((const char *)sptr + elm->memb_offset); if(!memb_ptr) { if(elm->optional) continue; /* Print <absent> line */ /* Fall through */ } } else { memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); } /* Indentation */ _i_INDENT(allocator, 1); /* Print the member's name and stuff */ if(cb(allocator, elm->name, strlen(elm->name), app_key) < 0 || cb(allocator, ": ", 2, app_key) < 0) return -1; /* Print the member itself */ ret = elm->type->print_struct(allocator, elm->type, memb_ptr, ilevel + 1, cb, app_key); if(ret) return ret; } ilevel--; _i_INDENT(allocator, 1); return (cb(allocator, "}", 1, app_key) < 0) ? -1 : 0; }