Imandrakit_ser_pack.Ser
Serialization
State used for serialization.
It contains an in-progress heap, and a hash table for hashconsing.
val create : unit -> state
New state.
type ptr = value
An integer + tag for value
val unit : value
Build a value null
val int64 : int64 -> value
Build a value integer
val int : int -> value
Build a value integer
val bool : bool -> value
Build a value bool
val float : float -> value
Build a value float
val string : string -> value
Build a value text string (UTF8)
val bytes : string -> value
Build a value blob (raw bytes)
val dict : value Imandrakit_common.Str_map.t -> value
add_entry st c
turns c
into a heap entry and returns a pointer to it. The pointer is a small value value (a tagged integer).
add_entry_hashcons st c
turns c
into a heap entry. c
is first compared to existing hashconsed entries (at a runtime cost) to see if we can reuse them instead of inserting a new value.
Same as add_entry state (`Text s)
, except that large strings will be hashconsed unconditionally.
Same as add_string
fix f
is a recursive serializer. f
receives a serializer for recursive cases and must use it to implement the serialization for the current value.
val create_cache_key :
(module Stdlib.Hashtbl.HashedType with type t = 'a) ->
'a cache_key
Create a new (generative) cache key for a hashable + comparable type.
NOTE this should be called only at module toplevel, as a constant, not dynamically inside a function: let key = value_pack.Ser.create_cache_key (module …);;
. Indeed, this is generative, so creating multiple keys for a type will result in sub-par or inexistant caching.
with_cache key enc
is the same encoder as enc
, but with caching. When encoding a value x:'a
, the cache key
is used to detect if x
was already encoded to some entry, and uses a pointer to this entry instead of re-serializing x
.
Turn the state into a pack with given key
as entrypoint.
Same as finalize_value
but also turns the resulting packed value into a string.