SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / NativeReal_xer.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 <NativeReal.h>
8 #include <REAL.h>
9
10 /*
11  * Decode the chunk of XML text encoding REAL.
12  */
13 asn_dec_rval_t
14 NativeReal_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
15                       const asn_TYPE_descriptor_t *td, void **sptr,
16                       const char *opt_mname, const void *buf_ptr, size_t size) {
17     asn_dec_rval_t rval;
18     REAL_t st = { 0, 0 };
19     REAL_t *stp = &st;
20
21     rval = REAL_decode_xer(opt_codec_ctx, td, (void **)&stp, opt_mname,
22                            buf_ptr, size);
23     if(rval.code == RC_OK) {
24         double d;
25         if(asn_REAL2double(&st, &d) || NativeReal__set(td, sptr, d) < 0) {
26             rval.code = RC_FAIL;
27             rval.consumed = 0;
28         }
29     } else {
30         /* Convert all errors into RC_FAIL */
31         rval.consumed = 0;
32     }
33     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &st);
34     return rval;
35 }
36
37 asn_enc_rval_t
38 NativeReal_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr,
39                       int ilevel, enum xer_encoder_flags_e flags,
40                       asn_app_consume_bytes_f *cb, void *app_key) {
41     double d = NativeReal__get_double(td, sptr);
42     asn_enc_rval_t er = {0,0,0};
43
44     (void)ilevel;
45
46     er.encoded = REAL__dump(d, flags & XER_F_CANONICAL, cb, app_key);
47     if(er.encoded < 0) ASN__ENCODE_FAILED;
48
49     ASN__ENCODED_OK(er);
50 }