NativeInteger_jer.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 
9 /*
10  * Decode the chunk of JSON text encoding INTEGER.
11  */
14  const asn_TYPE_descriptor_t *td,
15  const asn_jer_constraints_t* constraints,
16  void **sptr, const void *buf_ptr,
17  size_t size) {
18  const asn_INTEGER_specifics_t *specs =
20  asn_dec_rval_t rval;
21  INTEGER_t st;
22  void *st_ptr = (void *)&st;
23  long *native = (long *)*sptr;
24 
25  if(!native) {
26  native = (long *)(*sptr = CALLOC(1, sizeof(*native)));
27  if(!native) ASN__DECODE_FAILED;
28  }
29 
30  memset(&st, 0, sizeof(st));
31  rval = INTEGER_decode_jer(opt_codec_ctx, td, constraints, &st_ptr, buf_ptr, size);
32  if(rval.code == RC_OK) {
33  long l;
34  if((specs&&specs->field_unsigned)
35  ? asn_INTEGER2ulong(&st, (unsigned long *)&l) /* sic */
36  : asn_INTEGER2long(&st, &l)) {
37  rval.code = RC_FAIL;
38  rval.consumed = 0;
39  } else {
40  *native = l;
41  }
42  } else {
43  /*
44  * Cannot restart from the middle;
45  * there is no place to save state in the native type.
46  * Request a continuation from the very beginning.
47  */
48  rval.consumed = 0;
49  }
51  return rval;
52 }
53 
56  const asn_jer_constraints_t* constraints,
57  const void *sptr, int ilevel,
58  enum jer_encoder_flags_e flags,
59  asn_app_consume_bytes_f *cb, void *app_key) {
60  const asn_INTEGER_specifics_t *specs =
62  char scratch[32]; /* Enough for 64-bit int */
63  asn_enc_rval_t er = {0,0,0};
64  const long *native = (const long *)sptr;
65 
66  (void)ilevel;
67  (void)flags;
68 
69  if(!native) ASN__ENCODE_FAILED;
70 
71  er.encoded = snprintf(scratch, sizeof(scratch),
72  (specs && specs->field_unsigned)
73  ? "%lu" : "%ld", *native);
74  if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch)
75  || cb(scratch, er.encoded, app_key) < 0)
77 
78  ASN__ENCODED_OK(er);
79 }
ASN__PRIMITIVE_TYPE_s
Definition: asn_codecs_prim.h:14
ASN__ENCODED_OK
#define ASN__ENCODED_OK(rval)
Definition: asn_codecs.h:67
asn_jer_constraints_s
Definition: jer_support.h:18
asn_enc_rval_s
Definition: asn_codecs.h:41
jer_encoder_flags_e
jer_encoder_flags_e
Definition: jer_encoder.h:20
CALLOC
#define CALLOC(nmemb, size)
Definition: asn_internal.h:37
asn_DEF_INTEGER
asn_TYPE_descriptor_t asn_DEF_INTEGER
Definition: INTEGER.c:75
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
Definition: INTEGER.h:28
RC_OK
@ RC_OK
Definition: asn_codecs.h:82
INTEGER_decode_jer
jer_type_decoder_f INTEGER_decode_jer
Definition: INTEGER.h:65
NativeInteger_decode_jer
asn_dec_rval_t NativeInteger_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, const asn_TYPE_descriptor_t *td, const asn_jer_constraints_t *constraints, void **sptr, const void *buf_ptr, size_t size)
Definition: NativeInteger_jer.c:13
asn_app_consume_bytes_f
int() asn_app_consume_bytes_f(const void *buffer, size_t size, void *application_specific_key)
Definition: asn_application.h:124
asn_internal.h
NativeInteger_encode_jer
asn_enc_rval_t NativeInteger_encode_jer(const asn_TYPE_descriptor_t *td, const asn_jer_constraints_t *constraints, const void *sptr, int ilevel, enum jer_encoder_flags_e flags, asn_app_consume_bytes_f *cb, void *app_key)
Definition: NativeInteger_jer.c:55
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_INTEGER2ulong
int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l)
Definition: INTEGER.c:399
asn_INTEGER_specifics_s::field_unsigned
int field_unsigned
Definition: INTEGER.h:35
ASN_STRUCT_FREE_CONTENTS_ONLY
#define ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr)
Definition: constr_TYPE.h:123
asn_INTEGER2long
int asn_INTEGER2long(const INTEGER_t *i, long *l)
Definition: INTEGER.c:384
NativeInteger.h
RC_FAIL
@ RC_FAIL
Definition: asn_codecs.h:84


etsi_its_spatem_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:29:28