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_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) {
14 const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
16 long *native = (long *)*sptr;
18 void *tmpintptr = &tmpint;
21 ASN_DEBUG("Decoding NativeInteger %s (APER)", td->name);
24 native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
25 if(!native) ASN__DECODE_FAILED;
28 memset(&tmpint, 0, sizeof tmpint);
29 rval = INTEGER_decode_aper(opt_codec_ctx, td, constraints,
31 if(rval.code == RC_OK) {
32 if((specs&&specs->field_unsigned)
33 ? asn_INTEGER2ulong(&tmpint, (unsigned long *)native)
34 : asn_INTEGER2long(&tmpint, native))
37 ASN_DEBUG("NativeInteger %s got value %ld",
40 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
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) {
50 const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
51 asn_enc_rval_t er = {0,0,0};
55 if(!sptr) ASN__ENCODE_FAILED;
57 native = *(const long *)sptr;
59 ASN_DEBUG("Encoding NativeInteger %s %ld (APER)", td->name, native);
61 memset(&tmpint, 0, sizeof(tmpint));
62 if((specs&&specs->field_unsigned)
63 ? asn_ulong2INTEGER(&tmpint, (unsigned long)native)
64 : asn_long2INTEGER(&tmpint, native))
66 er = INTEGER_encode_aper(td, constraints, &tmpint, po);
67 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);