Skip to content

Commit

Permalink
Stop using deprecated protobuf API (#2045)
Browse files Browse the repository at this point in the history
Motivation:

swift-protobuf 1.27.0 deprecated the `init` from `serializedData` in
favor of the `serializedBytes` variant.

Modifications:

- Stop using `serializedData`

Result:

Fewer warnings
  • Loading branch information
glbrntt authored Sep 5, 2024
1 parent a06ade3 commit 3be62d5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Sources/GRPC/Serialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public struct ProtobufDeserializer<Message: SwiftProtobuf.Message>: MessageDeser
var buffer = byteBuffer
// '!' is okay; we can always read 'readableBytes'.
let data = buffer.readData(length: buffer.readableBytes)!
return try Message(serializedData: data)
return try Message(serializedBytes: data)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ extension ReflectionService {
"""
)
}
return try Google_Protobuf_FileDescriptorProto(serializedData: serializedData)
return try Google_Protobuf_FileDescriptorProto(serializedBytes: serializedData)
}

static func readSerializedFileDescriptorProtos(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ final class SerializationTests: GRPCTestCase {
.deletingLastPathComponent().appendingPathComponent("echo.grpc.reflection")
let base64EncodedData = try! Data(contentsOf: binaryFileURL)
let binaryData = Data(base64Encoded: base64EncodedData)!
self
.fileDescriptorProto =
try! Google_Protobuf_FileDescriptorProto(serializedData: binaryData)
self.fileDescriptorProto = try! Google_Protobuf_FileDescriptorProto(serializedBytes: binaryData)
}

func testFileDescriptorMetadata() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {
// response can't be nil as we just checked it.
let receivedFileDescriptorProto =
try Google_Protobuf_FileDescriptorProto(
serializedData: (message.fileDescriptorResponse
.fileDescriptorProto[0])
serializedBytes: message.fileDescriptorResponse.fileDescriptorProto[0]
)

XCTAssertEqual(receivedFileDescriptorProto.name, "bar1.proto")
Expand Down Expand Up @@ -177,7 +176,7 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {
let receivedData: [Google_Protobuf_FileDescriptorProto]
do {
receivedData = try message.fileDescriptorResponse.fileDescriptorProto.map {
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
}
} catch {
return XCTFail("Could not serialize data received as a message.")
Expand Down Expand Up @@ -221,7 +220,7 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {
let receivedData: [Google_Protobuf_FileDescriptorProto]
do {
receivedData = try message.fileDescriptorResponse.fileDescriptorProto.map {
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
}
} catch {
return XCTFail("Could not serialize data received as a message.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
switch serializedFileDescriptorProtosResult {
case .success(let serializedFileDescriptorProtos):
let fileDescriptorProtos = try serializedFileDescriptorProtos.map {
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
}
// Tests that the functions returns all the transitive dependencies, with their services and
// methods, together with the initial proto, as serialized data.
Expand Down Expand Up @@ -233,7 +233,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
switch serializedFileDescriptorProtosResult {
case .success(let serializedFileDescriptorProtos):
let fileDescriptorProtos = try serializedFileDescriptorProtos.map {
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
}
// Tests that the functions returns all the tranzitive dependencies, with their services and
// methods, together with the initial proto, as serialized data.
Expand Down Expand Up @@ -292,7 +292,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
switch serializedFileDescriptorProtosResult {
case .success(let serializedFileDescriptorProtos):
let fileDescriptorProtos = try serializedFileDescriptorProtos.map {
try Google_Protobuf_FileDescriptorProto(serializedData: $0)
try Google_Protobuf_FileDescriptorProto(serializedBytes: $0)
}
// Test that we get only 4 serialized File Descriptor Protos as response.
XCTAssertEqual(fileDescriptorProtos.count, 4)
Expand Down

0 comments on commit 3be62d5

Please sign in to comment.