Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
glbrntt committed Jan 17, 2025
1 parent 1da32b6 commit e2bdb70
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,28 @@ struct ChannelDebugCallbackTests {
kind: TransportKind,
address: SocketAddress,
debug: HTTP2ServerTransport.Config.ChannelDebuggingCallbacks
) -> any ServerTransport {
) -> NIOServerTransport {
switch kind {
case .posix:
return .http2NIOPosix(
address: address,
transportSecurity: .plaintext,
config: .defaults {
$0.channelDebuggingCallbacks = debug
}
return NIOServerTransport(
.http2NIOPosix(
address: address,
transportSecurity: .plaintext,
config: .defaults {
$0.channelDebuggingCallbacks = debug
}
)
)
#if canImport(Network)
case .transportServices:
return .http2NIOTS(
address: address,
transportSecurity: .plaintext,
config: .defaults {
$0.channelDebuggingCallbacks = debug
}
return NIOServerTransport(
.http2NIOTS(
address: address,
transportSecurity: .plaintext,
config: .defaults {
$0.channelDebuggingCallbacks = debug
}
)
)
#endif
}
Expand All @@ -120,24 +124,28 @@ struct ChannelDebugCallbackTests {
kind: TransportKind,
target: any ResolvableTarget,
debug: HTTP2ClientTransport.Config.ChannelDebuggingCallbacks
) throws -> any ClientTransport {
) throws -> NIOClientTransport {
switch kind {
case .posix:
return try .http2NIOPosix(
target: target,
transportSecurity: .plaintext,
config: .defaults {
$0.channelDebuggingCallbacks = debug
}
return NIOClientTransport(
try .http2NIOPosix(
target: target,
transportSecurity: .plaintext,
config: .defaults {
$0.channelDebuggingCallbacks = debug
}
)
)
#if canImport(Network)
case .transportServices:
return try .http2NIOTS(
target: target,
transportSecurity: .plaintext,
config: .defaults {
$0.channelDebuggingCallbacks = debug
}
return NIOClientTransport(
try .http2NIOTS(
target: target,
transportSecurity: .plaintext,
config: .defaults {
$0.channelDebuggingCallbacks = debug
}
)
)
#endif
}
Expand Down
12 changes: 7 additions & 5 deletions Tests/GRPCNIOTransportHTTP2Tests/Test Utilities/JSONCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import class Foundation.JSONDecoder
#endif

struct JSONCoder<Message: Codable>: MessageSerializer, MessageDeserializer {
func serialize(_ message: Message) throws -> [UInt8] {
func serialize<Bytes: GRPCContiguousBytes>(_ message: Message) throws -> Bytes {
let json = JSONEncoder()
let bytes = try json.encode(message)
return Array(bytes)
let data = try json.encode(message)
return Bytes(data)
}

func deserialize(_ serializedMessageBytes: [UInt8]) throws -> Message {
func deserialize<Bytes: GRPCContiguousBytes>(_ serializedMessageBytes: Bytes) throws -> Message {
let json = JSONDecoder()
let data = Data(serializedMessageBytes)
let data = serializedMessageBytes.withUnsafeBytes {
Data($0)
}
return try json.decode(Message.self, from: data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct StatsService {
}

extension StatsService: RegistrableRPCService {
func registerMethods(with router: inout RPCRouter) {
func registerMethods<Transport: ServerTransport>(with router: inout RPCRouter<Transport>) {
router.registerHandler(
forMethod: .getStats,
deserializer: JSONCoder<GetStatsRequest>(),
Expand All @@ -79,10 +79,10 @@ extension StatsService: RegistrableRPCService {
}
}

struct StatsClient {
private let underlying: GRPCClient
struct StatsClient<Transport: ClientTransport> {
private let underlying: GRPCClient<Transport>

init(wrapping underlying: GRPCClient) {
init(wrapping underlying: GRPCClient<Transport>) {
self.underlying = underlying
}

Expand Down

0 comments on commit e2bdb70

Please sign in to comment.