@@ -31,17 +31,17 @@ extension Message {
3131 /// - options: The ``BinaryDecodingOptions`` to use.
3232 /// - Throws: ``BinaryDecodingError`` if decoding fails.
3333 @inlinable
34- @available ( * , deprecated, renamed: " init(contiguousBytes :extensions:partial:options:) " )
34+ @available ( * , deprecated, renamed: " init(serializedBytes :extensions:partial:options:) " )
3535 public init (
3636 serializedData data: Data ,
3737 extensions: ( any ExtensionMap ) ? = nil ,
3838 partial: Bool = false ,
3939 options: BinaryDecodingOptions = BinaryDecodingOptions ( )
4040 ) throws {
4141 self . init ( )
42- try merge ( contiguousBytes : data, extensions: extensions, partial: partial, options: options)
42+ try merge ( serializedBytes : data, extensions: extensions, partial: partial, options: options)
4343 }
44-
44+
4545 /// Creates a new message by decoding the given `Foundation/ContiguousBytes` value
4646 /// containing a serialized message in Protocol Buffer binary format.
4747 ///
@@ -58,17 +58,44 @@ extension Message {
5858 /// - Throws: ``SwiftProtobufError`` if decoding fails.
5959 @inlinable
6060 @_disfavoredOverload
61- @available ( * , deprecated, message : " Please conform your Bytes type to `SwiftProtobufContiguousBytes` instead of `Foundation.ContiguousBytes`. " )
61+ @available ( * , deprecated, renamed : " init(serializedBytes:extensions:partial:options:) " )
6262 public init < Bytes: ContiguousBytes > (
6363 contiguousBytes bytes: Bytes ,
6464 extensions: ( any ExtensionMap ) ? = nil ,
6565 partial: Bool = false ,
6666 options: BinaryDecodingOptions = BinaryDecodingOptions ( )
6767 ) throws {
6868 self . init ( )
69- try merge ( contiguousBytes: bytes, extensions: extensions, partial: partial, options: options)
69+ try merge ( serializedBytes: bytes, extensions: extensions, partial: partial, options: options)
70+ }
71+
72+ /// Creates a new message by decoding the given `Foundation/ContiguousBytes` value
73+ /// containing a serialized message in Protocol Buffer binary format.
74+ ///
75+ /// - Parameters:
76+ /// - serializedBytes: The binary-encoded message data to decode.
77+ /// - extensions: An ``ExtensionMap`` used to look up and decode any
78+ /// extensions in this message or messages nested within this message's
79+ /// fields.
80+ /// - partial: If `false` (the default), this method will check
81+ /// ``Message/isInitialized-6abgi`` after decoding to verify that all required
82+ /// fields are present. If any are missing, this method throws
83+ /// ``SwiftProtobufError/BinaryDecoding/missingRequiredFields``.
84+ /// - options: The ``BinaryDecodingOptions`` to use.
85+ /// - Throws: ``SwiftProtobufError`` if decoding fails.
86+ @inlinable
87+ @_disfavoredOverload
88+ @available ( * , deprecated, message: " Please conform your Bytes type to `SwiftProtobufContiguousBytes` instead of `Foundation.ContiguousBytes`. " )
89+ public init < Bytes: ContiguousBytes > (
90+ serializedBytes bytes: Bytes ,
91+ extensions: ( any ExtensionMap ) ? = nil ,
92+ partial: Bool = false ,
93+ options: BinaryDecodingOptions = BinaryDecodingOptions ( )
94+ ) throws {
95+ self . init ( )
96+ try merge ( serializedBytes: bytes, extensions: extensions, partial: partial, options: options)
7097 }
71-
98+
7299 /// Updates the message by decoding the given `Foundation/ContiguousBytes` value
73100 /// containing a serialized message in Protocol Buffer binary format into the
74101 /// receiver.
@@ -90,7 +117,7 @@ extension Message {
90117 /// - Throws: ``SwiftProtobufError`` if decoding fails.
91118 @inlinable
92119 @_disfavoredOverload
93- @available ( * , deprecated, message : " Please conform your Bytes type to `SwiftProtobufContiguousBytes` instead of `Foundation.ContiguousBytes`. " )
120+ @available ( * , deprecated, renamed : " merge(serializedBytes:extensions:partial:options:) " )
94121 public mutating func merge< Bytes: ContiguousBytes > (
95122 contiguousBytes bytes: Bytes ,
96123 extensions: ( any ExtensionMap ) ? = nil ,
@@ -102,6 +129,39 @@ extension Message {
102129 }
103130 }
104131
132+ /// Updates the message by decoding the given `Foundation/ContiguousBytes` value
133+ /// containing a serialized message in Protocol Buffer binary format into the
134+ /// receiver.
135+ ///
136+ /// - Note: If this method throws an error, the message may still have been
137+ /// partially mutated by the binary data that was decoded before the error
138+ /// occurred.
139+ ///
140+ /// - Parameters:
141+ /// - serializedBytes: The binary-encoded message data to decode.
142+ /// - extensions: An ``ExtensionMap`` used to look up and decode any
143+ /// extensions in this message or messages nested within this message's
144+ /// fields.
145+ /// - partial: If `false` (the default), this method will check
146+ /// ``Message/isInitialized-6abgi`` after decoding to verify that all required
147+ /// fields are present. If any are missing, this method throws
148+ /// ``SwiftProtobufError/BinaryDecoding/missingRequiredFields``.
149+ /// - options: The ``BinaryDecodingOptions`` to use.
150+ /// - Throws: ``SwiftProtobufError`` if decoding fails.
151+ @inlinable
152+ @_disfavoredOverload
153+ @available ( * , deprecated, message: " Please conform your Bytes type to `SwiftProtobufContiguousBytes` instead of `Foundation.ContiguousBytes`. " )
154+ public mutating func merge< Bytes: ContiguousBytes > (
155+ serializedBytes bytes: Bytes ,
156+ extensions: ( any ExtensionMap ) ? = nil ,
157+ partial: Bool = false ,
158+ options: BinaryDecodingOptions = BinaryDecodingOptions ( )
159+ ) throws {
160+ try bytes. withUnsafeBytes { ( body: UnsafeRawBufferPointer ) in
161+ try _merge ( rawBuffer: body, extensions: extensions, partial: partial, options: options)
162+ }
163+ }
164+
105165 /// Updates the message by decoding the given `Data` value
106166 /// containing a serialized message in Protocol Buffer binary format into the
107167 /// receiver.
@@ -128,7 +188,7 @@ extension Message {
128188 partial: Bool = false ,
129189 options: BinaryDecodingOptions = BinaryDecodingOptions ( )
130190 ) throws {
131- try merge ( contiguousBytes : data, extensions: extensions, partial: partial, options: options)
191+ try merge ( serializedBytes : data, extensions: extensions, partial: partial, options: options)
132192 }
133193
134194 /// Returns a `Data` instance containing the Protocol Buffer binary
0 commit comments