NativeEnumerated_uper.c
Go to the documentation of this file.
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  */
8 
11  const asn_TYPE_descriptor_t *td,
12  const asn_per_constraints_t *constraints,
13  void **sptr, asn_per_data_t *pd) {
14  const asn_INTEGER_specifics_t *specs = td->specifics;
15  asn_dec_rval_t rval = { RC_OK, 0 };
16  long *native = (long *)*sptr;
17  const asn_per_constraint_t *ct;
18  long value;
19 
20  (void)opt_codec_ctx;
21 
22  if(constraints) ct = &constraints->value;
25  else ASN__DECODE_FAILED; /* Mandatory! */
26  if(!specs) ASN__DECODE_FAILED;
27 
28  if(!native) {
29  native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
30  if(!native) ASN__DECODE_FAILED;
31  }
32 
33  ASN_DEBUG("Decoding %s as NativeEnumerated", td->name);
34 
35  if(ct->flags & APC_EXTENSIBLE) {
36  int inext = per_get_few_bits(pd, 1);
37  if(inext < 0) ASN__DECODE_STARVED;
38  if(inext) ct = 0;
39  }
40 
41  if(ct && ct->range_bits >= 0) {
42  value = per_get_few_bits(pd, ct->range_bits);
43  if(value < 0) ASN__DECODE_STARVED;
44  if(value >= (specs->extension
45  ? specs->extension - 1 : specs->map_count))
47  } else {
48  if(!specs->extension)
50  /*
51  * X.691, #10.6: normally small non-negative whole number;
52  */
53  value = uper_get_nsnnwn(pd);
54  if(value < 0) ASN__DECODE_STARVED;
55  value += specs->extension - 1;
56  if(value >= specs->map_count)
58  }
59 
60  *native = specs->value2enum[value].nat_value;
61  ASN_DEBUG("Decoded %s = %ld", td->name, *native);
62 
63  return rval;
64 }
65 
68  const asn_per_constraints_t *constraints,
69  const void *sptr, asn_per_outp_t *po) {
70  const asn_INTEGER_specifics_t *specs =
72  asn_enc_rval_t er = {0,0,0};
73  long native, value;
74  const asn_per_constraint_t *ct;
75  int inext = 0;
77  const asn_INTEGER_enum_map_t *kf;
78 
79  if(!sptr) ASN__ENCODE_FAILED;
80  if(!specs) ASN__ENCODE_FAILED;
81 
82  if(constraints) ct = &constraints->value;
83  else if(td->encoding_constraints.per_constraints)
84  ct = &td->encoding_constraints.per_constraints->value;
85  else ASN__ENCODE_FAILED; /* Mandatory! */
86 
87  ASN_DEBUG("Encoding %s as NativeEnumerated", td->name);
88 
89  er.encoded = 0;
90 
91  native = *(const long *)sptr;
92 
93  key.nat_value = native;
94  kf = bsearch(&key, specs->value2enum, specs->map_count,
96  if(!kf) {
97  ASN_DEBUG("No element corresponds to %ld", native);
99  }
100  value = kf - specs->value2enum;
101 
102  if(ct->range_bits >= 0) {
103  int cmpWith = specs->extension
104  ? specs->extension - 1 : specs->map_count;
105  if(value >= cmpWith)
106  inext = 1;
107  }
108  if(ct->flags & APC_EXTENSIBLE) {
109  if(per_put_few_bits(po, inext, 1))
111  if(inext) ct = 0;
112  } else if(inext) {
114  }
115 
116  if(ct && ct->range_bits >= 0) {
117  if(per_put_few_bits(po, value, ct->range_bits))
119  ASN__ENCODED_OK(er);
120  }
121 
122  if(!specs->extension)
124 
125  /*
126  * X.691, #10.6: normally small non-negative whole number;
127  */
128  ASN_DEBUG("value = %ld, ext = %d, inext = %d, res = %ld",
129  value, specs->extension, inext,
130  value - (inext ? (specs->extension - 1) : 0));
131  if(uper_put_nsnnwn(po, value - (inext ? (specs->extension - 1) : 0)))
133 
134  ASN__ENCODED_OK(er);
135 }
asn_bit_outp_s
Definition: asn_bit_data.h:56
asn_INTEGER_specifics_s::extension
int extension
Definition: INTEGER.h:32
ASN__ENCODED_OK
#define ASN__ENCODED_OK(rval)
Definition: asn_codecs.h:67
uper_put_nsnnwn
int uper_put_nsnnwn(asn_per_outp_t *po, int n)
Definition: uper_support.c:101
asn_TYPE_descriptor_s::name
const char * name
Definition: constr_TYPE.h:225
asn_enc_rval_s
Definition: asn_codecs.h:41
NativeEnumerated.h
NativeEnumerated_decode_uper
asn_dec_rval_t NativeEnumerated_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, const asn_TYPE_descriptor_t *td, const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd)
Definition: NativeEnumerated_uper.c:10
CALLOC
#define CALLOC(nmemb, size)
Definition: asn_internal.h:37
per_get_few_bits
#define per_get_few_bits(data, bits)
Definition: per_support.h:39
asn_per_constraints_s::value
asn_per_constraint_t value
Definition: per_support.h:31
asn_per_constraint_s
Definition: per_support.h:18
NativeEnumerated__compar_value2enum
int NativeEnumerated__compar_value2enum(const void *ap, const void *bp)
Definition: NativeEnumerated.c:105
NativeEnumerated_encode_uper
asn_enc_rval_t NativeEnumerated_encode_uper(const asn_TYPE_descriptor_t *td, const asn_per_constraints_t *constraints, const void *sptr, asn_per_outp_t *po)
Definition: NativeEnumerated_uper.c:67
asn_bit_data_s
Definition: asn_bit_data.h:17
ASN__ENCODE_FAILED
#define ASN__ENCODE_FAILED
Definition: asn_codecs.h:59
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
asn_TYPE_descriptor_s::specifics
const void * specifics
Definition: constr_TYPE.h:259
asn_INTEGER_specifics_s::map_count
int map_count
Definition: INTEGER.h:31
asn_INTEGER_specifics_s
Definition: INTEGER.h:28
RC_OK
@ RC_OK
Definition: asn_codecs.h:82
asn_INTEGER_enum_map_s::nat_value
long nat_value
Definition: INTEGER.h:22
ASN__DECODE_STARVED
#define ASN__DECODE_STARVED
Definition: asn_codecs.h:97
asn_encoding_constraints_s::per_constraints
const struct asn_per_constraints_s * per_constraints
Definition: constr_TYPE.h:213
key
static void ssize_t void * key
Definition: asn_internal.h:96
asn_internal.h
asn_codec_ctx_s
Definition: asn_codecs.h:23
asn_dec_rval_s
Definition: asn_codecs.h:86
ASN__DECODE_FAILED
#define ASN__DECODE_FAILED
Definition: asn_codecs.h:90
asn_per_constraint_s::range_bits
int range_bits
Definition: per_support.h:25
asn_per_constraints_s
Definition: per_support.h:30
asn_TYPE_descriptor_s::encoding_constraints
asn_encoding_constraints_t encoding_constraints
Definition: constr_TYPE.h:247
asn_INTEGER_specifics_s::value2enum
const asn_INTEGER_enum_map_t * value2enum
Definition: INTEGER.h:29
asn_per_constraint_s::flags
enum asn_per_constraint_s::asn_per_constraint_flags flags
uper_get_nsnnwn
ssize_t uper_get_nsnnwn(asn_per_data_t *pd)
Definition: uper_support.c:75
per_put_few_bits
#define per_put_few_bits(out, bits, obits)
Definition: per_support.h:46
asn_INTEGER_enum_map_s
Definition: INTEGER.h:21


etsi_its_vam_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:30:55