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 * INTEGER specific human-readable output.
13 NativeInteger_print(const asn_TYPE_descriptor_t *td, const void *sptr,
14 int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
15 const asn_INTEGER_specifics_t *specs =
16 (const asn_INTEGER_specifics_t *)td->specifics;
17 const long *native = (const long *)sptr;
18 char scratch[32]; /* Enough for 64-bit int */
21 (void)td; /* Unused argument */
22 (void)ilevel; /* Unused argument */
26 ret = snprintf(scratch, sizeof(scratch),
27 (specs && specs->field_unsigned) ? "%lu" : "%ld", value);
28 assert(ret > 0 && (size_t)ret < sizeof(scratch));
29 if(cb(scratch, ret, app_key) < 0) return -1;
30 if(specs && (value >= 0 || !specs->field_unsigned)) {
31 const asn_INTEGER_enum_map_t *el =
32 INTEGER_map_value2enum(specs, value);
34 if(cb(" (", 2, app_key) < 0) return -1;
35 if(cb(el->enum_name, el->enum_len, app_key) < 0) return -1;
36 if(cb(")", 1, app_key) < 0) return -1;
41 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;