Skip to content

Commit bf61972

Browse files
committed
Rename arguments back from contiguousBytes to serializedBytes
1 parent 7c823e2 commit bf61972

File tree

13 files changed

+95
-32
lines changed

13 files changed

+95
-32
lines changed

Documentation/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public struct Example: SwiftProtobuf.Message {
6969
// proto2-format messages that utilize extensions.
7070
// See below for more details.
7171
func serializedBytes<Bytes: SwiftProtobufContiguousBytes>() throws -> Bytes
72-
init<Bytes: SwiftProtobufContiguousBytes>(contiguousBytes: Bytes) throws {
73-
init<Bytes: SwiftProtobufContiguousBytes>(contiguousBytes: Bytes, extensions: ExtensionMap? = nil, partial: Bool = false) throws
72+
init<Bytes: SwiftProtobufContiguousBytes>(serializedBytes: Bytes) throws {
73+
init<Bytes: SwiftProtobufContiguousBytes>(serializedBytes: Bytes, extensions: ExtensionMap? = nil, partial: Bool = false) throws
7474

7575
// Messages can be serialized or deserialized to JSON format
7676
// as either UTF8-encoded ``SwiftProtobufContiguousBytes``-conforming objects or as Strings.

FuzzTesting/Sources/FuzzBinary/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public func FuzzBinary(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
1818
var msg: SwiftProtoTesting_Fuzz_Message?
1919
do {
2020
msg = try SwiftProtoTesting_Fuzz_Message(
21-
contiguousBytes: Array(bytes),
21+
serializedBytes: Array(bytes),
2222
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions,
2323
options: options)
2424
} catch {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ let binaryDataAsBytes: [UInt8] = try info.serializedBytes()
270270
let decodedInfo = try BookInfo(serializedData: binaryData)
271271

272272
// Deserialize a received [UInt8] object from `binaryDataAsBytes`
273-
let decodedInfo = try BookInfo(contiguousBytes: binaryDataAsBytes)
273+
let decodedInfo = try BookInfo(serializedBytes: binaryDataAsBytes)
274274

275275
// Serialize to JSON format as a Data object, or as any other type conforming to
276276
// SwiftProtobufContiguousBytes. For example:

Sources/Conformance/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func buildResponse(serializedData: Data) -> Conformance_ConformanceResponse {
7171

7272
let request: Conformance_ConformanceRequest
7373
do {
74-
request = try Conformance_ConformanceRequest(contiguousBytes: serializedData)
74+
request = try Conformance_ConformanceRequest(serializedBytes: serializedData)
7575
} catch {
7676
response.runtimeError = "Failed to parse conformance request"
7777
return response
@@ -132,7 +132,7 @@ func buildResponse(serializedData: Data) -> Conformance_ConformanceResponse {
132132
switch request.payload {
133133
case .protobufPayload(let data)?:
134134
do {
135-
testMessage = try msgType.init(contiguousBytes: data, extensions: extensions)
135+
testMessage = try msgType.init(serializedBytes: data, extensions: extensions)
136136
} catch let e {
137137
response.parseError = "Protobuf failed to parse: \(e)"
138138
return response

Sources/SwiftProtobuf/AnyMessageStorage.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ internal class AnyMessageStorage {
179179

180180
switch state {
181181
case .binary(let data):
182-
target = try M(contiguousBytes: data, extensions: extensions, partial: true, options: options)
182+
target = try M(serializedBytes: data, extensions: extensions, partial: true, options: options)
183183

184184
case .message(let msg):
185185
if let message = msg as? M {
@@ -188,7 +188,7 @@ internal class AnyMessageStorage {
188188
} else {
189189
// Different type, serialize and parse.
190190
let bytes: [UInt8] = try msg.serializedBytes(partial: true)
191-
target = try M(contiguousBytes: bytes, extensions: extensions, partial: true)
191+
target = try M(serializedBytes: bytes, extensions: extensions, partial: true)
192192
}
193193

194194
case .contentJSON(let contentJSON, let options):
@@ -272,7 +272,7 @@ extension AnyMessageStorage {
272272
if let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) {
273273
// If we can decode it, we can write the readable verbose form:
274274
do {
275-
let m = try messageType.init(contiguousBytes: valueData, partial: true)
275+
let m = try messageType.init(serializedBytes: valueData, partial: true)
276276
emitVerboseTextForm(visitor: &visitor, message: m, typeURL: _typeURL)
277277
return
278278
} catch {
@@ -424,7 +424,7 @@ extension AnyMessageStorage {
424424
// else to decode later.)
425425
throw JSONEncodingError.anyTranscodeFailure
426426
}
427-
let m = try messageType.init(contiguousBytes: valueData, partial: true)
427+
let m = try messageType.init(serializedBytes: valueData, partial: true)
428428
return try serializeAnyJSON(for: m, typeURL: _typeURL, options: options)
429429

430430
case .message(let msg):

Sources/SwiftProtobuf/AsyncMessageSequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ public struct AsyncMessageSequence<
179179
}
180180
if messageSize == 0 {
181181
return try M(
182-
contiguousBytes: [],
182+
serializedBytes: [],
183183
extensions: extensions,
184184
partial: partial,
185185
options: options
186186
)
187187
}
188188
let buffer = try await readBytes(Int(messageSize))
189189
return try M(
190-
contiguousBytes: buffer,
190+
serializedBytes: buffer,
191191
extensions: extensions,
192192
partial: partial,
193193
options: options

Sources/SwiftProtobuf/BinaryDelimited.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public enum BinaryDelimited {
200200
bytesNeeded -= bytesRead
201201
}
202202

203-
try message.merge(contiguousBytes: data,
203+
try message.merge(serializedBytes: data,
204204
extensions: extensions,
205205
partial: partial,
206206
options: options)

Sources/SwiftProtobuf/Docs.docc/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public struct Example: SwiftProtobuf.Message {
6969
// proto2-format messages that utilize extensions.
7070
// See below for more details.
7171
func serializedData() throws -> Data
72-
init<Bytes: SwiftProtobufContiguousBytes>(contiguousBytes: Bytes) throws {
73-
init<Bytes: SwiftProtobufContiguousBytes>(contiguousBytes: Bytes, extensions: ExtensionMap? = nil, partial: Bool = false) throws
72+
init<Bytes: SwiftProtobufContiguousBytes>(serializedBytes: Bytes) throws {
73+
init<Bytes: SwiftProtobufContiguousBytes>(serializedBytes: Bytes, extensions: ExtensionMap? = nil, partial: Bool = false) throws
7474

7575
// Messages can be serialized or deserialized to JSON format
7676
// as either UTF8-encoded Data objects or as Strings.

Sources/SwiftProtobuf/Message+BinaryAdditions.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ extension Message {
7575
return visitor.serializedSize
7676
}
7777

78+
79+
7880
/// Creates a new message by decoding the given `SwiftProtobufContiguousBytes` value
7981
/// containing a serialized message in Protocol Buffer binary format.
8082
///
8183
/// - Parameters:
82-
/// - contiguousBytes: The binary-encoded message data to decode.
84+
/// - serializedBytes: The binary-encoded message data to decode.
8385
/// - extensions: An ``ExtensionMap`` used to look up and decode any
8486
/// extensions in this message or messages nested within this message's
8587
/// fields.
@@ -91,13 +93,13 @@ extension Message {
9193
/// - Throws: ``BinaryDecodingError`` if decoding fails.
9294
@inlinable
9395
public init<Bytes: SwiftProtobufContiguousBytes>(
94-
contiguousBytes bytes: Bytes,
96+
serializedBytes bytes: Bytes,
9597
extensions: (any ExtensionMap)? = nil,
9698
partial: Bool = false,
9799
options: BinaryDecodingOptions = BinaryDecodingOptions()
98100
) throws {
99101
self.init()
100-
try merge(contiguousBytes: bytes, extensions: extensions, partial: partial, options: options)
102+
try merge(serializedBytes: bytes, extensions: extensions, partial: partial, options: options)
101103
}
102104

103105
/// Updates the message by decoding the given `SwiftProtobufContiguousBytes` value
@@ -109,7 +111,7 @@ extension Message {
109111
/// occurred.
110112
///
111113
/// - Parameters:
112-
/// - contiguousBytes: The binary-encoded message data to decode.
114+
/// - serializedBytes: The binary-encoded message data to decode.
113115
/// - extensions: An ``ExtensionMap`` used to look up and decode any
114116
/// extensions in this message or messages nested within this message's
115117
/// fields.
@@ -121,7 +123,7 @@ extension Message {
121123
/// - Throws: ``BinaryDecodingError`` if decoding fails.
122124
@inlinable
123125
public mutating func merge<Bytes: SwiftProtobufContiguousBytes>(
124-
contiguousBytes bytes: Bytes,
126+
serializedBytes bytes: Bytes,
125127
extensions: (any ExtensionMap)? = nil,
126128
partial: Bool = false,
127129
options: BinaryDecodingOptions = BinaryDecodingOptions()

Sources/SwiftProtobuf/Message+BinaryAdditions_Data.swift

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)