[vlc-devel] [PATCH v2 02/15] strings: add function to hex-encode binary data
Marvin Scholz
epirat07 at gmail.com
Wed Apr 8 00:04:18 CEST 2020
---
include/vlc_strings.h | 12 ++++++++++++
src/libvlccore.sym | 1 +
src/text/strings.c | 10 ++++++++++
3 files changed, 23 insertions(+)
diff --git a/include/vlc_strings.h b/include/vlc_strings.h
index 411f4a8ceb..e229b32d5d 100644
--- a/include/vlc_strings.h
+++ b/include/vlc_strings.h
@@ -118,6 +118,18 @@ VLC_API void vlc_xml_decode(char *st);
*/
VLC_API char *vlc_xml_encode(const char *str) VLC_MALLOC;
+/**
+ * Encode binary data as hex string
+ *
+ * Writes a given data buffer to the output buffer as a null terminated
+ * string in hexadecimal representation.
+ *
+ * \param input Input buffer
+ * \param size Input buffer size
+ * \param[out] output Output buffer to write the string to
+ */
+VLC_API void vlc_hex_encode_binary(const void *input, size_t size, char *output);
+
/**
* Base64 encoding.
*
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index cc8098edd9..17561db932 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -483,6 +483,7 @@ vlc_b64_decode_binary
vlc_b64_decode_binary_to_buffer
vlc_b64_encode
vlc_b64_encode_binary
+vlc_hex_encode_binary
vlc_cancel
vlc_clone
VLC_CompileBy
diff --git a/src/text/strings.c b/src/text/strings.c
index 658249f890..5180f16a83 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -346,6 +346,16 @@ char *vlc_xml_encode (const char *str)
return stream.ptr;
}
+/* Hex encoding */
+void vlc_hex_encode_binary(const void *input, size_t size, char *output)
+{
+ unsigned char *buffer = input;
+
+ for (size_t i = 0; i < size; i++) {
+ sprintf(&output[i * 2], "%02" PRIx8, buffer[i]);
+ }
+}
+
/* Base64 encoding */
char *vlc_b64_encode_binary(const void *src, size_t length)
{
--
2.24.1 (Apple Git-126)
More information about the vlc-devel
mailing list