[vlc-devel] [PATCH v4 01/14] strings: add function to hex-encode binary data
Marvin Scholz
epirat07 at gmail.com
Wed Apr 15 13:35:16 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..930d3347fb 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 a96d9100ad..b27431dc80 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -480,6 +480,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..9676687aae 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)
+{
+ const unsigned char *buffer = input;
+
+ for (size_t i = 0; i < size; i++) {
+ sprintf(&output[i * 2], "%02hhx", 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