package hxd
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=4ede235296a5e2a2599776c8bceb4853c164ef7e573570a1edc68a4c0c90433e
sha512=39d42632ea7acc2e9418faefdef91085e420a03c3aa03e04e75f99c9d24a4deb96ff71ad948d208ce562077dd3f6f92f975dc7c006a97cd7eabc1e8a7f5381d0
doc/hxd.core/Hxd/index.html
Module Hxd
Source
HeXDump library for OCaml.
The library provides the most abstract way to serialize something to a human-readable hexdump. It allows the transmission of binary data in a `mail-safe' ASCII representation and it can handle colors if the given Format.formatter
supports it.
It permits to serialize to a caml value as a simple list of string
s or an array of string
s.
The type of colorschemes.
colorscheme_of_array arr
returns a colorscheme
from an array of 256 elements. Otherwise, it returns an invalid argument.
lowercase c style
sets lowercase ASCII values to the style style
.
uppercase c style
sets uppercase ASCII values to the style style
.
digit c style
sets digit ASCII values to the style style
.
code c code style
sets a specific ASCII code c
to the style style
.
The type of configurations.
xxd ?cols ?groupsize ?long ?uppercase colorscheme
returns a configuration which can be used by generate
then.
cols
: octets per line (default to 16)groupsize
: Separate the output of everygroupsize
bytes by a whitespace (default to 2).long
: stop after readinglen
octets.uppercase
: use upper case hex letters (default is lower case).colorscheme
:colorscheme
used if the givenFormat.formatter
supports it.
val caml :
?with_comments:bool ->
?cols:int ->
?long:int ->
?uppercase:bool ->
[ `List | `Array ] ->
cfg
caml ?with_comments ?cols ?long ?uppercase k
returns a configuration which can be used by generate
then. It allows to produces a caml value from something.
cols
: octets per line (default to 16)with_comments
: add a comment which pretty-line the group in a commentlong
: stop after readinglen
octets.k
: if the user wants to produce a list ofstring
s or an array ofstring
s.
val generate :
cfg ->
's scheduler ->
('i, bytes, 's, 'e) input ->
('o, string, 's, 'e) output ->
'i ->
'o ->
('i, 's, 'e) seek ->
[ `Absolute of int | `Relative of int ] ->
Format.formatter ->
((unit, 'e) result, 's) io
generate cfg scheduler input output ic oc seek pos ppf
is the most abstract way to produce an hex-dump output. According to arguments, we are able to read into ic
and write into oc
with respectively input
and output
.
seek
is used to manipulate the position in ic
according to the given position pos
.
ppf
is used to know if we support colors or not. generate
writes on it too and it takes care about pretty-printing boxes.
scheduler
depends on which scheduler you use. You need to create one over monads:
module Unix_scheduler = Hxd.Make(struct type 'a t = 'a end)
let unix_scheduler =
let open Unix_scheduler in
{ Hxd.bind= (fun x f -> f (prj x))
; return= inj }
generate cfg unix_scheduler ...
You can abstract LWT monads too:
module Lwt_scheduler = Hxd.Make (struct type 'a t = 'a Lwt.t end)
let lwt_scheduler =
let open Lwt.Infix in
let open Lwt_scheduler in
{
Hxd.bind= (fun f x -> inj (prj x >>= fun x -> prj (f x)))
; return= (fun x -> inj (Lwt.return x))
}
generate cfg lwt_scheduler
Such layers exist with hxd.unix
and hxd.lwt
.