SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / BOOLEAN_uper.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 <BOOLEAN.h>
8
9 asn_dec_rval_t
10 BOOLEAN_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,
13                     asn_per_data_t *pd) {
14     asn_dec_rval_t rv;
15     BOOLEAN_t *st = (BOOLEAN_t *)*sptr;
16
17     (void)opt_codec_ctx;
18     (void)td;
19     (void)constraints;
20
21     if(!st) {
22         st = (BOOLEAN_t *)(*sptr = MALLOC(sizeof(*st)));
23         if(!st) ASN__DECODE_FAILED;
24     }
25
26     /*
27      * Extract a single bit
28      */
29     switch(per_get_few_bits(pd, 1)) {
30     case 1: *st = 1; break;
31     case 0: *st = 0; break;
32     case -1: default: ASN__DECODE_STARVED;
33     }
34
35     ASN_DEBUG("%s decoded as %s", td->name, *st ? "TRUE" : "FALSE");
36
37     rv.code = RC_OK;
38     rv.consumed = 1;
39     return rv;
40 }
41
42
43 asn_enc_rval_t
44 BOOLEAN_encode_uper(const asn_TYPE_descriptor_t *td,
45                     const asn_per_constraints_t *constraints, const void *sptr,
46                     asn_per_outp_t *po) {
47     const BOOLEAN_t *st = (const BOOLEAN_t *)sptr;
48     asn_enc_rval_t er = { 0, 0, 0 };
49
50     (void)constraints;
51
52     if(!st) ASN__ENCODE_FAILED;
53
54     if(per_put_few_bits(po, *st ? 1 : 0, 1))
55         ASN__ENCODE_FAILED;
56
57     ASN__ENCODED_OK(er);
58 }