diff mbox series

lib: fwts_dump_data: add library function for dumping all raw data with prefix

Message ID 20230612101357.60792-1-ivan.hu@canonical.com
State Accepted
Headers show
Series lib: fwts_dump_data: add library function for dumping all raw data with prefix | expand

Commit Message

ivanhu June 12, 2023, 10:13 a.m. UTC
BugLink: https://bugs.launchpad.net/fwts/+bug/2023542

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/lib/include/fwts_dump_data.h |  2 +-
 src/lib/src/fwts_dump_data.c     | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/lib/include/fwts_dump_data.h b/src/lib/include/fwts_dump_data.h
index 5e255754..c2e01606 100644
--- a/src/lib/include/fwts_dump_data.h
+++ b/src/lib/include/fwts_dump_data.h
@@ -24,5 +24,5 @@ 
 
 void fwts_dump_raw_data(char *buffer, const size_t len, const uint8_t *data, const int where, const size_t bytes);
 void fwts_dump_raw_data_prefix(char *buffer, const size_t len, const uint8_t *data, const char *prefix, const size_t bytes);
-
+void fwts_hexdump_data_prefix_all(fwts_framework *fw, const uint8_t *data, const char *prefix,	const size_t nbytes);
 #endif
diff --git a/src/lib/src/fwts_dump_data.c b/src/lib/src/fwts_dump_data.c
index 60287a9d..251e2668 100644
--- a/src/lib/src/fwts_dump_data.c
+++ b/src/lib/src/fwts_dump_data.c
@@ -87,3 +87,27 @@  void fwts_dump_raw_data_prefix(
 
 	buffer[n] = '\0';
 }
+
+/*
+ *  fwts_hexdump_data_prefix_all()
+ *	print all raw uint8 data of length `nbytes` as a hex dump with prefix.
+ *	The prefix could be used as alighment.
+ */
+void fwts_hexdump_data_prefix_all(
+	fwts_framework *fw,
+	const uint8_t *data,	/* Octects to dump */
+	const char *prefix,	/* Prefix string or for alignment for each line */
+	const size_t nbytes)	/* Number of bytes to dump for all data */
+{
+
+	size_t i;
+
+	for (i = 0; i < nbytes; i += 16) {
+		char buffer[128];
+		const size_t left = nbytes - i;
+
+		fwts_dump_raw_data_prefix(buffer, sizeof(buffer), data + i, prefix, left > 16 ? 16 : left);
+		fwts_log_info_verbatim(fw, "%s", buffer);
+	}
+}
+