Module Hex
Hexadecimal encoding.
Hex
defines hexadecimal encodings for characters, strings and Cstruct.t buffers.
Characters
Strings
val of_string : ?ignore:char list -> string -> t
of_string s
is the hexadecimal representation of the binary strings
. Ifignore
is set, skip the characters in the list when converting. Egof_string ~ignore:[' '] "a f"
. The default value ofignore
is[]
).
val to_string : t -> string
to_string t
is the binary strings
such thatof_string s
ist
.
Bytes
val of_bytes : ?ignore:char list -> bytes -> t
of_bytes s
is the hexadecimal representation of the binary strings
. Ifignore
is set, skip the characters in the list when converting. Egof_bytes ~ignore:[' '] "a f"
. The default value ofignore
is[]
).
val to_bytes : t -> bytes
to_bytes t
is the binary strings
such thatof_bytes s
ist
.
Cstruct
val of_cstruct : ?ignore:char list -> Cstruct.t -> t
of_cstruct buf
is the hexadecimal representation of the bufferbuf
.
val to_cstruct : t -> Cstruct.t
to_cstruct t
is the bufferb
such thatof_cstruct b
ist
.
Bigstring
val of_bigstring : ?ignore:char list -> Cstruct.buffer -> t
of_bigstring buf
is the hexadecimal representation of the bufferbuf
.
val to_bigstring : t -> Cstruct.buffer
to_bigstring t
is the bufferb
such thatof_bigstring b
ist
.
Debugging
val hexdump : ?print_row_numbers:bool -> ?print_chars:bool -> t -> unit
hexdump h
dumps the hex encoding to stdout in the following format:00000000: 6865 6c6c 6f20 776f 726c 6420 6865 6c6c hello world hell 00000010: 6f20 776f 726c 640a o world.
This is the same format as emacs hexl-mode, and is a very similar format to hexdump -C. '\t' and '\n' are printed as '.'.in the char column.
print_row_numbers
andprint_chars
both default totrue
. Setting either tofalse
does not print the column.
val hexdump_s : ?print_row_numbers:bool -> ?print_chars:bool -> t -> string
Same as
hexdump
except returns a string.
Pretty printing
val pp : Stdlib.Format.formatter -> t -> unit
pp fmt t
will output a human-readable hex representation oft
to the formatterfmt
.
val show : t -> string
show t
will return a human-readable hex representation oft
as a string.