SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / constr_SEQUENCE_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_SEQUENCE.h>
8
9 int
10 SEQUENCE_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
11                asn_app_consume_bytes_f *cb, void *app_key) {
12     size_t edx;
13     int ret;
14
15     if(!sptr) return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
16
17     /* Dump preamble */
18     if(cb(td->name, strlen(td->name), app_key) < 0
19     || cb(" ::= {", 6, app_key) < 0)
20         return -1;
21
22     for(edx = 0; edx < td->elements_count; edx++) {
23         asn_TYPE_member_t *elm = &td->elements[edx];
24         const void *memb_ptr;
25
26         if(elm->flags & ATF_POINTER) {
27             memb_ptr = *(const void * const *)((const char *)sptr + elm->memb_offset);
28             if(!memb_ptr) {
29                 if(elm->optional) continue;
30                 /* Print <absent> line */
31                 /* Fall through */
32             }
33         } else {
34             memb_ptr = (const void *)((const char *)sptr + elm->memb_offset);
35         }
36
37         /* Indentation */
38         _i_INDENT(1);
39
40         /* Print the member's name and stuff */
41         if(cb(elm->name, strlen(elm->name), app_key) < 0
42         || cb(": ", 2, app_key) < 0)
43             return -1;
44
45         /* Print the member itself */
46         ret = elm->type->op->print_struct(elm->type, memb_ptr, ilevel + 1,
47                                           cb, app_key);
48         if(ret) return ret;
49     }
50
51     ilevel--;
52     _i_INDENT(1);
53
54     return (cb("}", 1, app_key) < 0) ? -1 : 0;
55 }