@@ -28,7 +28,7 @@ struct Serve: AsyncParsableCommand {
2828 let server = GRPCServer (
2929 transport: . http2NIOPosix(
3030 address: . ipv4( host: " 127.0.0.1 " , port: self . port) ,
31- config : . defaults ( transportSecurity: . plaintext)
31+ transportSecurity: . plaintext
3232 ) ,
3333 services: [ EchoService ( ) ]
3434 )
@@ -42,44 +42,40 @@ struct Serve: AsyncParsableCommand {
4242 }
4343}
4444
45- struct EchoService : Echo_Echo_ServiceProtocol {
45+ struct EchoService : Echo_Echo . SimpleServiceProtocol {
4646 func get(
47- request: ServerRequest < Echo_EchoRequest > ,
47+ request: Echo_EchoRequest ,
4848 context: ServerContext
49- ) async throws -> ServerResponse < Echo_EchoResponse > {
50- return ServerResponse ( message : . with { $0. text = request. message . text } )
49+ ) async throws -> Echo_EchoResponse {
50+ return . with { $0. text = request. text }
5151 }
5252
5353 func collect(
54- request: StreamingServerRequest < Echo_EchoRequest > ,
54+ request: RPCAsyncSequence < Echo_EchoRequest , any Error > ,
5555 context: ServerContext
56- ) async throws -> ServerResponse < Echo_EchoResponse > {
57- let messages = try await request. messages . reduce ( into: [ ] ) { $0. append ( $1. text) }
56+ ) async throws -> Echo_EchoResponse {
57+ let messages = try await request. reduce ( into: [ ] ) { $0. append ( $1. text) }
5858 let joined = messages. joined ( separator: " " )
59- return ServerResponse ( message : . with { $0. text = joined } )
59+ return . with { $0. text = joined }
6060 }
6161
6262 func expand(
63- request: ServerRequest < Echo_EchoRequest > ,
63+ request: Echo_EchoRequest ,
64+ response: RPCWriter < Echo_EchoResponse > ,
6465 context: ServerContext
65- ) async throws -> StreamingServerResponse < Echo_EchoResponse > {
66- return StreamingServerResponse { writer in
67- let parts = request. message. text. split ( separator: " " )
68- let messages = parts. map { part in Echo_EchoResponse . with { $0. text = String ( part) } }
69- try await writer. write ( contentsOf: messages)
70- return [ : ]
71- }
66+ ) async throws {
67+ let parts = request. text. split ( separator: " " )
68+ let messages = parts. map { part in Echo_EchoResponse . with { $0. text = String ( part) } }
69+ try await response. write ( contentsOf: messages)
7270 }
7371
7472 func update(
75- request: StreamingServerRequest < Echo_EchoRequest > ,
73+ request: RPCAsyncSequence < Echo_EchoRequest , any Error > ,
74+ response: RPCWriter < Echo_EchoResponse > ,
7675 context: ServerContext
77- ) async throws -> StreamingServerResponse < Echo_EchoResponse > {
78- return StreamingServerResponse { writer in
79- for try await message in request. messages {
80- try await writer. write ( . with { $0. text = message. text } )
81- }
82- return [ : ]
76+ ) async throws {
77+ for try await message in request {
78+ try await response. write ( . with { $0. text = message. text } )
8379 }
8480 }
8581}
0 commit comments