/src/swift-protobuf/Sources/SwiftProtobuf/UnknownStorage.swift
Line | Count | Source |
1 | | // Sources/SwiftProtobuf/UnknownStorage.swift - Handling unknown fields |
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 | | /// Proto2 binary coding requires storing and recoding of unknown fields. |
12 | | /// This simple support class handles that requirement. A property of this type |
13 | | /// is compiled into every proto2 message. |
14 | | /// |
15 | | // ----------------------------------------------------------------------------- |
16 | | |
17 | | import Foundation |
18 | | |
19 | | /// Contains any unknown fields in a decoded message; that is, fields that were |
20 | | /// sent on the wire but were not recognized by the generated message |
21 | | /// implementation or were valid field numbers but with mismatching wire |
22 | | /// formats (for example, a field encoded as a varint when a fixed32 integer |
23 | | /// was expected). |
24 | | public struct UnknownStorage: Equatable, Sendable { |
25 | | |
26 | | /// The raw protocol buffer binary-encoded bytes that represent the unknown |
27 | | /// fields of a decoded message. |
28 | 4.03G | public private(set) var data = Data() |
29 | | |
30 | 4.03G | public init() {} |
31 | | |
32 | 3.04M | package mutating func append(protobufData: Data) { |
33 | 3.04M | data.append(protobufData) |
34 | 3.04M | } |
35 | | |
36 | 1.18G | public func traverse<V: Visitor>(visitor: inout V) throws { |
37 | 1.18G | if !data.isEmpty { |
38 | 91.2M | try visitor.visitUnknown(bytes: data) |
39 | 1.18G | } |
40 | 1.18G | } |
41 | | } |