nox-hex#
Hexadecimal string codec (RFC 4648 base16): encode and decode between octet strings and their hex rendering, with bytesrw stream filters and hexdump pretty-printers. Adapted from ohex (Hannes Mehnert, BSD-2-Clause) and API-compatible with it.
Installation#
Install with opam:
$ opam install nox-hex
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install nox-hex
Usage#
# Hex.encode "AB";;
- : string = "4142"
# Hex.decode "41 42";;
- : string = "AB"
# Hex.required_length "4142";;
- : int = 2
Decoding accepts both digit cases and, by default, skips whitespace;
an invalid character or an odd digit count raises Invalid_argument.
API#
Hex.encode/Hex.encode_into- octets to lowercase hexHex.decode/Hex.decode_into- hex to octets, validating firstHex.required_length- decoded size of a hex stringHex.encode_reads/Hex.decode_reads- bytesrw reader filtersHex.encode_writes/Hex.decode_writes- bytesrw writer filtersHex.pp/Hex.pp_hexdump- spaced hex andhexdump -Coutput
License#
ISC.