2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <NativeInteger.h>
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,
14 const asn_INTEGER_specifics_t *specs =
15 (const asn_INTEGER_specifics_t *)td->specifics;
17 long *native = (long *)*sptr;
19 void *tmpintptr = &tmpint;
22 ASN_DEBUG("Decoding NativeInteger %s (UPER)", td->name);
25 native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
26 if(!native) ASN__DECODE_FAILED;
29 memset(&tmpint, 0, sizeof tmpint);
30 rval = INTEGER_decode_uper(opt_codec_ctx, td, constraints,
32 if(rval.code == RC_OK) {
33 if((specs&&specs->field_unsigned)
34 ? asn_INTEGER2ulong(&tmpint, (unsigned long *)native)
35 : asn_INTEGER2long(&tmpint, native))
38 ASN_DEBUG("NativeInteger %s got value %ld",
41 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
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};
56 if(!sptr) ASN__ENCODE_FAILED;
58 native = *(const long *)sptr;
60 ASN_DEBUG("Encoding NativeInteger %s %ld (UPER)", td->name, native);
62 memset(&tmpint, 0, sizeof(tmpint));
63 if((specs&&specs->field_unsigned)
64 ? asn_ulong2INTEGER(&tmpint, native)
65 : asn_long2INTEGER(&tmpint, native))
67 er = INTEGER_encode_uper(td, constraints, &tmpint, po);
68 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);