diff --git a/Tests/GRPCNIOTransportHTTP2Tests/ControlMessages.swift b/Tests/GRPCNIOTransportHTTP2Tests/ControlMessages.swift index eddca49..f66f735 100644 --- a/Tests/GRPCNIOTransportHTTP2Tests/ControlMessages.swift +++ b/Tests/GRPCNIOTransportHTTP2Tests/ControlMessages.swift @@ -133,22 +133,3 @@ enum CancellationKind: Codable { struct Empty: Codable { } - -struct JSONSerializer: MessageSerializer { - private let encoder = JSONEncoder() - - func serialize(_ message: Message) throws -> Bytes { - let data = try self.encoder.encode(message) - return Bytes(data) - } -} - -struct JSONDeserializer: MessageDeserializer { - private let decoder = JSONDecoder() - - func deserialize(_ serializedMessageBytes: Bytes) throws -> Message { - try serializedMessageBytes.withUnsafeBytes { - try self.decoder.decode(Message.self, from: Data($0)) - } - } -} diff --git a/Tests/GRPCNIOTransportHTTP2Tests/Test Utilities/JSONSerializing.swift b/Tests/GRPCNIOTransportHTTP2Tests/Test Utilities/JSONSerializing.swift new file mode 100644 index 0000000..bc47c0f --- /dev/null +++ b/Tests/GRPCNIOTransportHTTP2Tests/Test Utilities/JSONSerializing.swift @@ -0,0 +1,37 @@ +/* + * 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 -> Bytes { + let data = try self.encoder.encode(message) + return Bytes(data) + } +} + +struct JSONDeserializer: MessageDeserializer { + private let decoder = JSONDecoder() + + func deserialize(_ serializedMessageBytes: Bytes) throws -> Message { + try serializedMessageBytes.withUnsafeBytes { + try self.decoder.decode(Message.self, from: Data($0)) + } + } +}