Coverage Report

Created: 2026-06-07 06:52

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