046afe9e87c8ac15c5be7493e09bde5dab0b210d
[sim/e2-interface.git] / e2sim / asn1c / NativeEnumerated_jer.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 <NativeEnumerated.h>
8
9 asn_enc_rval_t
10 NativeEnumerated_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr,
11                             int ilevel, enum jer_encoder_flags_e flags,
12                             asn_app_consume_bytes_f *cb, void *app_key) {
13     const asn_INTEGER_specifics_t *specs =
14         (const asn_INTEGER_specifics_t *)td->specifics;
15     asn_enc_rval_t er = {0,0,0};
16     const long *native = (const long *)sptr;
17     const asn_INTEGER_enum_map_t *el;
18
19     (void)ilevel;
20     (void)flags;
21
22     if(!native) ASN__ENCODE_FAILED;
23
24     el = INTEGER_map_value2enum(specs, *native);
25     if(el) {
26         er.encoded =
27             asn__format_to_callback(cb, app_key, "\"%s\"", el->enum_name);
28         if(er.encoded < 0) ASN__ENCODE_FAILED;
29         ASN__ENCODED_OK(er);
30     } else {
31         ASN_DEBUG(
32             "ASN.1 forbids dealing with "
33             "unknown value of ENUMERATED type");
34         ASN__ENCODE_FAILED;
35     }
36 }