Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oer: OPEN TYPE encoding fix #164

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading