Coverage Report

Created: 2026-11-12 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/swift-protobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift
Line
Count
Source
1
// Sources/SwiftProtobuf/Message+AnyAdditions.swift - Any-related Message extensions
2
//
3
// Copyright (c) 2014 - 2017 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
/// Extends the ``Message`` type with ``Google_Protobuf_Any``-specific behavior.
12
///
13
// -----------------------------------------------------------------------------
14
15
extension Message {
16
    /// Initialize this message from the provided `google.protobuf.Any`
17
    /// well-known type.
18
    ///
19
    /// This corresponds to the `unpack` method in the Google C++ API.
20
    ///
21
    /// If the Any object was decoded from Protobuf Binary or JSON
22
    /// format, then the enclosed field data was stored and is not
23
    /// fully decoded until you unpack the Any object into a message.
24
    /// As such, this method will typically need to perform a full
25
    /// deserialization of the enclosed data and can fail for any
26
    /// reason that deserialization can fail.
27
    ///
28
    /// See `Google_Protobuf_Any.unpackTo()` for more discussion.
29
    ///
30
    /// - Parameter unpackingAny: the message to decode.
31
    /// - Parameter extensions: An ``ExtensionMap`` used to look up and decode any
32
    ///   extensions in this message or messages nested within this message's
33
    ///   fields.
34
    /// - Parameter options: The BinaryDecodingOptions to use.
35
    /// - Throws: an instance of ``AnyUnpackError``, ``JSONDecodingError``, or
36
    ///   ``BinaryDecodingError`` on failure.
37
    public init(
38
        unpackingAny: Google_Protobuf_Any,
39
        extensions: (any ExtensionMap)? = nil,
40
        options: BinaryDecodingOptions = BinaryDecodingOptions()
41
0
    ) throws {
42
0
        self.init()
43
0
        try unpackingAny._storage.unpackTo(target: &self, extensions: extensions, options: options)
44
0
    }
45
}