SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / constr_CHOICE_print.c
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  */
6 #include <asn_internal.h>
7 #include <constr_CHOICE.h>
8
9 int
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;
13     unsigned present;
14
15     if(!sptr) return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
16
17     /*
18      * Figure out which CHOICE element is encoded.
19      */
20     present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size);
21
22     /*
23      * Print that element.
24      */
25     if(present > 0 && present <= td->elements_count) {
26         asn_TYPE_member_t *elm = &td->elements[present-1];
27         const void *memb_ptr;
28
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;
32         } else {
33             memb_ptr = (const void *)((const char *)sptr + elm->memb_offset);
34         }
35
36         /* Print member's name and stuff */
37         if(0) {
38             if(cb(elm->name, strlen(elm->name), app_key) < 0
39             || cb(": ", 2, app_key) < 0)
40                 return -1;
41         }
42
43         return elm->type->op->print_struct(elm->type, memb_ptr, ilevel,
44                                            cb, app_key);
45     } else {
46         return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
47     }
48 }