Module Bin_there.Serialization Source Serialization state and serializer combinators.
This module provides the concrete serialization context and first-class serializers. Unlike previous versions, this is not a functor - it uses existential types to wrap output sinks.
A t is the mutable context that accumulates bytes into an output sink and maintains the per-type sharing tables used to detect aliased or cyclic values. It is created once per top-level serialization and threaded through every serializer.
A 'a serializer is an opaque value that knows how to write one 'a into the sink, including the sharing-id prefix required by the wire format.
Source type output = { add_uint8 : int -> unit; add_bytes : bytes -> unit; } Create an output wrapper from a Buffer.t.
Create an output wrapper from an out_channel.
Source val output_of : add_uint8 :(int -> unit) -> add_bytes :(bytes -> unit) -> output Create an output wrapper from individual functions.
The mutable serialization context. One value per top-level serialization.
Source val create : ?deduplicate_strings :bool -> output :output -> unit -> t create ?deduplicate_strings ~output () creates a fresh serialization context targeting output.
An opaque serializer for values of type 'a.
Source type 'a content_writer = t -> 'a -> unit The type of the function that writes a single value's content. It must not emit a sharing prefix - that is handled by write_value .
make_serializer ~serialization ?sharing_detector ~shared ~type_id ~content_writer () constructs a serializer.
Returns the optional string-deduplication state, or None if string deduplication was not requested.
write_value ~serialization ~serializer ~v writes v using serializer, emitting the sharing prefix (if any) before delegating to the content_writer.
write_raw_std_header ~serialization writes the standard file header.
Source val write_raw_varint : serialization :t -> int -> unitwrite_raw_varint ~serialization n appends n as an unsigned LEB128.
Source val write_raw_bytes : serialization :t -> bytes -> unitwrite_raw_bytes ~serialization b appends b verbatim.
Source val write_raw_int32_be : serialization :t -> int32 -> unitwrite_raw_int32_be ~serialization n writes n as big-endian 32-bit.
Source val write_raw_uint8 : serialization :t -> int -> unitwrite_raw_uint8 ~serialization b appends one byte.
write_raw_bigarray1 ~serialization b writes a bigarray.
through ~serialization ~post ~converter builds a serializer for 'a by first mapping through converter then delegating to post.
Source val serialize_mutable_collection :
serialization :t ->
element_serializer :'elem serializer ->
length :('coll -> int) ->
iter :(('elem -> unit) -> 'coll -> unit) ->
v :'coll ->
unitserialize_mutable_collection ... serializes a mutable collection.
Source val serialize_persistent_collection :
serialization :t ->
element_serializer :'elem serializer ->
length :('coll -> int) ->
iter :(('elem -> unit) -> 'coll -> unit) ->
v :'coll ->
unitserialize_persistent_collection ... serializes a persistent collection.