Module Imandrakit_ser_pack.Deser

Deserialization

type state

Deserialization state, containing the heap of value values.

type ptr
type 'a t = state -> value -> 'a

A deserializer takes a value value, and returns a value of type 'a from it.

  • raises Error

    in case of error

val deref : state -> ptr -> value

Get an item via its pointer.

  • raises Invalid_argument

    if the pointer is invalid.

val return : 'a -> 'a t
val fail : string -> 'a

Fail to decode.

val failf : ('a, unit, string, 'b) format4 -> 'a

Fail to decode with a formatted message.

val to_unit : unit t
val to_int : int t
val to_int64 : int64 t
val to_bool : bool t
val to_float : float t
val to_list : value list t
val to_list_of : 'a t -> 'a list t
val to_map : (string * value) list t
val to_ptr : value -> ptr
val map_entry : k:string -> state -> value -> value
val to_any_tag : state -> value -> int * value

Deserialize an arbitrary tag

val to_tag : int -> state -> value -> value

Expect a particular tag.

val to_text : string t
val to_bytes : string t
val deref_if_ptr : state -> value -> value

If the value is a pointer, dereference it (recursively)

val ptr_of_int : int -> ptr

Entry point

val let+ : 'a t -> ('a -> 'b) -> 'b t

Map combinator

val let* : 'a t -> ('a -> 'b t) -> 'b t

Bind combinator

val delay : (unit -> 'a t) -> 'a t

delay f is like f(), but f is only called when needed.

val parse : string -> state result
val parse_exn : string -> state
type 'a cache_key

Generative key used to cache values during decoding

val create_cache_key : unit -> _ cache_key

Generate a new (generative) cache key for a type.

NOTE this should be called only at module toplevel, as a constant, not dynamically inside a function: let key: foo value_pack.Deser.cache_key = value_pack.Deser.create_cache_key ();;. Indeed, this is generative, so creating multiple keys for a type will result in sub-par or inexistant caching.

val with_cache : 'a cache_key -> 'a t -> 'a t

with_cache key dec is the same decoder as dec but it uses key to retrieve values directly from an internal table for entries/values that have already been decoded in the past. This means that a value that was encoded with a lot of sharing (e.g in a graph, or a large string using Ser.add_string) will be decoded only once.

val fix : ('a t -> 'a t) -> 'a t

fix f is a recursive deserializer. f receives a deserializer for recursive cases and must use it to implement the deserialization for the current value.

val result : 'a t -> 'b t -> ('a, 'b) result t
val entry_key : state -> value

Entrypoint for the pack, as used in Ser.finalize_value or Ser.finalize_string

val show_diagnostic : state -> string

Show the content of the deserialized value using the diagnostic notation

val pp_diagnostic : Stdlib.Format.formatter -> state -> unit

Show the content of the deserialized value using the diagnostic notation