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