From 35ace19d5115533d6c6516865c2fc9c7c8c04993 Mon Sep 17 00:00:00 2001 From: Lev Walkin Date: Sat, 26 Aug 2017 23:33:14 -0700 Subject: [PATCH] uper-encode open type --- skeletons/OPEN_TYPE.c | 39 +++++++++++++++++++++++++++++++++++++++ skeletons/OPEN_TYPE.h | 5 ++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/skeletons/OPEN_TYPE.c b/skeletons/OPEN_TYPE.c index 6c73eef5..72bc88cf 100644 --- a/skeletons/OPEN_TYPE.c +++ b/skeletons/OPEN_TYPE.c @@ -258,4 +258,43 @@ OPEN_TYPE_uper_get(asn_codec_ctx_t *opt_codec_ctx, return rv; } +asn_enc_rval_t +OPEN_TYPE_encode_uper(asn_TYPE_descriptor_t *td, + const asn_per_constraints_t *constraints, void *sptr, + asn_per_outp_t *po) { + asn_type_selector_result_t selected; + void *memb_ptr; /* Pointer to the member */ + asn_TYPE_member_t *elm; /* CHOICE's element */ + asn_enc_rval_t er; + unsigned present; + + (void)constraints; + + present = CHOICE_variant_get_presence(td, sptr); + if(present == 0 || present > td->elements_count) { + ASN__ENCODE_FAILED; + } else { + present--; + } + + ASN_DEBUG("Encoding %s OPEN TYPE element %d", td->name, present); + + elm = &td->elements[present]; + if(elm->flags & ATF_POINTER) { + /* Member is a pointer to another structure */ + memb_ptr = *(void **)((char *)sptr + elm->memb_offset); + if(!memb_ptr) ASN__ENCODE_FAILED; + } else { + memb_ptr = (char *)sptr + elm->memb_offset; + } + + if(uper_open_type_put(elm->type, NULL, memb_ptr, po) < 0) { + ASN__ENCODE_FAILED; + } + + er.encoded = 0; + ASN__ENCODED_OK(er); +} + + #endif /* ASN_DISABLE_PER_SUPPORT */ diff --git a/skeletons/OPEN_TYPE.h b/skeletons/OPEN_TYPE.h index ff49adad..d49b3e64 100644 --- a/skeletons/OPEN_TYPE.h +++ b/skeletons/OPEN_TYPE.h @@ -20,7 +20,6 @@ extern "C" { #define OPEN_TYPE_decode_xer NULL #define OPEN_TYPE_encode_xer CHOICE_encode_xer #define OPEN_TYPE_decode_uper NULL -#define OPEN_TYPE_encode_uper CHOICE_encode_uper extern asn_TYPE_operation_t asn_OP_OPEN_TYPE; @@ -46,6 +45,10 @@ asn_dec_rval_t OPEN_TYPE_uper_get(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_member_t *element, asn_per_data_t *pd); +asn_enc_rval_t OPEN_TYPE_encode_uper(asn_TYPE_descriptor_t *type_descriptor, + const asn_per_constraints_t *constraints, + void *struct_ptr, + asn_per_outp_t *per_output); #ifdef __cplusplus }