feat(util): add Ser_value

This commit is contained in:
Simon Cruanes 2022-09-19 21:50:01 -04:00
parent a313918e74
commit d518511c64
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 39 additions and 0 deletions

View file

@ -23,5 +23,6 @@ module Stat = Stat
module Hash = Hash module Hash = Hash
module Profile = Profile module Profile = Profile
module Chunk_stack = Chunk_stack module Chunk_stack = Chunk_stack
module Ser_value = Ser_value
let[@inline] ( let@ ) f x = f x let[@inline] ( let@ ) f x = f x

15
src/util/ser_value.ml Normal file
View file

@ -0,0 +1,15 @@
type t =
| Bool of bool
| Str of string
| Bytes of string
| Int of int
| List of t list
| Dict of t Util.Str_map.t
let bool b : t = Bool b
let int i : t = Int i
let string x : t = Str x
let bytes x : t = Bytes x
let list x : t = List x
let dict x : t = Dict x
let dict_of_list l = dict (Util.Str_map.of_list l)

23
src/util/ser_value.mli Normal file
View file

@ -0,0 +1,23 @@
(** Serialization representation.
A [Ser_value.t] describes how to serialized some structured
data into bytes.
It reflects the shape of the structured data but does not commit to a
particular serialization format.
*)
type t = private
| Bool of bool
| Str of string
| Bytes of string
| Int of int
| List of t list
| Dict of t Util.Str_map.t
val bool : bool -> t
val int : int -> t
val string : string -> t
val bytes : string -> t
val list : t list -> t
val dict : t Util.Str_map.t -> t
val dict_of_list : (string * t) list -> t