Hexadecimal string codec
0

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 90.0%
Dune 2.6%
Other 7.3%
10 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-hex https://tangled.org/did:plc:44z6fz6ps2m7vutprh2d6llv
git@git.recoil.org:gazagnaire.org/ocaml-hex git@git.recoil.org:did:plc:44z6fz6ps2m7vutprh2d6llv

For self-hosted knots, clone URLs may differ based on your setup.



README.md

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 hex
  • Hex.decode / Hex.decode_into - hex to octets, validating first
  • Hex.required_length - decoded size of a hex string
  • Hex.encode_reads / Hex.decode_reads - bytesrw reader filters
  • Hex.encode_writes / Hex.decode_writes - bytesrw writer filters
  • Hex.pp / Hex.pp_hexdump - spaced hex and hexdump -C output

License#

ISC.