2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #include <asn_internal.h>
7 #include <constr_CHOICE.h>
11 OPEN_TYPE_oer_get(const asn_codec_ctx_t *opt_codec_ctx,
12 const asn_TYPE_descriptor_t *td, void *sptr,
13 asn_TYPE_member_t *elm, const void *ptr, size_t size) {
14 asn_type_selector_result_t selected;
15 void *memb_ptr; /* Pointer to the member */
16 void **memb_ptr2; /* Pointer to that pointer */
22 if(!(elm->flags & ATF_OPEN_TYPE)) {
26 if(!elm->type_selector) {
27 ASN_DEBUG("Type selector is not defined for Open Type %s->%s->%s",
28 td->name, elm->name, elm->type->name);
32 selected = elm->type_selector(td, sptr);
33 if(!selected.presence_index) {
37 /* Fetch the pointer to this member */
38 if(elm->flags & ATF_POINTER) {
39 memb_ptr2 = (void **)((char *)sptr + elm->memb_offset);
41 memb_ptr = (char *)sptr + elm->memb_offset;
42 memb_ptr2 = &memb_ptr;
44 if(*memb_ptr2 != NULL) {
45 /* Make sure we reset the structure first before encoding */
46 if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, 0) != 0) {
53 + elm->type->elements[selected.presence_index - 1].memb_offset;
55 ot_ret = oer_open_type_get(opt_codec_ctx, selected.type_descriptor, NULL,
56 &inner_value, ptr, size);
59 if(CHOICE_variant_set_presence(elm->type, *memb_ptr2,
60 selected.presence_index)
66 /* Oh, now a full-blown failure failure */
80 const asn_CHOICE_specifics_t *specs =
81 selected.type_descriptor->specifics;
82 if(elm->flags & ATF_POINTER) {
83 ASN_STRUCT_FREE(*selected.type_descriptor, inner_value);
86 ASN_STRUCT_FREE_CONTENTS_ONLY(*selected.type_descriptor,
88 memset(*memb_ptr2, 0, specs->struct_size);