From c0bca6893ff358f0bbf179cd99867d90d9fd217e Mon Sep 17 00:00:00 2001 From: George Barnett Date: Thu, 5 Sep 2024 10:40:19 +0100 Subject: [PATCH] Stop using deprecated protobuf API Motivation: swift-protobuf 1.27.0 deprecated the `init` from `serializedData` in favor of the `serializedBytes` variant. Modifications: - Stop using `serializedData` Result: Fewer warnings --- Sources/GRPC/Serialization.swift | 2 +- .../GRPCReflectionService/Server/ReflectionService.swift | 2 +- .../Codegen/Serialization/SerializationTests.swift | 4 +--- .../ReflectionServiceIntegrationTests.swift | 7 +++---- .../ReflectionServiceUnitTests.swift | 6 +++--- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Sources/GRPC/Serialization.swift b/Sources/GRPC/Serialization.swift index a6c590d59..fff0e13ec 100644 --- a/Sources/GRPC/Serialization.swift +++ b/Sources/GRPC/Serialization.swift @@ -76,7 +76,7 @@ public struct ProtobufDeserializer: 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) } } diff --git a/Sources/GRPCReflectionService/Server/ReflectionService.swift b/Sources/GRPCReflectionService/Server/ReflectionService.swift index c55529adf..af9dc2529 100644 --- a/Sources/GRPCReflectionService/Server/ReflectionService.swift +++ b/Sources/GRPCReflectionService/Server/ReflectionService.swift @@ -366,7 +366,7 @@ extension ReflectionService { """ ) } - return try Google_Protobuf_FileDescriptorProto(serializedData: serializedData) + return try Google_Protobuf_FileDescriptorProto(serializedBytes: serializedData) } static func readSerializedFileDescriptorProtos( diff --git a/Tests/GRPCTests/Codegen/Serialization/SerializationTests.swift b/Tests/GRPCTests/Codegen/Serialization/SerializationTests.swift index e9584273c..a4bcd28e8 100644 --- a/Tests/GRPCTests/Codegen/Serialization/SerializationTests.swift +++ b/Tests/GRPCTests/Codegen/Serialization/SerializationTests.swift @@ -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 { diff --git a/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift b/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift index 1fdfca6e5..1836a1f68 100644 --- a/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift +++ b/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift @@ -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") @@ -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.") @@ -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.") diff --git a/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift b/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift index 76c51f2db..69f680311 100644 --- a/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift +++ b/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift @@ -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. @@ -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. @@ -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)