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 <NativeReal.h>
9 #include <OCTET_STRING.h>
12 * Decode REAL type using PER.
15 NativeReal_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
16 const asn_TYPE_descriptor_t *td,
17 const asn_per_constraints_t *constraints, void **sptr,
27 memset(&tmp, 0, sizeof(tmp));
28 rval = OCTET_STRING_decode_uper(opt_codec_ctx, &asn_DEF_REAL,
30 if(rval.code != RC_OK) {
31 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);
35 ret = asn_REAL2double(&tmp, &d);
36 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);
37 if(ret) ASN__DECODE_FAILED;
39 if(NativeReal__set(td, sptr, d) < 0 )
46 * Encode the NativeReal using the OCTET STRING PER encoder.
49 NativeReal_encode_uper(const asn_TYPE_descriptor_t *td,
50 const asn_per_constraints_t *constraints,
51 const void *sptr, asn_per_outp_t *po) {
52 double d = NativeReal__get_double(td, sptr);
53 asn_enc_rval_t erval = {0,0,0};
58 /* Prepare a temporary clean structure */
59 memset(&tmp, 0, sizeof(tmp));
61 if(asn_double2REAL(&tmp, d))
64 /* Encode a DER REAL */
65 erval = OCTET_STRING_encode_uper(&asn_DEF_REAL, NULL, &tmp, po);
66 if(erval.encoded == -1)
67 erval.structure_ptr = sptr;
69 /* Free possibly allocated members of the temporary structure */
70 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);