Source file common_pb.ml
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
[@@@ocaml.warning "-27-30-39"]
type array_value_mutable = {
mutable values : Common_types.any_value list;
}
let default_array_value_mutable () : array_value_mutable = {
values = [];
}
type key_value_list_mutable = {
mutable values : Common_types.key_value list;
}
let default_key_value_list_mutable () : key_value_list_mutable = {
values = [];
}
type key_value_mutable = {
mutable key : string;
mutable value : Common_types.any_value option;
}
let default_key_value_mutable () : key_value_mutable = {
key = "";
value = None;
}
type instrumentation_library_mutable = {
mutable name : string;
mutable version : string;
}
let default_instrumentation_library_mutable () : instrumentation_library_mutable = {
name = "";
version = "";
}
let rec decode_any_value d =
let rec loop () =
let ret:Common_types.any_value = match Pbrt.Decoder.key d with
| None -> Pbrt.Decoder.malformed_variant "any_value"
| Some (1, _) -> (Common_types.String_value (Pbrt.Decoder.string d) : Common_types.any_value)
| Some (2, _) -> (Common_types.Bool_value (Pbrt.Decoder.bool d) : Common_types.any_value)
| Some (3, _) -> (Common_types.Int_value (Pbrt.Decoder.int64_as_varint d) : Common_types.any_value)
| Some (4, _) -> (Common_types.Double_value (Pbrt.Decoder.float_as_bits64 d) : Common_types.any_value)
| Some (5, _) -> (Common_types.Array_value (decode_array_value (Pbrt.Decoder.nested d)) : Common_types.any_value)
| Some (6, _) -> (Common_types.Kvlist_value (decode_key_value_list (Pbrt.Decoder.nested d)) : Common_types.any_value)
| Some (7, _) -> (Common_types.Bytes_value (Pbrt.Decoder.bytes d) : Common_types.any_value)
| Some (n, payload_kind) -> (
Pbrt.Decoder.skip d payload_kind;
loop ()
)
in
ret
in
loop ()
and decode_array_value d =
let v = default_array_value_mutable () in
let continue__= ref true in
while !continue__ do
match Pbrt.Decoder.key d with
| None -> (
v.values <- List.rev v.values;
); continue__ := false
| Some (1, Pbrt.Bytes) -> begin
v.values <- (decode_any_value (Pbrt.Decoder.nested d)) :: v.values;
end
| Some (1, pk) ->
Pbrt.Decoder.unexpected_payload "Message(array_value), field(1)" pk
| Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind
done;
({
Common_types.values = v.values;
} : Common_types.array_value)
and decode_key_value_list d =
let v = default_key_value_list_mutable () in
let continue__= ref true in
while !continue__ do
match Pbrt.Decoder.key d with
| None -> (
v.values <- List.rev v.values;
); continue__ := false
| Some (1, Pbrt.Bytes) -> begin
v.values <- (decode_key_value (Pbrt.Decoder.nested d)) :: v.values;
end
| Some (1, pk) ->
Pbrt.Decoder.unexpected_payload "Message(key_value_list), field(1)" pk
| Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind
done;
({
Common_types.values = v.values;
} : Common_types.key_value_list)
and decode_key_value d =
let v = default_key_value_mutable () in
let continue__= ref true in
while !continue__ do
match Pbrt.Decoder.key d with
| None -> (
); continue__ := false
| Some (1, Pbrt.Bytes) -> begin
v.key <- Pbrt.Decoder.string d;
end
| Some (1, pk) ->
Pbrt.Decoder.unexpected_payload "Message(key_value), field(1)" pk
| Some (2, Pbrt.Bytes) -> begin
v.value <- Some (decode_any_value (Pbrt.Decoder.nested d));
end
| Some (2, pk) ->
Pbrt.Decoder.unexpected_payload "Message(key_value), field(2)" pk
| Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind
done;
({
Common_types.key = v.key;
Common_types.value = v.value;
} : Common_types.key_value)
let rec decode_instrumentation_library d =
let v = default_instrumentation_library_mutable () in
let continue__= ref true in
while !continue__ do
match Pbrt.Decoder.key d with
| None -> (
); continue__ := false
| Some (1, Pbrt.Bytes) -> begin
v.name <- Pbrt.Decoder.string d;
end
| Some (1, pk) ->
Pbrt.Decoder.unexpected_payload "Message(instrumentation_library), field(1)" pk
| Some (2, Pbrt.Bytes) -> begin
v.version <- Pbrt.Decoder.string d;
end
| Some (2, pk) ->
Pbrt.Decoder.unexpected_payload "Message(instrumentation_library), field(2)" pk
| Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind
done;
({
Common_types.name = v.name;
Common_types.version = v.version;
} : Common_types.instrumentation_library)
let rec encode_any_value (v:Common_types.any_value) encoder =
begin match v with
| Common_types.String_value x ->
Pbrt.Encoder.key (1, Pbrt.Bytes) encoder;
Pbrt.Encoder.string x encoder;
| Common_types.Bool_value x ->
Pbrt.Encoder.key (2, Pbrt.Varint) encoder;
Pbrt.Encoder.bool x encoder;
| Common_types.Int_value x ->
Pbrt.Encoder.key (3, Pbrt.Varint) encoder;
Pbrt.Encoder.int64_as_varint x encoder;
| Common_types.Double_value x ->
Pbrt.Encoder.key (4, Pbrt.Bits64) encoder;
Pbrt.Encoder.float_as_bits64 x encoder;
| Common_types.Array_value x ->
Pbrt.Encoder.key (5, Pbrt.Bytes) encoder;
Pbrt.Encoder.nested (encode_array_value x) encoder;
| Common_types.Kvlist_value x ->
Pbrt.Encoder.key (6, Pbrt.Bytes) encoder;
Pbrt.Encoder.nested (encode_key_value_list x) encoder;
| Common_types.Bytes_value x ->
Pbrt.Encoder.key (7, Pbrt.Bytes) encoder;
Pbrt.Encoder.bytes x encoder;
end
and encode_array_value (v:Common_types.array_value) encoder =
List.iter (fun x ->
Pbrt.Encoder.key (1, Pbrt.Bytes) encoder;
Pbrt.Encoder.nested (encode_any_value x) encoder;
) v.Common_types.values;
()
and encode_key_value_list (v:Common_types.key_value_list) encoder =
List.iter (fun x ->
Pbrt.Encoder.key (1, Pbrt.Bytes) encoder;
Pbrt.Encoder.nested (encode_key_value x) encoder;
) v.Common_types.values;
()
and encode_key_value (v:Common_types.key_value) encoder =
Pbrt.Encoder.key (1, Pbrt.Bytes) encoder;
Pbrt.Encoder.string v.Common_types.key encoder;
begin match v.Common_types.value with
| Some x ->
Pbrt.Encoder.key (2, Pbrt.Bytes) encoder;
Pbrt.Encoder.nested (encode_any_value x) encoder;
| None -> ();
end;
()
let rec encode_instrumentation_library (v:Common_types.instrumentation_library) encoder =
Pbrt.Encoder.key (1, Pbrt.Bytes) encoder;
Pbrt.Encoder.string v.Common_types.name encoder;
Pbrt.Encoder.key (2, Pbrt.Bytes) encoder;
Pbrt.Encoder.string v.Common_types.version encoder;
()