package b0
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0
doc/b0.std/B0_bincode/index.html
Module B0_bincode
Source
Binary coding of values.
Encoders
The type for encoders of values of type 'a
. The call enc b v
must encode v
in buffer b
.
Decoders
The type for decoders of values of type 'a
. The call dec s i
must decode a value in s
starting at i
(which may be String.length s
) and return the index of the byte in s
after the decoded value (this can be String.length s
). The function must raise Failure
in case of error, use err
for this.
err i fmt
reports a decoding error for position i
formatted according to fmt
.
err_byte ~kind i byte
report an error for the unexpected byte byte
at position i
for decoding a value of type kind
.
get_byte s i
is the byte s.[i]
. Does not check that i
is in bounds.
dec_eoi s i
asserts that i
is exactly at the end of input, i.e. String.length s
.
Codecs
The type for encoding and decoding values of type 'a
.
make enc dec
is a decoder using enc
to encode and dec
to decode.
encode c v
encodes v
using c
(and buf
if provided, it is the client's duty to reset it before an encoding).
of_string ~file c s
decodes a value from s
using c
and dec_eoi
. In case of error file
is mentioned in the error message (defaults to B0_std.Fpath.dash
).
Base codecs
Magic numbers
dec_magic m
decodes magic number m
and returns the next index to read from.
Bytes
dec_byte
decodes a byte for a value of type kind
(used with err_byte
)
byte
codecs a byte for a value of type kind
(used with err_byte
).
unit
bool
int
enc_int
encodes an integer. The encoding does not depend on Sys.word_size
.
dec_int
dedodes an integer. Warning. An int
encoded on a 64-bit platform may end up being truncated if read back on 32-bit platform.
int64
string
Fpath.t
enc_fpath
encodes an B0_std.Fpath.t
.
dec_fpath
decodes an B0_std.Fpath.t
.
fpath
is a coded for !B0_std.Fpath.t
.
list
option
enc_option enc
encodes an option using enc
for the Some
case value.
dec_option dec
decodes an option using dec
for the Some
case value.
option c
is a codec for options with Some
elements coded with c
.
result
enc_result ~ok ~error
encodes a result value with the corresponding case encoders.
dec_result ~ok ~error
decodes a result value with the corresponding case decoders.
result
is a codec for results with Ok
elements coded with ok
and Error
elements coded with error
.
Set.t
enc_set (module S) enc
encodes S.t
sets using enc
for its elements.
dec_set (module S) dec
decodes S.t
sets with dec
for its elements.
set (module S) c
is a codec for S.t
sets using c
for its elements.
B0_hash.t
Mtime.Span.t
enc_mtime_span
encodes a B0_std.Mtime.Span.t
.
dec_mtime_span
decodes a B0_std.Mtime.Span.t
.
mtime_span
is a codec for B0_std.Mtime.Span.t
.
Os.Cpu.Time.Span.t
enc_cpu_time_span
encodes a B0_std.Os.Cpu.Time.Span.t
.
dec_cpu_time_span
decodes a B0_std.Os.Cpu.Time.Span.t
.
cpu_time_span
is a codec for B0_std.Os.Cpu.Time.Span.t
.