diff options
author | Damjan Marion <damarion@cisco.com> | 2023-04-16 11:12:22 +0000 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2023-04-17 10:53:27 +0000 |
commit | cbc0410d6223503a4deef0834d22a34f75e490e7 (patch) | |
tree | c5abff33444092e13cd190aca8649108273e517c | |
parent | 4621966638735a875f430522ad479aede67844a3 (diff) |
vppinfra: add format_hexdump_u{16,32,64}
Change-Id: I0eeccfc5739276d58a81a6552a043c6c105fe67a
Type: improvement
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | src/vppinfra/format.h | 3 | ||||
-rw-r--r-- | src/vppinfra/std-formats.c | 66 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h index a359328005f..935b57f2c4b 100644 --- a/src/vppinfra/format.h +++ b/src/vppinfra/format.h @@ -321,6 +321,9 @@ u8 *format_c_identifier (u8 * s, va_list * va); /* Format hexdump with both hex and printable chars - compatible with text2pcap */ u8 *format_hexdump (u8 * s, va_list * va); +u8 *format_hexdump_u16 (u8 *s, va_list *va); +u8 *format_hexdump_u32 (u8 *s, va_list *va); +u8 *format_hexdump_u64 (u8 *s, va_list *va); /* Format bitmap of array of uword numbers */ u8 *format_uword_bitmap (u8 *s, va_list *va); diff --git a/src/vppinfra/std-formats.c b/src/vppinfra/std-formats.c index 4605ed5d75c..7a51a531d31 100644 --- a/src/vppinfra/std-formats.c +++ b/src/vppinfra/std-formats.c @@ -456,6 +456,72 @@ format_hexdump (u8 * s, va_list * args) } __clib_export u8 * +format_hexdump_u16 (u8 *s, va_list *args) +{ + u16 *data = va_arg (*args, u16 *); + u32 len = va_arg (*args, u32); + u32 indent = format_get_indent (s); + + if (!len) + return s; + + for (int i = 0; i < len; i++) + { + if (i % 8 == 0) + { + s = format (s, "%s%U%05x: ", i ? "\n" : "", format_white_space, + i ? indent : 0, i * 2); + } + s = format (s, " %04lx", data[i]); + } + return s; +} + +__clib_export u8 * +format_hexdump_u32 (u8 *s, va_list *args) +{ + u32 *data = va_arg (*args, u32 *); + u32 len = va_arg (*args, u32); + u32 indent = format_get_indent (s); + + if (!len) + return s; + + for (int i = 0; i < len; i++) + { + if (i % 4 == 0) + { + s = format (s, "%s%U%05x: ", i ? "\n" : "", format_white_space, + i ? indent : 0, i * 4); + } + s = format (s, " %08lx", data[i]); + } + return s; +} + +__clib_export u8 * +format_hexdump_u64 (u8 *s, va_list *args) +{ + u64 *data = va_arg (*args, u64 *); + u32 len = va_arg (*args, u32); + u32 indent = format_get_indent (s); + + if (!len) + return s; + + for (int i = 0; i < len; i++) + { + if (i % 2 == 0) + { + s = format (s, "%s%U%05x: ", i ? "\n" : "", format_white_space, + i ? indent : 0, i * 8); + } + s = format (s, " %016lx", data[i]); + } + return s; +} + +__clib_export u8 * format_uword_bitmap (u8 *s, va_list *args) { uword *bitmap = va_arg (*args, uword *); |