vlc | branch: master | Marvin Scholz <[email protected]> | Tue Apr 7 23:49:59 2020 +0200| [5f38902ab7e3c96c11830f6006b8cda661bc66aa] | committer: Marvin Scholz
strings: add function to hex-encode binary data > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5f38902ab7e3c96c11830f6006b8cda661bc66aa --- 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) { _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
