summaryrefslogtreecommitdiffstats
path: root/src/NativeEnumerated.c
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2010-06-14 23:31:04 +0200
committerHarald Welte <laforge@gnumonks.org>2010-07-20 00:10:38 +0200
commitb9d517e75509c6c30e2fe8740b81f5c26d77f89e (patch)
treea26c1a5efd592d6cb2914db76ccf495d0554f2eb /src/NativeEnumerated.c
parent6264d3d94b1ba827a507433efa630d92145cb3cb (diff)
src: Add verbose pretty print for enumerated types
This is just much easier to read when reading the text dumps. Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'src/NativeEnumerated.c')
-rw-r--r--src/NativeEnumerated.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/NativeEnumerated.c b/src/NativeEnumerated.c
index 1554220..3184644 100644
--- a/src/NativeEnumerated.c
+++ b/src/NativeEnumerated.c
@@ -22,7 +22,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = {
"ENUMERATED", /* The ASN.1 type is still ENUMERATED */
"ENUMERATED",
NativeInteger_free,
- NativeInteger_print,
+ NativeEnumerated_print,
asn_generic_no_constraint,
NativeInteger_decode_ber,
NativeInteger_encode_der,
@@ -205,3 +205,30 @@ NativeEnumerated_encode_uper(asn_TYPE_descriptor_t *td,
_ASN_ENCODED_OK(er);
}
+int
+NativeEnumerated_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
+ asn_app_consume_bytes_f *cb, void *app_key) {
+ asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics;
+ const long *native = (const long *)sptr;
+ char scratch[256];
+ int ret;
+
+ (void)td; /* Unused argument */
+ (void)ilevel; /* Unused argument */
+
+ if(native) {
+ const asn_INTEGER_enum_map_t *map = INTEGER_map_value2enum(specs, *native);
+ if (map && map->enum_len && map->enum_name) {
+ ret = snprintf(scratch, sizeof(scratch),
+ "%s", map->enum_name);
+ } else {
+ ret = snprintf(scratch, sizeof(scratch),
+ (specs && specs->field_unsigned)
+ ? "%lu" : "%ld", *native);
+ }
+ assert(ret > 0 && (size_t)ret < sizeof(scratch));
+ return (cb(scratch, ret, app_key) < 0) ? -1 : 0;
+ } else {
+ return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
+ }
+}