Throughout my work, I’ve systematically wanted to introspect formats & protocols in order to implement them (such as Git formats, Zlib or SMTP). But these formats & protocols are not so easy readable for a human.
Of course, several tools exist to “dump” a content: hexdump or xxd.
However, it seems that the new fashion is to use color codes to display content. The human eye seems more receptive to a colorful world rather than a monochrome universe. Thus, to embellish my life and my work, I developed a small tool that allows you to “dump” content with colors:
This is very inspired from pixd & hexd but in OCaml! hxd is focused on performances and is comparable to xxd. The program has almost the same options as xxd. One interesting option is -s, with this option, it’s possible to seek you in a file or stream and extract part of it. For more details, you can see some examples in the test suite.
Of course, hxd foes further! In this introspection of formats & protocols, it may be interesting to re-export them in OCaml to embellish your tests for example:
The code produced can be directly compiled with OCaml. There are various options such as exporting to an array and adding comments.
Finally, hxd is not only a simple program, it is also a library. The goal is to be able to get the same result as the program but in your libraries using Format. hxd offers different ways to display content: with Format, using in_channel/out_channel or with LWT
Have fun with this program, and I hope that, like me, you will have more fun to debug machine formats & protocols.



