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
45
46
47
48
49
50
51
52
type t =
| Varint of Int64.t
| Fixed_64_bit of Int64.t
| Length_delimited of {
offset : int;
length : int;
data : string;
}
| Fixed_32_bit of Int32.t
let varint v = Varint v
let fixed_32_bit v = Fixed_32_bit v
let fixed_64_bit v = Fixed_64_bit v
let length_delimited ?(offset=0) ?length data =
let length = Option.value ~default:(String.length data - offset) length in
Length_delimited {offset; length; data}
let pp: Format.formatter -> t -> unit = fun fmt ->
function
| Varint a0 ->
(Format.fprintf fmt "(@[<2>Field.Varint@ ";
(Format.fprintf fmt "%LdL") a0;
Format.fprintf fmt "@])")
| Fixed_64_bit a0 ->
(Format.fprintf fmt
"(@[<2>Field.Fixed_64_bit@ ";
(Format.fprintf fmt "%LdL") a0;
Format.fprintf fmt "@])")
| Length_delimited
{ offset = aoffset; length = alength; data = adata } ->
(Format.fprintf fmt
"@[<2>Field.Length_delimited {@,";
(((Format.fprintf fmt "@[%s =@ " "offset";
(Format.fprintf fmt "%d") aoffset;
Format.fprintf fmt "@]");
Format.fprintf fmt ";@ ";
Format.fprintf fmt "@[%s =@ " "length";
(Format.fprintf fmt "%d") alength;
Format.fprintf fmt "@]");
Format.fprintf fmt ";@ ";
Format.fprintf fmt "@[%s =@ " "data";
(Format.fprintf fmt "%S") adata;
Format.fprintf fmt "@]");
Format.fprintf fmt "@]}")
| Fixed_32_bit a0 ->
(Format.fprintf fmt
"(@[<2>Field.Fixed_32_bit@ ";
(Format.fprintf fmt "%ldl") a0;
Format.fprintf fmt "@])")
let show : t -> string = Format.asprintf "%a" pp