aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2015-08-31 08:43:36 +0200
committerHarald Welte <laforge@gnumonks.org>2015-08-31 08:43:36 +0200
commit485a972a43775cf10b1fdf65c5e75fe47a03b3e9 (patch)
tree480e6bd0da6b8fcbc1e34a6ccd0bdeb447f8de59
parent36cd7dd18f92113467b7c94aab8fe7e0e543ca1f (diff)
skeletons: Add verbose pretty print for enumerated types
This is just much easier to read when reading the text dumps.
-rw-r--r--skeletons/NativeEnumerated.c29
-rw-r--r--skeletons/NativeEnumerated.h1
2 files changed, 29 insertions, 1 deletions
diff --git a/skeletons/NativeEnumerated.c b/skeletons/NativeEnumerated.c
index 4df925e4..124e7f0f 100644
--- a/skeletons/NativeEnumerated.c
+++ b/skeletons/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,
@@ -331,3 +331,30 @@ NativeEnumerated_encode_aper(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;
+ }
+}
diff --git a/skeletons/NativeEnumerated.h b/skeletons/NativeEnumerated.h
index 95f05312..9db2611a 100644
--- a/skeletons/NativeEnumerated.h
+++ b/skeletons/NativeEnumerated.h
@@ -26,6 +26,7 @@ per_type_decoder_f NativeEnumerated_decode_uper;
per_type_encoder_f NativeEnumerated_encode_uper;
per_type_decoder_f NativeEnumerated_decode_aper;
per_type_encoder_f NativeEnumerated_encode_aper;
+asn_struct_print_f NativeEnumerated_print;
#ifdef __cplusplus
}