hexyl icon indicating copy to clipboard operation
hexyl copied to clipboard

Add an option to output the result in C include file style

Open sorairolake opened this issue 10 months ago • 2 comments

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!");
}

sorairolake avatar Feb 20 '25 18:02 sorairolake

Sounds like a reasonable request, thank you.

sharkdp avatar Mar 02 '25 18:03 sharkdp

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!

wpcwzy avatar Apr 09 '25 12:04 wpcwzy