[aravis] gvcp: move the hex dump code to arv_g_string_append_hex_dump.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] gvcp: move the hex dump code to arv_g_string_append_hex_dump.
- Date: Thu, 28 Jun 2012 15:19:11 +0000 (UTC)
commit 30e7e4bdea0883855232a75322585463a3b8ef61
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Thu Jun 28 17:18:16 2012 +0200
gvcp: move the hex dump code to arv_g_string_append_hex_dump.
docs/reference/aravis/aravis-sections.txt | 1 +
src/arvgvcp.c | 30 ++----------------
src/arvstr.c | 46 +++++++++++++++++++++++++++++
src/arvstr.h | 2 +
4 files changed, 53 insertions(+), 26 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 1de2eb1..fc23f58 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -573,6 +573,7 @@ arv_stream_get_n_buffers
arv_stream_get_statistics
arv_stream_get_emit_signals
arv_stream_set_emit_signals
+arv_g_string_append_hex_dump
<SUBSECTION Standard>
ARV_STREAM
ARV_IS_STREAM
diff --git a/src/arvgvcp.c b/src/arvgvcp.c
index 5a479a0..6381e1c 100644
--- a/src/arvgvcp.c
+++ b/src/arvgvcp.c
@@ -29,6 +29,7 @@
#include <arvenumtypes.h>
#include <string.h>
#include <arvdebug.h>
+#include <arvstr.h>
void
arv_gvcp_packet_free (ArvGvcpPacket *packet)
@@ -452,7 +453,7 @@ arv_gvcp_packet_to_string (const ArvGvcpPacket *packet)
GString *string;
char *c_string;
char *data;
- int i, j, packet_size, index;
+ int packet_size;
guint32 value;
g_return_val_if_fail (packet != NULL, NULL);
@@ -518,31 +519,8 @@ arv_gvcp_packet_to_string (const ArvGvcpPacket *packet)
}
packet_size = sizeof (ArvGvcpHeader) + g_ntohs (packet->header.size);
- for (i = 0; i < (packet_size + 15) / 16; i++) {
- for (j = 0; j < 16; j++) {
- index = i * 16 + j;
- if (j == 0)
- g_string_append_printf (string, "%04x", i * 16);
- if (index < packet_size)
- g_string_append_printf (string, " %02x", *((guint8 *) ((void *) packet) + index));
- else
- g_string_append (string, " ");
- }
- for (j = 0; j < 16; j++) {
- index = i * 16 + j;
- if (j == 0)
- g_string_append (string, " ");
- if (index < packet_size)
- if (*((char *) ((void *) packet) + index) >= ' ' &&
- *((char *) ((void *) packet) + index) < '\x7f')
- g_string_append_c (string, *((char *) ((void *) packet) + index));
- else g_string_append_c (string, '.');
- else
- g_string_append_c (string, ' ');
- }
- if (index < packet_size)
- g_string_append (string, "\n");
- }
+
+ arv_g_string_append_hex_dump (string, packet, packet_size);
c_string = string->str;
diff --git a/src/arvstr.c b/src/arvstr.c
index a1e5627..1af7fca 100644
--- a/src/arvstr.c
+++ b/src/arvstr.c
@@ -191,3 +191,49 @@ arv_str_parse_double_list (char **str, unsigned int n_values, double *values)
return i;
}
+/**
+ * arv_g_string_append_hex_dump:
+ * @string: a #GString
+ * @data: binary data
+ * @size: size of binary data
+ *
+ * Adds an hexadecimal dump of @data to @string, which consists in lines displaying the data adress, 16 8 bit values in hexadecimal representation, followed by their corresponding ASCII character (replaced by a dot for control ones).
+ *
+ * Here is an example of the output:
+ *
+ * 01e0 c8 b7 89 b0 45 fa 3d 9d 8c e9 a7 33 46 85 1f 2c ....E.=....3F..,
+ * 01f0 3f 4c ba 8d 99 f3 ff d0 40 78 73 37 32 e5 4f 9f ?L xs72 O
+ * 0200 d0 d2 f2 ef 5a 2f fc 61 e3 64 36 21 ....Z/.a.d6!
+ */
+
+void
+arv_g_string_append_hex_dump (GString *string, const void *data, size_t size)
+{
+ guint64 i, j, index;
+
+ for (i = 0; i < (size + 15) / 16; i++) {
+ for (j = 0; j < 16; j++) {
+ index = i * 16 + j;
+ if (j == 0)
+ g_string_append_printf (string, "%08" G_GUINT64_FORMAT, i * 16);
+ if (index < size)
+ g_string_append_printf (string, " %02x", *((guint8 *) data + index));
+ else
+ g_string_append (string, " ");
+ }
+ for (j = 0; j < 16; j++) {
+ index = i * 16 + j;
+ if (j == 0)
+ g_string_append (string, " ");
+ if (index < size)
+ if (*((char *) data + index) >= ' ' &&
+ *((char *) data + index) < '\x7f')
+ g_string_append_c (string, *((char *) data + index));
+ else g_string_append_c (string, '.');
+ else
+ g_string_append_c (string, ' ');
+ }
+ if (index < size)
+ g_string_append (string, "\n");
+ }
+}
diff --git a/src/arvstr.h b/src/arvstr.h
index e886975..2a0006e 100644
--- a/src/arvstr.h
+++ b/src/arvstr.h
@@ -69,6 +69,8 @@ arv_str_skip_colon_and_spaces (char **str)
(*str)++;
}
+void arv_g_string_append_hex_dump (GString *string, const void *data, size_t size);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]