1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
open Base
module Internal = struct
module Parser = Parser
module Serializer = Serializer
end
module type Msgpackable = sig
type t
val of_msgpack : Message.t -> t Or_error.t
val to_msgpack : t -> Message.t
end
module Custom = struct
type t = Message.custom =
{ type_id : int
; data : Bytes.t
}
[@@deriving compare, sexp]
end
module T = struct
type t = Message.t =
| Nil
| Integer of int
| Int64 of Int64.t
| UInt64 of Int64.t
| Boolean of bool
| Floating of float
| Array of t list
| Map of (t * t) list
| String of string
| Binary of Bytes.t
| Extension of Custom.t
[@@deriving compare, sexp]
end
include T
include Comparable.Make (T)
let t_of_string = Parser.parse
let t_of_string_exn s = Or_error.ok_exn (Parser.parse s)
let string_of_t_exn = Serializer.message_to_string_exn