Skip to content

Commit

Permalink
Merge pull request #164 from v0-e/oer-open-type-encode-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse07410 committed Jan 9, 2024
2 parents f2c5d7c + 815e5bc commit 9e5726b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion skeletons/OPEN_TYPE.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ asn_dec_rval_t OPEN_TYPE_oer_get(
asn_TYPE_member_t *element, const void *ptr,
size_t size);
#define OPEN_TYPE_decode_oer NULL
#define OPEN_TYPE_encode_oer CHOICE_encode_oer
asn_enc_rval_t OPEN_TYPE_encode_oer(
const asn_TYPE_descriptor_t *type_descriptor,
const asn_oer_constraints_t *constraints, const void *struct_ptr,
asn_app_consume_bytes_f *consume_bytes_cb, void *app_key);
#endif /* !defined(ASN_DISABLE_OER_SUPPORT) */

#if !defined(ASN_DISABLE_UPER_SUPPORT)
Expand Down
47 changes: 47 additions & 0 deletions skeletons/OPEN_TYPE_oer.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,50 @@ OPEN_TYPE_oer_get(const asn_codec_ctx_t *opt_codec_ctx,
}
return rv;
}

asn_enc_rval_t
OPEN_TYPE_encode_oer(const asn_TYPE_descriptor_t *td,
const asn_oer_constraints_t *constraints, const void *sptr,
asn_app_consume_bytes_f *cb, void *app_key) {
asn_TYPE_member_t *elm;
unsigned present;
const void *memb_ptr;
ssize_t encoded;
asn_enc_rval_t er = {0, 0, 0};

(void)constraints;

if(!sptr) ASN__ENCODE_FAILED;

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) {
memb_ptr =
*(const void *const *)((const char *)sptr + elm->memb_offset);
if(memb_ptr == 0) {
/* Mandatory element absent */
ASN__ENCODE_FAILED;
}
} else {
memb_ptr = (const void *)((const char *)sptr + elm->memb_offset);
}

if((encoded = oer_open_type_put(elm->type,
elm->encoding_constraints.oer_constraints,
memb_ptr, cb, app_key)) < 0) {
ASN__ENCODE_FAILED;
}

er.encoded = encoded;
ASN__ENCODED_OK(er);

return er;
}

0 comments on commit 9e5726b

Please sign in to comment.