@@ -28,7 +28,7 @@ struct Serve: AsyncParsableCommand {
28
28
let server = GRPCServer (
29
29
transport: . http2NIOPosix(
30
30
address: . ipv4( host: " 127.0.0.1 " , port: self . port) ,
31
- config : . defaults ( transportSecurity: . plaintext)
31
+ transportSecurity: . plaintext
32
32
) ,
33
33
services: [ EchoService ( ) ]
34
34
)
@@ -42,44 +42,40 @@ struct Serve: AsyncParsableCommand {
42
42
}
43
43
}
44
44
45
- struct EchoService : Echo_Echo_ServiceProtocol {
45
+ struct EchoService : Echo_Echo . SimpleServiceProtocol {
46
46
func get(
47
- request: ServerRequest < Echo_EchoRequest > ,
47
+ request: Echo_EchoRequest ,
48
48
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 }
51
51
}
52
52
53
53
func collect(
54
- request: StreamingServerRequest < Echo_EchoRequest > ,
54
+ request: RPCAsyncSequence < Echo_EchoRequest , any Error > ,
55
55
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) }
58
58
let joined = messages. joined ( separator: " " )
59
- return ServerResponse ( message : . with { $0. text = joined } )
59
+ return . with { $0. text = joined }
60
60
}
61
61
62
62
func expand(
63
- request: ServerRequest < Echo_EchoRequest > ,
63
+ request: Echo_EchoRequest ,
64
+ response: RPCWriter < Echo_EchoResponse > ,
64
65
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)
72
70
}
73
71
74
72
func update(
75
- request: StreamingServerRequest < Echo_EchoRequest > ,
73
+ request: RPCAsyncSequence < Echo_EchoRequest , any Error > ,
74
+ response: RPCWriter < Echo_EchoResponse > ,
76
75
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 } )
83
79
}
84
80
}
85
81
}
0 commit comments