diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-27 17:48:22 -0400 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-27 19:23:14 -0400 |
commit | 65534dca5e71cd81070e2e464060f023b9868600 (patch) | |
tree | bc2b1b7c18c8b811b3ecb644e55cf894b27de401 | |
parent | 148deaba00b5710135ebf4f6ff0577d4a9483654 (diff) |
libmisc: fmt: Add hbyte and hmem
-rw-r--r-- | libmisc/fmt.c | 11 | ||||
-rw-r--r-- | libmisc/include/libmisc/fmt.h | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/libmisc/fmt.c b/libmisc/fmt.c index d3ca14a..a8baa84 100644 --- a/libmisc/fmt.c +++ b/libmisc/fmt.c @@ -28,6 +28,17 @@ void fmt_print_strn(lo_interface fmt_dest w, const char *str, size_t size) { fmt_print_byte(w, *(str++)); } +void fmt_print_hmem(lo_interface fmt_dest w, const void *_str, size_t size) { + const uint8_t *str = _str; + fmt_print_byte(w, '{'); + for (size_t i = 0; i < size; i++) { + if (i) + fmt_print_byte(w, ','); + fmt_print_hbyte(w, str[i]); + } + fmt_print_byte(w, '}'); +} + void fmt_print_byte(lo_interface fmt_dest w, uint8_t b) { LO_CALL(w, putb, b); } diff --git a/libmisc/include/libmisc/fmt.h b/libmisc/include/libmisc/fmt.h index 4abe730..c0743ff 100644 --- a/libmisc/include/libmisc/fmt.h +++ b/libmisc/include/libmisc/fmt.h @@ -34,6 +34,10 @@ void fmt_print_qmem(lo_interface fmt_dest w, const void *str, size_t size); void fmt_print_qstr(lo_interface fmt_dest w, const char *str); void fmt_print_qstrn(lo_interface fmt_dest w, const char *str, size_t size); +/* Hex bytes. */ +#define fmt_print_hbyte fmt_print_base16_u8_ +void fmt_print_hmem(lo_interface fmt_dest w, const void *str, size_t size); + /* Integers. */ #define _fmt_declare_base(base) \ void _fmt_print_base##base##_u8(lo_interface fmt_dest w, uint8_t val); \ |