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 NativeReal_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
13 const asn_TYPE_descriptor_t *td,
14 const asn_per_constraints_t *constraints,
15 void **dbl_ptr, asn_per_data_t *pd) {
16 double *Dbl = (double *)*dbl_ptr;
25 * If the structure is not there, allocate it.
28 *dbl_ptr = CALLOC(1, sizeof(*Dbl));
29 Dbl = (double *)*dbl_ptr;
34 memset(&tmp, 0, sizeof(tmp));
35 rval = OCTET_STRING_decode_aper(opt_codec_ctx, td, NULL,
37 if(rval.code != RC_OK) {
38 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);
42 ret = asn_REAL2double(&tmp, Dbl);
43 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);
44 if(ret) ASN__DECODE_FAILED;
50 NativeReal_encode_aper(const asn_TYPE_descriptor_t *td,
51 const asn_per_constraints_t *constraints,
52 const void *sptr, asn_per_outp_t *po) {
53 double Dbl = *(const double *)sptr;
54 asn_enc_rval_t erval = {0,0,0};
59 /* Prepare a temporary clean structure */
60 memset(&tmp, 0, sizeof(tmp));
62 if(asn_double2REAL(&tmp, Dbl))
65 /* Encode a DER REAL */
66 erval = OCTET_STRING_encode_aper(td, NULL, &tmp, po);
67 if(erval.encoded == -1)
68 erval.structure_ptr = sptr;
70 /* Free possibly allocated members of the temporary structure */
71 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);