From 837b94b6dde76703590a10140376e999975c4884 Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Fri, 17 Jan 2025 10:59:49 +0000 Subject: [PATCH] Move test JSON (de)serializer to its own file --- .../ControlMessages.swift | 17 --------- .../Test Utilities/JSONSerializing.swift | 35 +++++++++++++++++++ 2 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 Tests/GRPCNIOTransportHTTP2Tests/Test Utilities/JSONSerializing.swift diff --git a/Tests/GRPCNIOTransportHTTP2Tests/ControlMessages.swift b/Tests/GRPCNIOTransportHTTP2Tests/ControlMessages.swift index dfce195..f66f735 100644 --- a/Tests/GRPCNIOTransportHTTP2Tests/ControlMessages.swift +++ b/Tests/GRPCNIOTransportHTTP2Tests/ControlMessages.swift @@ -133,20 +133,3 @@ enum CancellationKind: Codable { struct Empty: Codable { } - -struct JSONSerializer: MessageSerializer { - private let encoder = JSONEncoder() - - func serialize(_ message: Message) throws -> [UInt8] { - let data = try self.encoder.encode(message) - return Array(data) - } -} - -struct JSONDeserializer: MessageDeserializer { - private let decoder = JSONDecoder() - - func deserialize(_ serializedMessageBytes: [UInt8]) throws -> Message { - try self.decoder.decode(Message.self, from: Data(serializedMessageBytes)) - } -} diff --git a/Tests/GRPCNIOTransportHTTP2Tests/Test Utilities/JSONSerializing.swift b/Tests/GRPCNIOTransportHTTP2Tests/Test Utilities/JSONSerializing.swift new file mode 100644 index 0000000..da44de4 --- /dev/null +++ b/Tests/GRPCNIOTransportHTTP2Tests/Test Utilities/JSONSerializing.swift @@ -0,0 +1,35 @@ +/* + * Copyright 2025, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Foundation +import GRPCCore + +struct JSONSerializer: MessageSerializer { + private let encoder = JSONEncoder() + + func serialize(_ message: Message) throws -> [UInt8] { + let data = try self.encoder.encode(message) + return Array(data) + } +} + +struct JSONDeserializer: MessageDeserializer { + private let decoder = JSONDecoder() + + func deserialize(_ serializedMessageBytes: [UInt8]) throws -> Message { + try self.decoder.decode(Message.self, from: Data(serializedMessageBytes)) + } +}