Skip to content

Commit 202ba35

Browse files
committed
fix up peer info
1 parent 40cb657 commit 202ba35

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Tests/GRPCInProcessTransportTests/InProcessTransportTests.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import GRPCCore
1818
import GRPCInProcessTransport
1919
import Testing
20+
import struct Foundation.Data
21+
import class Foundation.JSONDecoder
22+
import class Foundation.JSONEncoder
2023

2124
@Suite("InProcess transport")
2225
struct InProcessTransportTests {
@@ -172,14 +175,16 @@ private struct PeerInfo: Codable {
172175
}
173176

174177
private struct PeerInfoSerializer: MessageSerializer {
175-
func serialize(_ message: PeerInfo) throws -> [UInt8] {
176-
Array("\(message.local) \(message.remote)".utf8)
178+
func serialize<Bytes: GRPCContiguousBytes>(_ message: PeerInfo) throws -> Bytes {
179+
Bytes("\(message.local) \(message.remote)".utf8)
177180
}
178181
}
179182

180183
private struct PeerInfoDeserializer: MessageDeserializer {
181-
func deserialize(_ serializedMessageBytes: [UInt8]) throws -> PeerInfo {
182-
let stringPeerInfo = String(decoding: serializedMessageBytes, as: UTF8.self)
184+
func deserialize<Bytes: GRPCContiguousBytes>(_ serializedMessageBytes: Bytes) throws -> PeerInfo {
185+
let stringPeerInfo = serializedMessageBytes.withUnsafeBytes {
186+
String(decoding: $0, as: UTF8.self)
187+
}
183188
let peerInfoComponents = stringPeerInfo.split(separator: " ")
184189
return PeerInfo(local: String(peerInfoComponents[0]), remote: String(peerInfoComponents[1]))
185190
}

0 commit comments

Comments
 (0)