SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / NativeInteger_aper.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 <NativeInteger.h>
8
9 asn_dec_rval_t
10 NativeInteger_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
11                           const asn_TYPE_descriptor_t *td,
12                           const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
13
14     const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
15     asn_dec_rval_t rval;
16     long *native = (long *)*sptr;
17     INTEGER_t tmpint;
18     void *tmpintptr = &tmpint;
19
20     (void)opt_codec_ctx;
21     ASN_DEBUG("Decoding NativeInteger %s (APER)", td->name);
22
23     if(!native) {
24         native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
25         if(!native) ASN__DECODE_FAILED;
26     }
27
28     memset(&tmpint, 0, sizeof tmpint);
29     rval = INTEGER_decode_aper(opt_codec_ctx, td, constraints,
30                                &tmpintptr, pd);
31     if(rval.code == RC_OK) {
32         if((specs&&specs->field_unsigned)
33                 ? asn_INTEGER2ulong(&tmpint, (unsigned long *)native)
34                 : asn_INTEGER2long(&tmpint, native))
35             rval.code = RC_FAIL;
36         else
37             ASN_DEBUG("NativeInteger %s got value %ld",
38                       td->name, *native);
39     }
40     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
41
42     return rval;
43 }
44
45 asn_enc_rval_t
46 NativeInteger_encode_aper(const asn_TYPE_descriptor_t *td,
47                           const asn_per_constraints_t *constraints,
48                           const void *sptr, asn_per_outp_t *po) {
49
50     const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
51     asn_enc_rval_t er = {0,0,0};
52     long native;
53     INTEGER_t tmpint;
54
55     if(!sptr) ASN__ENCODE_FAILED;
56
57     native = *(const long *)sptr;
58
59     ASN_DEBUG("Encoding NativeInteger %s %ld (APER)", td->name, native);
60
61     memset(&tmpint, 0, sizeof(tmpint));
62     if((specs&&specs->field_unsigned)
63             ? asn_ulong2INTEGER(&tmpint, (unsigned long)native)
64             : asn_long2INTEGER(&tmpint, native))
65         ASN__ENCODE_FAILED;
66     er = INTEGER_encode_aper(td, constraints, &tmpint, po);
67     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
68     return er;
69 }