Module Imandrakit_ser_pack

ser-pack.

ser-pack is a data serialization scheme built on top of Imandrakit_ser. It introduces a notion of heap (an array of ser-values) and pointers into this heap (ser-values consisting of an integer wrapped in a specific tag). The heap is then turned into an array of ser-values, so that the resulting "pack" is just a single large ser-value with a specific internal structure (some of which are pointers into the large internal heap).

When serializing a complex data structure that presents internal sharing (typically, with pointers/references), the heap can be used to represent that sharing directly in the ser-value. This is done by serializing a value once, adding it to the heap (which is an array); the position of the ser-value in the heap can then be wrapped with tag 6 to become a pointer. All other references to this value are serialized as pointers.

exception Error of string
type nonrec 'a result = ('a, string) result
module Ser : sig ... end

Serialization

val to_cbor_string : 'a Ser.t -> 'a -> string

to_cbor_string ser x seralizes x using ser, and returns the pack containing the shared heap, and an entry point.

val to_value : 'a Ser.t -> 'a -> value

Same as to_string but without the value encoding step.

module Deser : sig ... end

Deserialization

val of_value_exn : 'a Deser.t -> value -> 'a

of_value_exn deser value deserializes an object using deser from the shared heap value.h, starting at value.key.

val of_value : 'a Deser.t -> value -> 'a result

Deserialize a pack into a value of type 'a

val of_cbor_string_exn : 'a Deser.t -> string -> 'a

Parse value and deserialize it

val of_cbor_string : 'a Deser.t -> string -> 'a result