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 <constr_CHOICE.h>
10 CHOICE_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
11 asn_app_consume_bytes_f *cb, void *app_key) {
12 const asn_CHOICE_specifics_t *specs = (const asn_CHOICE_specifics_t *)td->specifics;
15 if(!sptr) return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
18 * Figure out which CHOICE element is encoded.
20 present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size);
25 if(present > 0 && present <= td->elements_count) {
26 asn_TYPE_member_t *elm = &td->elements[present-1];
29 if(elm->flags & ATF_POINTER) {
30 memb_ptr = *(const void * const *)((const char *)sptr + elm->memb_offset);
31 if(!memb_ptr) return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
33 memb_ptr = (const void *)((const char *)sptr + elm->memb_offset);
36 /* Print member's name and stuff */
38 if(cb(elm->name, strlen(elm->name), app_key) < 0
39 || cb(": ", 2, app_key) < 0)
43 return elm->type->op->print_struct(elm->type, memb_ptr, ilevel,
46 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;