/src/swift-protobuf/Sources/SwiftProtobuf/Visitor.swift
Line | Count | Source |
1 | | // Sources/SwiftProtobuf/Visitor.swift - Basic serialization machinery |
2 | | // |
3 | | // Copyright (c) 2014 - 2016 Apple Inc. and the project authors |
4 | | // Licensed under Apache License v2.0 with Runtime Library Exception |
5 | | // |
6 | | // See LICENSE.txt for license information: |
7 | | // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt |
8 | | // |
9 | | // ----------------------------------------------------------------------------- |
10 | | /// |
11 | | /// Protocol for traversing the object tree. |
12 | | /// |
13 | | /// This is used by: |
14 | | /// = Protobuf serialization |
15 | | /// = JSON serialization (with some twists to account for specialty JSON |
16 | | /// encodings) |
17 | | /// = Protobuf text serialization |
18 | | /// = Hashable computation |
19 | | /// |
20 | | /// Conceptually, serializers create visitor objects that are |
21 | | /// then passed recursively to every message and field via generated |
22 | | /// 'traverse' methods. The details get a little involved due to |
23 | | /// the need to allow particular messages to override particular |
24 | | /// behaviors for specific encodings, but the general idea is quite simple. |
25 | | /// |
26 | | // ----------------------------------------------------------------------------- |
27 | | |
28 | | import Foundation |
29 | | |
30 | | /// This is the key interface used by the generated `traverse()` methods |
31 | | /// used for serialization. It is implemented by each serialization protocol: |
32 | | /// Protobuf Binary, Protobuf Text, JSON, and the Hash encoder. |
33 | | public protocol Visitor { |
34 | | |
35 | | /// Called for each non-repeated float field |
36 | | /// |
37 | | /// A default implementation is provided that just widens the value |
38 | | /// and calls `visitSingularDoubleField` |
39 | | mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws |
40 | | |
41 | | /// Called for each non-repeated double field |
42 | | /// |
43 | | /// There is no default implementation. This must be implemented. |
44 | | mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws |
45 | | |
46 | | /// Called for each non-repeated int32 field |
47 | | /// |
48 | | /// A default implementation is provided that just widens the value |
49 | | /// and calls `visitSingularInt64Field` |
50 | | mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws |
51 | | |
52 | | /// Called for each non-repeated int64 field |
53 | | /// |
54 | | /// There is no default implementation. This must be implemented. |
55 | | mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws |
56 | | |
57 | | /// Called for each non-repeated uint32 field |
58 | | /// |
59 | | /// A default implementation is provided that just widens the value |
60 | | /// and calls `visitSingularUInt64Field` |
61 | | mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws |
62 | | |
63 | | /// Called for each non-repeated uint64 field |
64 | | /// |
65 | | /// There is no default implementation. This must be implemented. |
66 | | mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws |
67 | | |
68 | | /// Called for each non-repeated sint32 field |
69 | | /// |
70 | | /// A default implementation is provided that just forwards to |
71 | | /// `visitSingularInt32Field` |
72 | | mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws |
73 | | |
74 | | /// Called for each non-repeated sint64 field |
75 | | /// |
76 | | /// A default implementation is provided that just forwards to |
77 | | /// `visitSingularInt64Field` |
78 | | mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws |
79 | | |
80 | | /// Called for each non-repeated fixed32 field |
81 | | /// |
82 | | /// A default implementation is provided that just forwards to |
83 | | /// `visitSingularUInt32Field` |
84 | | mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws |
85 | | |
86 | | /// Called for each non-repeated fixed64 field |
87 | | /// |
88 | | /// A default implementation is provided that just forwards to |
89 | | /// `visitSingularUInt64Field` |
90 | | mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws |
91 | | |
92 | | /// Called for each non-repeated sfixed32 field |
93 | | /// |
94 | | /// A default implementation is provided that just forwards to |
95 | | /// `visitSingularInt32Field` |
96 | | mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws |
97 | | |
98 | | /// Called for each non-repeated sfixed64 field |
99 | | /// |
100 | | /// A default implementation is provided that just forwards to |
101 | | /// `visitSingularInt64Field` |
102 | | mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws |
103 | | |
104 | | /// Called for each non-repeated bool field |
105 | | /// |
106 | | /// There is no default implementation. This must be implemented. |
107 | | mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws |
108 | | |
109 | | /// Called for each non-repeated string field |
110 | | /// |
111 | | /// There is no default implementation. This must be implemented. |
112 | | mutating func visitSingularStringField(value: String, fieldNumber: Int) throws |
113 | | |
114 | | /// Called for each non-repeated bytes field |
115 | | /// |
116 | | /// There is no default implementation. This must be implemented. |
117 | | mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws |
118 | | |
119 | | /// Called for each non-repeated enum field |
120 | | /// |
121 | | /// There is no default implementation. This must be implemented. |
122 | | mutating func visitSingularEnumField<E: Enum>(value: E, fieldNumber: Int) throws |
123 | | |
124 | | /// Called for each non-repeated nested message field. |
125 | | /// |
126 | | /// There is no default implementation. This must be implemented. |
127 | | mutating func visitSingularMessageField<M: Message>(value: M, fieldNumber: Int) throws |
128 | | |
129 | | /// Called for each non-repeated proto2 group field. |
130 | | /// |
131 | | /// A default implementation is provided that simply forwards to |
132 | | /// `visitSingularMessageField`. Implementors who need to handle groups |
133 | | /// differently than nested messages can override this and provide distinct |
134 | | /// implementations. |
135 | | mutating func visitSingularGroupField<G: Message>(value: G, fieldNumber: Int) throws |
136 | | |
137 | | // Called for each non-packed repeated float field. |
138 | | /// The method is called once with the complete array of values for |
139 | | /// the field. |
140 | | /// |
141 | | /// A default implementation is provided that simply calls |
142 | | /// `visitSingularFloatField` once for each item in the array. |
143 | | mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws |
144 | | |
145 | | // Called for each non-packed repeated double field. |
146 | | /// The method is called once with the complete array of values for |
147 | | /// the field. |
148 | | /// |
149 | | /// A default implementation is provided that simply calls |
150 | | /// `visitSingularDoubleField` once for each item in the array. |
151 | | mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws |
152 | | |
153 | | // Called for each non-packed repeated int32 field. |
154 | | /// The method is called once with the complete array of values for |
155 | | /// the field. |
156 | | /// |
157 | | /// A default implementation is provided that simply calls |
158 | | /// `visitSingularInt32Field` once for each item in the array. |
159 | | mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws |
160 | | |
161 | | // Called for each non-packed repeated int64 field. |
162 | | /// The method is called once with the complete array of values for |
163 | | /// the field. |
164 | | /// |
165 | | /// A default implementation is provided that simply calls |
166 | | /// `visitSingularInt64Field` once for each item in the array. |
167 | | mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws |
168 | | |
169 | | // Called for each non-packed repeated uint32 field. |
170 | | /// The method is called once with the complete array of values for |
171 | | /// the field. |
172 | | /// |
173 | | /// A default implementation is provided that simply calls |
174 | | /// `visitSingularUInt32Field` once for each item in the array. |
175 | | mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws |
176 | | |
177 | | // Called for each non-packed repeated uint64 field. |
178 | | /// The method is called once with the complete array of values for |
179 | | /// the field. |
180 | | /// |
181 | | /// A default implementation is provided that simply calls |
182 | | /// `visitSingularUInt64Field` once for each item in the array. |
183 | | mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws |
184 | | |
185 | | // Called for each non-packed repeated sint32 field. |
186 | | /// The method is called once with the complete array of values for |
187 | | /// the field. |
188 | | /// |
189 | | /// A default implementation is provided that simply calls |
190 | | /// `visitSingularSInt32Field` once for each item in the array. |
191 | | mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws |
192 | | |
193 | | // Called for each non-packed repeated sint64 field. |
194 | | /// The method is called once with the complete array of values for |
195 | | /// the field. |
196 | | /// |
197 | | /// A default implementation is provided that simply calls |
198 | | /// `visitSingularSInt64Field` once for each item in the array. |
199 | | mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws |
200 | | |
201 | | // Called for each non-packed repeated fixed32 field. |
202 | | /// The method is called once with the complete array of values for |
203 | | /// the field. |
204 | | /// |
205 | | /// A default implementation is provided that simply calls |
206 | | /// `visitSingularFixed32Field` once for each item in the array. |
207 | | mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws |
208 | | |
209 | | // Called for each non-packed repeated fixed64 field. |
210 | | /// The method is called once with the complete array of values for |
211 | | /// the field. |
212 | | /// |
213 | | /// A default implementation is provided that simply calls |
214 | | /// `visitSingularFixed64Field` once for each item in the array. |
215 | | mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws |
216 | | |
217 | | // Called for each non-packed repeated sfixed32 field. |
218 | | /// The method is called once with the complete array of values for |
219 | | /// the field. |
220 | | /// |
221 | | /// A default implementation is provided that simply calls |
222 | | /// `visitSingularSFixed32Field` once for each item in the array. |
223 | | mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws |
224 | | |
225 | | // Called for each non-packed repeated sfixed64 field. |
226 | | /// The method is called once with the complete array of values for |
227 | | /// the field. |
228 | | /// |
229 | | /// A default implementation is provided that simply calls |
230 | | /// `visitSingularSFixed64Field` once for each item in the array. |
231 | | mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws |
232 | | |
233 | | // Called for each non-packed repeated bool field. |
234 | | /// The method is called once with the complete array of values for |
235 | | /// the field. |
236 | | /// |
237 | | /// A default implementation is provided that simply calls |
238 | | /// `visitSingularBoolField` once for each item in the array. |
239 | | mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws |
240 | | |
241 | | // Called for each non-packed repeated string field. |
242 | | /// The method is called once with the complete array of values for |
243 | | /// the field. |
244 | | /// |
245 | | /// A default implementation is provided that simply calls |
246 | | /// `visitSingularStringField` once for each item in the array. |
247 | | mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws |
248 | | |
249 | | // Called for each non-packed repeated bytes field. |
250 | | /// The method is called once with the complete array of values for |
251 | | /// the field. |
252 | | /// |
253 | | /// A default implementation is provided that simply calls |
254 | | /// `visitSingularBytesField` once for each item in the array. |
255 | | mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws |
256 | | |
257 | | /// Called for each repeated, unpacked enum field. |
258 | | /// The method is called once with the complete array of values for |
259 | | /// the field. |
260 | | /// |
261 | | /// A default implementation is provided that simply calls |
262 | | /// `visitSingularEnumField` once for each item in the array. |
263 | | mutating func visitRepeatedEnumField<E: Enum>(value: [E], fieldNumber: Int) throws |
264 | | |
265 | | /// Called for each repeated nested message field. The method is called once |
266 | | /// with the complete array of values for the field. |
267 | | /// |
268 | | /// A default implementation is provided that simply calls |
269 | | /// `visitSingularMessageField` once for each item in the array. |
270 | | mutating func visitRepeatedMessageField<M: Message>( |
271 | | value: [M], |
272 | | fieldNumber: Int |
273 | | ) throws |
274 | | |
275 | | /// Called for each repeated proto2 group field. |
276 | | /// |
277 | | /// A default implementation is provided that simply calls |
278 | | /// `visitSingularGroupField` once for each item in the array. |
279 | | mutating func visitRepeatedGroupField<G: Message>(value: [G], fieldNumber: Int) throws |
280 | | |
281 | | // Called for each packed, repeated float field. |
282 | | /// |
283 | | /// This is called once with the complete array of values for |
284 | | /// the field. |
285 | | /// |
286 | | /// There is a default implementation that forwards to the non-packed |
287 | | /// function. |
288 | | mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws |
289 | | |
290 | | // Called for each packed, repeated double field. |
291 | | /// |
292 | | /// This is called once with the complete array of values for |
293 | | /// the field. |
294 | | /// |
295 | | /// There is a default implementation that forwards to the non-packed |
296 | | /// function. |
297 | | mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws |
298 | | |
299 | | // Called for each packed, repeated int32 field. |
300 | | /// |
301 | | /// This is called once with the complete array of values for |
302 | | /// the field. |
303 | | /// |
304 | | /// There is a default implementation that forwards to the non-packed |
305 | | /// function. |
306 | | mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws |
307 | | |
308 | | // Called for each packed, repeated int64 field. |
309 | | /// |
310 | | /// This is called once with the complete array of values for |
311 | | /// the field. |
312 | | /// |
313 | | /// There is a default implementation that forwards to the non-packed |
314 | | /// function. |
315 | | mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws |
316 | | |
317 | | // Called for each packed, repeated uint32 field. |
318 | | /// |
319 | | /// This is called once with the complete array of values for |
320 | | /// the field. |
321 | | /// |
322 | | /// There is a default implementation that forwards to the non-packed |
323 | | /// function. |
324 | | mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws |
325 | | |
326 | | // Called for each packed, repeated uint64 field. |
327 | | /// |
328 | | /// This is called once with the complete array of values for |
329 | | /// the field. |
330 | | /// |
331 | | /// There is a default implementation that forwards to the non-packed |
332 | | /// function. |
333 | | mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws |
334 | | |
335 | | // Called for each packed, repeated sint32 field. |
336 | | /// |
337 | | /// This is called once with the complete array of values for |
338 | | /// the field. |
339 | | /// |
340 | | /// There is a default implementation that forwards to the non-packed |
341 | | /// function. |
342 | | mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws |
343 | | |
344 | | // Called for each packed, repeated sint64 field. |
345 | | /// |
346 | | /// This is called once with the complete array of values for |
347 | | /// the field. |
348 | | /// |
349 | | /// There is a default implementation that forwards to the non-packed |
350 | | /// function. |
351 | | mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws |
352 | | |
353 | | // Called for each packed, repeated fixed32 field. |
354 | | /// |
355 | | /// This is called once with the complete array of values for |
356 | | /// the field. |
357 | | /// |
358 | | /// There is a default implementation that forwards to the non-packed |
359 | | /// function. |
360 | | mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws |
361 | | |
362 | | // Called for each packed, repeated fixed64 field. |
363 | | /// |
364 | | /// This is called once with the complete array of values for |
365 | | /// the field. |
366 | | /// |
367 | | /// There is a default implementation that forwards to the non-packed |
368 | | /// function. |
369 | | mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws |
370 | | |
371 | | // Called for each packed, repeated sfixed32 field. |
372 | | /// |
373 | | /// This is called once with the complete array of values for |
374 | | /// the field. |
375 | | /// |
376 | | /// There is a default implementation that forwards to the non-packed |
377 | | /// function. |
378 | | mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws |
379 | | |
380 | | // Called for each packed, repeated sfixed64 field. |
381 | | /// |
382 | | /// This is called once with the complete array of values for |
383 | | /// the field. |
384 | | /// |
385 | | /// There is a default implementation that forwards to the non-packed |
386 | | /// function. |
387 | | mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws |
388 | | |
389 | | // Called for each packed, repeated bool field. |
390 | | /// |
391 | | /// This is called once with the complete array of values for |
392 | | /// the field. |
393 | | /// |
394 | | /// There is a default implementation that forwards to the non-packed |
395 | | /// function. |
396 | | mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws |
397 | | |
398 | | /// Called for each repeated, packed enum field. |
399 | | /// The method is called once with the complete array of values for |
400 | | /// the field. |
401 | | /// |
402 | | /// A default implementation is provided that simply forwards to |
403 | | /// `visitRepeatedEnumField`. Implementors who need to handle packed fields |
404 | | /// differently than unpacked fields can override this and provide distinct |
405 | | /// implementations. |
406 | | mutating func visitPackedEnumField<E: Enum>(value: [E], fieldNumber: Int) throws |
407 | | |
408 | | /// Called for each map field with primitive values. The method is |
409 | | /// called once with the complete dictionary of keys/values for the |
410 | | /// field. |
411 | | /// |
412 | | /// There is no default implementation. This must be implemented. |
413 | | mutating func visitMapField<KeyType, ValueType: MapValueType>( |
414 | | fieldType: _ProtobufMap<KeyType, ValueType>.Type, |
415 | | value: _ProtobufMap<KeyType, ValueType>.BaseType, |
416 | | fieldNumber: Int |
417 | | ) throws |
418 | | |
419 | | /// Called for each map field with enum values. The method is called |
420 | | /// once with the complete dictionary of keys/values for the field. |
421 | | /// |
422 | | /// There is no default implementation. This must be implemented. |
423 | | mutating func visitMapField<KeyType, ValueType>( |
424 | | fieldType: _ProtobufEnumMap<KeyType, ValueType>.Type, |
425 | | value: _ProtobufEnumMap<KeyType, ValueType>.BaseType, |
426 | | fieldNumber: Int |
427 | | ) throws where ValueType.RawValue == Int |
428 | | |
429 | | /// Called for each map field with message values. The method is |
430 | | /// called once with the complete dictionary of keys/values for the |
431 | | /// field. |
432 | | /// |
433 | | /// There is no default implementation. This must be implemented. |
434 | | mutating func visitMapField<KeyType, ValueType>( |
435 | | fieldType: _ProtobufMessageMap<KeyType, ValueType>.Type, |
436 | | value: _ProtobufMessageMap<KeyType, ValueType>.BaseType, |
437 | | fieldNumber: Int |
438 | | ) throws |
439 | | |
440 | | /// Called for each extension range. |
441 | | mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws |
442 | | |
443 | | /// Called for each extension range. |
444 | | mutating func visitExtensionFieldsAsMessageSet( |
445 | | fields: ExtensionFieldValueSet, |
446 | | start: Int, |
447 | | end: Int |
448 | | ) throws |
449 | | |
450 | | /// Called with the raw bytes that represent any unknown fields. |
451 | | mutating func visitUnknown(bytes: Data) throws |
452 | | } |
453 | | |
454 | | /// Forwarding default implementations of some visitor methods, for convenience. |
455 | | extension Visitor { |
456 | | |
457 | | // Default definitions of numeric serializations. |
458 | | // |
459 | | // The 32-bit versions widen and delegate to 64-bit versions. |
460 | | // The specialized integer codings delegate to standard Int/UInt. |
461 | | // |
462 | | // These "just work" for Hash and Text formats. Most of these work |
463 | | // for JSON (32-bit integers are overridden to suppress quoting), |
464 | | // and a few even work for Protobuf Binary (thanks to varint coding |
465 | | // which erases the size difference between 32-bit and 64-bit ints). |
466 | | |
467 | 0 | public mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { |
468 | 0 | try visitSingularDoubleField(value: Double(value), fieldNumber: fieldNumber) |
469 | 0 | } |
470 | 16.7M | public mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { |
471 | 16.7M | try visitSingularInt64Field(value: Int64(value), fieldNumber: fieldNumber) |
472 | 16.7M | } |
473 | 2.82M | public mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { |
474 | 2.82M | try visitSingularUInt64Field(value: UInt64(value), fieldNumber: fieldNumber) |
475 | 2.82M | } |
476 | 28.1k | public mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { |
477 | 28.1k | try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) |
478 | 28.1k | } |
479 | 64.4k | public mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { |
480 | 64.4k | try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) |
481 | 64.4k | } |
482 | 14.4k | public mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { |
483 | 14.4k | try visitSingularUInt32Field(value: value, fieldNumber: fieldNumber) |
484 | 14.4k | } |
485 | 55.4k | public mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { |
486 | 55.4k | try visitSingularUInt64Field(value: value, fieldNumber: fieldNumber) |
487 | 55.4k | } |
488 | 20.3k | public mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { |
489 | 20.3k | try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) |
490 | 20.3k | } |
491 | 18.5k | public mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { |
492 | 18.5k | try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) |
493 | 18.5k | } |
494 | | |
495 | | // Default definitions of repeated serializations that just iterate and |
496 | | // invoke the singular encoding. These "just work" for Protobuf Binary (encoder |
497 | | // and size visitor), Protobuf Text, and Hash visitors. JSON format stores |
498 | | // repeated values differently from singular, so overrides these. |
499 | | |
500 | 32.7k | public mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { |
501 | 32.7k | assert(!value.isEmpty) |
502 | 516k | for v in value { |
503 | 516k | try visitSingularFloatField(value: v, fieldNumber: fieldNumber) |
504 | 516k | } |
505 | 32.7k | } |
506 | | |
507 | 21.2k | public mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { |
508 | 21.2k | assert(!value.isEmpty) |
509 | 128k | for v in value { |
510 | 128k | try visitSingularDoubleField(value: v, fieldNumber: fieldNumber) |
511 | 128k | } |
512 | 21.2k | } |
513 | | |
514 | 28.0k | public mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { |
515 | 28.0k | assert(!value.isEmpty) |
516 | 240k | for v in value { |
517 | 240k | try visitSingularInt32Field(value: v, fieldNumber: fieldNumber) |
518 | 240k | } |
519 | 28.0k | } |
520 | | |
521 | 20.5k | public mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { |
522 | 20.5k | assert(!value.isEmpty) |
523 | 296k | for v in value { |
524 | 296k | try visitSingularInt64Field(value: v, fieldNumber: fieldNumber) |
525 | 296k | } |
526 | 20.5k | } |
527 | | |
528 | 48.1k | public mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { |
529 | 48.1k | assert(!value.isEmpty) |
530 | 561k | for v in value { |
531 | 561k | try visitSingularUInt32Field(value: v, fieldNumber: fieldNumber) |
532 | 561k | } |
533 | 48.1k | } |
534 | | |
535 | 22.3k | public mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { |
536 | 22.3k | assert(!value.isEmpty) |
537 | 1.14M | for v in value { |
538 | 1.14M | try visitSingularUInt64Field(value: v, fieldNumber: fieldNumber) |
539 | 1.14M | } |
540 | 22.3k | } |
541 | | |
542 | 21.0k | public mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { |
543 | 21.0k | assert(!value.isEmpty) |
544 | 487k | for v in value { |
545 | 487k | try visitSingularSInt32Field(value: v, fieldNumber: fieldNumber) |
546 | 487k | } |
547 | 21.0k | } |
548 | | |
549 | 36.6k | public mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { |
550 | 36.6k | assert(!value.isEmpty) |
551 | 2.01M | for v in value { |
552 | 2.01M | try visitSingularSInt64Field(value: v, fieldNumber: fieldNumber) |
553 | 2.01M | } |
554 | 36.6k | } |
555 | | |
556 | 28.1k | public mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { |
557 | 28.1k | assert(!value.isEmpty) |
558 | 173k | for v in value { |
559 | 173k | try visitSingularFixed32Field(value: v, fieldNumber: fieldNumber) |
560 | 173k | } |
561 | 28.1k | } |
562 | | |
563 | 9.01k | public mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { |
564 | 9.01k | assert(!value.isEmpty) |
565 | 197k | for v in value { |
566 | 197k | try visitSingularFixed64Field(value: v, fieldNumber: fieldNumber) |
567 | 197k | } |
568 | 9.01k | } |
569 | | |
570 | 17.9k | public mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { |
571 | 17.9k | assert(!value.isEmpty) |
572 | 753k | for v in value { |
573 | 753k | try visitSingularSFixed32Field(value: v, fieldNumber: fieldNumber) |
574 | 753k | } |
575 | 17.9k | } |
576 | | |
577 | 16.6k | public mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { |
578 | 16.6k | assert(!value.isEmpty) |
579 | 270k | for v in value { |
580 | 270k | try visitSingularSFixed64Field(value: v, fieldNumber: fieldNumber) |
581 | 270k | } |
582 | 16.6k | } |
583 | | |
584 | 19.5k | public mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { |
585 | 19.5k | assert(!value.isEmpty) |
586 | 3.99M | for v in value { |
587 | 3.99M | try visitSingularBoolField(value: v, fieldNumber: fieldNumber) |
588 | 3.99M | } |
589 | 19.5k | } |
590 | | |
591 | 11.3k | public mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { |
592 | 11.3k | assert(!value.isEmpty) |
593 | 33.7k | for v in value { |
594 | 33.7k | try visitSingularStringField(value: v, fieldNumber: fieldNumber) |
595 | 33.7k | } |
596 | 11.3k | } |
597 | | |
598 | 29.0k | public mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { |
599 | 29.0k | assert(!value.isEmpty) |
600 | 61.0k | for v in value { |
601 | 61.0k | try visitSingularBytesField(value: v, fieldNumber: fieldNumber) |
602 | 61.0k | } |
603 | 29.0k | } |
604 | | |
605 | 25.2k | public mutating func visitRepeatedEnumField<E: Enum>(value: [E], fieldNumber: Int) throws { |
606 | 25.2k | assert(!value.isEmpty) |
607 | 663k | for v in value { |
608 | 663k | try visitSingularEnumField(value: v, fieldNumber: fieldNumber) |
609 | 663k | } |
610 | 25.2k | } |
611 | | |
612 | 202k | public mutating func visitRepeatedMessageField<M: Message>(value: [M], fieldNumber: Int) throws { |
613 | 202k | assert(!value.isEmpty) |
614 | 2.14M | for v in value { |
615 | 2.14M | try visitSingularMessageField(value: v, fieldNumber: fieldNumber) |
616 | 2.14M | } |
617 | 202k | } |
618 | | |
619 | 18.1k | public mutating func visitRepeatedGroupField<G: Message>(value: [G], fieldNumber: Int) throws { |
620 | 18.1k | assert(!value.isEmpty) |
621 | 50.1k | for v in value { |
622 | 50.1k | try visitSingularGroupField(value: v, fieldNumber: fieldNumber) |
623 | 50.1k | } |
624 | 18.1k | } |
625 | | |
626 | | // Default definitions of packed serialization just defer to the |
627 | | // repeated implementation. This works for Hash and JSON visitors |
628 | | // (which do not distinguish packed vs. non-packed) but are |
629 | | // overridden by Protobuf Binary and Text. |
630 | | |
631 | 8.27k | public mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { |
632 | 8.27k | assert(!value.isEmpty) |
633 | 8.27k | try visitRepeatedFloatField(value: value, fieldNumber: fieldNumber) |
634 | 8.27k | } |
635 | | |
636 | 9.41k | public mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { |
637 | 9.41k | assert(!value.isEmpty) |
638 | 9.41k | try visitRepeatedDoubleField(value: value, fieldNumber: fieldNumber) |
639 | 9.41k | } |
640 | | |
641 | 39.4k | public mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { |
642 | 39.4k | assert(!value.isEmpty) |
643 | 39.4k | try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) |
644 | 39.4k | } |
645 | | |
646 | 9.60k | public mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { |
647 | 9.60k | assert(!value.isEmpty) |
648 | 9.60k | try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) |
649 | 9.60k | } |
650 | | |
651 | 8.14k | public mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { |
652 | 8.14k | assert(!value.isEmpty) |
653 | 8.14k | try visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) |
654 | 8.14k | } |
655 | | |
656 | 17.6k | public mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { |
657 | 17.6k | assert(!value.isEmpty) |
658 | 17.6k | try visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) |
659 | 17.6k | } |
660 | | |
661 | 2.20k | public mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { |
662 | 2.20k | assert(!value.isEmpty) |
663 | 2.20k | try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) |
664 | 2.20k | } |
665 | | |
666 | 2.08k | public mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { |
667 | 2.08k | assert(!value.isEmpty) |
668 | 2.08k | try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) |
669 | 2.08k | } |
670 | | |
671 | 1.11k | public mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { |
672 | 1.11k | assert(!value.isEmpty) |
673 | 1.11k | try visitPackedUInt32Field(value: value, fieldNumber: fieldNumber) |
674 | 1.11k | } |
675 | | |
676 | 1.40k | public mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { |
677 | 1.40k | assert(!value.isEmpty) |
678 | 1.40k | try visitPackedUInt64Field(value: value, fieldNumber: fieldNumber) |
679 | 1.40k | } |
680 | | |
681 | 1.12k | public mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { |
682 | 1.12k | assert(!value.isEmpty) |
683 | 1.12k | try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) |
684 | 1.12k | } |
685 | | |
686 | 2.13k | public mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { |
687 | 2.13k | assert(!value.isEmpty) |
688 | 2.13k | try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) |
689 | 2.13k | } |
690 | | |
691 | 7.06k | public mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { |
692 | 7.06k | assert(!value.isEmpty) |
693 | 7.06k | try visitRepeatedBoolField(value: value, fieldNumber: fieldNumber) |
694 | 7.06k | } |
695 | | |
696 | | public mutating func visitPackedEnumField<E: Enum>( |
697 | | value: [E], |
698 | | fieldNumber: Int |
699 | 2.85k | ) throws { |
700 | 2.85k | assert(!value.isEmpty) |
701 | 2.85k | try visitRepeatedEnumField(value: value, fieldNumber: fieldNumber) |
702 | 2.85k | } |
703 | | |
704 | | // Default handling for Groups is to treat them just like messages. |
705 | | // This works for Text and Hash, but is overridden by Protobuf Binary |
706 | | // format (which has a different encoding for groups) and JSON |
707 | | // (which explicitly ignores all groups). |
708 | | |
709 | | public mutating func visitSingularGroupField<G: Message>( |
710 | | value: G, |
711 | | fieldNumber: Int |
712 | 14.7k | ) throws { |
713 | 14.7k | try visitSingularMessageField(value: value, fieldNumber: fieldNumber) |
714 | 14.7k | } |
715 | | |
716 | | // Default handling of Extensions as a MessageSet to handing them just |
717 | | // as plain extensions. Formats that what custom behavior can override |
718 | | // it. |
719 | | |
720 | | public mutating func visitExtensionFieldsAsMessageSet( |
721 | | fields: ExtensionFieldValueSet, |
722 | | start: Int, |
723 | | end: Int |
724 | 15.2k | ) throws { |
725 | 15.2k | try visitExtensionFields(fields: fields, start: start, end: end) |
726 | 15.2k | } |
727 | | |
728 | | // Default handling for Extensions is to forward the traverse to |
729 | | // the ExtensionFieldValueSet. Formats that don't care about extensions |
730 | | // can override to avoid it. |
731 | | |
732 | | /// Called for each extension range. |
733 | 65.0M | public mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws { |
734 | 65.0M | try fields.traverse(visitor: &self, start: start, end: end) |
735 | 65.0M | } |
736 | | } |