hexyl
hexyl copied to clipboard
Add an option to output the result in C include file style
I think it would be useful to have an option for hexyl that has the same purpose as the -i/-include option for the xxd command:
$ echo -n "Hello, world!" | xxd -i
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64,
0x21
This output can easily be embedded as an array in many programming languages:
fn main() {
let arr = [
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
];
let s = std::str::from_utf8(&arr).unwrap();
assert_eq!(s, "Hello, world!");
}
Sounds like a reasonable request, thank you.
I’m planning to work on implementing this feature. If anyone has any suggestions or thoughts on how it should be approached, I’d really appreciate your input. Thank you!