Coverage Report

Created: 2026-05-16 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
#if canImport(FoundationEssentials)
18
import FoundationEssentials
19
#else
20
import Foundation
21
#endif
22
23
/// Contains any unknown fields in a decoded message; that is, fields that were
24
/// sent on the wire but were not recognized by the generated message
25
/// implementation or were valid field numbers but with mismatching wire
26
/// formats (for example, a field encoded as a varint when a fixed32 integer
27
/// was expected).
28
public struct UnknownStorage: Equatable, Sendable {
29
30
    /// The raw protocol buffer binary-encoded bytes that represent the unknown
31
    /// fields of a decoded message.
32
3.24G
    public private(set) var data = Data()
33
34
3.24G
    public init() {}
35
36
4.53M
    package mutating func append(protobufData: Data) {
37
4.53M
        data.append(protobufData)
38
4.53M
    }
39
40
1.13G
    public func traverse<V: Visitor>(visitor: inout V) throws {
41
1.13G
        if !data.isEmpty {
42
190M
            try visitor.visitUnknown(bytes: data)
43
1.13G
        }
44
1.13G
    }
45
}