Skip to content

Commit 3be62d5

Browse files
authored
Stop using deprecated protobuf API (#2045)
Motivation: swift-protobuf 1.27.0 deprecated the `init` from `serializedData` in favor of the `serializedBytes` variant. Modifications: - Stop using `serializedData` Result: Fewer warnings
1 parent a06ade3 commit 3be62d5

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

Sources/GRPC/Serialization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct ProtobufDeserializer<Message: SwiftProtobuf.Message>: MessageDeser
7676
var buffer = byteBuffer
7777
// '!' is okay; we can always read 'readableBytes'.
7878
let data = buffer.readData(length: buffer.readableBytes)!
79-
return try Message(serializedData: data)
79+
return try Message(serializedBytes: data)
8080
}
8181
}
8282

Sources/GRPCReflectionService/Server/ReflectionService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ extension ReflectionService {
366366
"""
367367
)
368368
}
369-
return try Google_Protobuf_FileDescriptorProto(serializedData: serializedData)
369+
return try Google_Protobuf_FileDescriptorProto(serializedBytes: serializedData)
370370
}
371371

372372
static func readSerializedFileDescriptorProtos(

Tests/GRPCTests/Codegen/Serialization/SerializationTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ final class SerializationTests: GRPCTestCase {
2828
.deletingLastPathComponent().appendingPathComponent("echo.grpc.reflection")
2929
let base64EncodedData = try! Data(contentsOf: binaryFileURL)
3030
let binaryData = Data(base64Encoded: base64EncodedData)!
31-
self
32-
.fileDescriptorProto =
33-
try! Google_Protobuf_FileDescriptorProto(serializedData: binaryData)
31+
self.fileDescriptorProto = try! Google_Protobuf_FileDescriptorProto(serializedBytes: binaryData)
3432
}
3533

3634
func testFileDescriptorMetadata() throws {

Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {
128128
// response can't be nil as we just checked it.
129129
let receivedFileDescriptorProto =
130130
try Google_Protobuf_FileDescriptorProto(
131-
serializedData: (message.fileDescriptorResponse
132-
.fileDescriptorProto[0])
131+
serializedBytes: message.fileDescriptorResponse.fileDescriptorProto[0]
133132
)
134133

135134
XCTAssertEqual(receivedFileDescriptorProto.name, "bar1.proto")
@@ -177,7 +176,7 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {
177176
let receivedData: [Google_Protobuf_FileDescriptorProto]
178177
do {
179178
receivedData = try message.fileDescriptorResponse.fileDescriptorProto.map {
180-
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
179+
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
181180
}
182181
} catch {
183182
return XCTFail("Could not serialize data received as a message.")
@@ -221,7 +220,7 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {
221220
let receivedData: [Google_Protobuf_FileDescriptorProto]
222221
do {
223222
receivedData = try message.fileDescriptorResponse.fileDescriptorProto.map {
224-
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
223+
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
225224
}
226225
} catch {
227226
return XCTFail("Could not serialize data received as a message.")

Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
178178
switch serializedFileDescriptorProtosResult {
179179
case .success(let serializedFileDescriptorProtos):
180180
let fileDescriptorProtos = try serializedFileDescriptorProtos.map {
181-
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
181+
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
182182
}
183183
// Tests that the functions returns all the transitive dependencies, with their services and
184184
// methods, together with the initial proto, as serialized data.
@@ -233,7 +233,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
233233
switch serializedFileDescriptorProtosResult {
234234
case .success(let serializedFileDescriptorProtos):
235235
let fileDescriptorProtos = try serializedFileDescriptorProtos.map {
236-
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
236+
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
237237
}
238238
// Tests that the functions returns all the tranzitive dependencies, with their services and
239239
// methods, together with the initial proto, as serialized data.
@@ -292,7 +292,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
292292
switch serializedFileDescriptorProtosResult {
293293
case .success(let serializedFileDescriptorProtos):
294294
let fileDescriptorProtos = try serializedFileDescriptorProtos.map {
295-
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
295+
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
296296
}
297297
// Test that we get only 4 serialized File Descriptor Protos as response.
298298
XCTAssertEqual(fileDescriptorProtos.count, 4)

0 commit comments

Comments
 (0)