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 <NativeInteger.h>
10 NativeInteger_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr,
11 int ilevel, enum jer_encoder_flags_e flags,
12 asn_app_consume_bytes_f *cb, void *app_key) {
13 const asn_INTEGER_specifics_t *specs =
14 (const asn_INTEGER_specifics_t *)td->specifics;
15 char scratch[32]; /* Enough for 64-bit int */
16 asn_enc_rval_t er = {0,0,0};
17 const long *native = (const long *)sptr;
22 if(!native) ASN__ENCODE_FAILED;
24 er.encoded = snprintf(scratch, sizeof(scratch),
25 (specs && specs->field_unsigned)
26 ? "%lu" : "%ld", *native);
27 if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch)
28 || cb(scratch, er.encoded, app_key) < 0)