@@ -31,65 +31,27 @@ import SwiftProtobuf
31
31
public protocol Echo_EchoClientProtocol : GRPCClient {
32
32
func get(
33
33
_ request: Echo_EchoRequest ,
34
- callOptions: CallOptions
34
+ callOptions: CallOptions ?
35
35
) -> UnaryCall < Echo_EchoRequest , Echo_EchoResponse >
36
36
37
37
func expand(
38
38
_ request: Echo_EchoRequest ,
39
- callOptions: CallOptions ,
39
+ callOptions: CallOptions ? ,
40
40
handler: @escaping ( Echo_EchoResponse ) -> Void
41
41
) -> ServerStreamingCall < Echo_EchoRequest , Echo_EchoResponse >
42
42
43
43
func collect(
44
- callOptions: CallOptions
44
+ callOptions: CallOptions ?
45
45
) -> ClientStreamingCall < Echo_EchoRequest , Echo_EchoResponse >
46
46
47
47
func update(
48
- callOptions: CallOptions ,
48
+ callOptions: CallOptions ? ,
49
49
handler: @escaping ( Echo_EchoResponse ) -> Void
50
50
) -> BidirectionalStreamingCall < Echo_EchoRequest , Echo_EchoResponse >
51
51
52
52
}
53
53
54
54
extension Echo_EchoClientProtocol {
55
- public func get(
56
- _ request: Echo_EchoRequest
57
- ) -> UnaryCall < Echo_EchoRequest , Echo_EchoResponse > {
58
- return self . get ( request, callOptions: self . defaultCallOptions)
59
- }
60
-
61
- public func expand(
62
- _ request: Echo_EchoRequest ,
63
- handler: @escaping ( Echo_EchoResponse ) -> Void
64
- ) -> ServerStreamingCall < Echo_EchoRequest , Echo_EchoResponse > {
65
- return self . expand ( request, callOptions: self . defaultCallOptions, handler: handler)
66
- }
67
-
68
- public func collect( ) -> ClientStreamingCall < Echo_EchoRequest , Echo_EchoResponse > {
69
- return self . collect ( callOptions: self . defaultCallOptions)
70
- }
71
-
72
- public func update(
73
- handler: @escaping ( Echo_EchoResponse ) -> Void
74
- ) -> BidirectionalStreamingCall < Echo_EchoRequest , Echo_EchoResponse > {
75
- return self . update ( callOptions: self . defaultCallOptions, handler: handler)
76
- }
77
-
78
- }
79
-
80
- public final class Echo_EchoClient : Echo_EchoClientProtocol {
81
- public let channel : GRPCChannel
82
- public var defaultCallOptions : CallOptions
83
-
84
- /// Creates a client for the echo.Echo service.
85
- ///
86
- /// - Parameters:
87
- /// - channel: `GRPCChannel` to the service host.
88
- /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
89
- public init ( channel: GRPCChannel , defaultCallOptions: CallOptions = CallOptions ( ) ) {
90
- self . channel = channel
91
- self . defaultCallOptions = defaultCallOptions
92
- }
93
55
94
56
/// Immediately returns an echo of a request.
95
57
///
@@ -99,12 +61,12 @@ public final class Echo_EchoClient: Echo_EchoClientProtocol {
99
61
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
100
62
public func get(
101
63
_ request: Echo_EchoRequest ,
102
- callOptions: CallOptions
64
+ callOptions: CallOptions ? = nil
103
65
) -> UnaryCall < Echo_EchoRequest , Echo_EchoResponse > {
104
66
return self . makeUnaryCall (
105
67
path: " /echo.Echo/Get " ,
106
68
request: request,
107
- callOptions: callOptions
69
+ callOptions: callOptions ?? self . defaultCallOptions
108
70
)
109
71
}
110
72
@@ -117,13 +79,13 @@ public final class Echo_EchoClient: Echo_EchoClientProtocol {
117
79
/// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
118
80
public func expand(
119
81
_ request: Echo_EchoRequest ,
120
- callOptions: CallOptions ,
82
+ callOptions: CallOptions ? = nil ,
121
83
handler: @escaping ( Echo_EchoResponse ) -> Void
122
84
) -> ServerStreamingCall < Echo_EchoRequest , Echo_EchoResponse > {
123
85
return self . makeServerStreamingCall (
124
86
path: " /echo.Echo/Expand " ,
125
87
request: request,
126
- callOptions: callOptions,
88
+ callOptions: callOptions ?? self . defaultCallOptions ,
127
89
handler: handler
128
90
)
129
91
}
@@ -137,11 +99,11 @@ public final class Echo_EchoClient: Echo_EchoClientProtocol {
137
99
/// - callOptions: Call options.
138
100
/// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
139
101
public func collect(
140
- callOptions: CallOptions
102
+ callOptions: CallOptions ? = nil
141
103
) -> ClientStreamingCall < Echo_EchoRequest , Echo_EchoResponse > {
142
104
return self . makeClientStreamingCall (
143
105
path: " /echo.Echo/Collect " ,
144
- callOptions: callOptions
106
+ callOptions: callOptions ?? self . defaultCallOptions
145
107
)
146
108
}
147
109
@@ -155,17 +117,147 @@ public final class Echo_EchoClient: Echo_EchoClientProtocol {
155
117
/// - handler: A closure called when each response is received from the server.
156
118
/// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
157
119
public func update(
158
- callOptions: CallOptions ,
120
+ callOptions: CallOptions ? = nil ,
159
121
handler: @escaping ( Echo_EchoResponse ) -> Void
160
122
) -> BidirectionalStreamingCall < Echo_EchoRequest , Echo_EchoResponse > {
161
123
return self . makeBidirectionalStreamingCall (
162
124
path: " /echo.Echo/Update " ,
163
- callOptions: callOptions,
125
+ callOptions: callOptions ?? self . defaultCallOptions ,
164
126
handler: handler
165
127
)
166
128
}
167
129
}
168
130
131
+ public final class Echo_EchoClient : Echo_EchoClientProtocol {
132
+ public let channel : GRPCChannel
133
+ public var defaultCallOptions : CallOptions
134
+
135
+ /// Creates a client for the echo.Echo service.
136
+ ///
137
+ /// - Parameters:
138
+ /// - channel: `GRPCChannel` to the service host.
139
+ /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
140
+ public init ( channel: GRPCChannel , defaultCallOptions: CallOptions = CallOptions ( ) ) {
141
+ self . channel = channel
142
+ self . defaultCallOptions = defaultCallOptions
143
+ }
144
+ }
145
+
146
+ public final class Echo_EchoTestClient : Echo_EchoClientProtocol {
147
+ private let fakeChannel : FakeChannel
148
+ public var defaultCallOptions : CallOptions
149
+
150
+ public var channel : GRPCChannel {
151
+ return self . fakeChannel
152
+ }
153
+
154
+ public init (
155
+ fakeChannel: FakeChannel = FakeChannel ( ) ,
156
+ defaultCallOptions callOptions: CallOptions = CallOptions ( )
157
+ ) {
158
+ self . fakeChannel = fakeChannel
159
+ self . defaultCallOptions = callOptions
160
+ }
161
+
162
+ /// Make a unary response for the Get RPC. This must be called
163
+ /// before calling 'get'. See also 'FakeUnaryResponse'.
164
+ ///
165
+ /// - Parameter requestHandler: a handler for request parts sent by the RPC.
166
+ public func makeGetResponseStream(
167
+ _ requestHandler: @escaping ( FakeRequestPart < Echo_EchoRequest > ) -> ( ) = { _ in }
168
+ ) -> FakeUnaryResponse < Echo_EchoRequest , Echo_EchoResponse > {
169
+ return self . fakeChannel. makeFakeUnaryResponse ( path: " /echo.Echo/Get " , requestHandler: requestHandler)
170
+ }
171
+
172
+ public func enqueueGetResponse(
173
+ _ response: Echo_EchoResponse ,
174
+ _ requestHandler: @escaping ( FakeRequestPart < Echo_EchoRequest > ) -> ( ) = { _ in }
175
+ ) {
176
+ let stream = self . makeGetResponseStream ( requestHandler)
177
+ // This is the only operation on the stream; try! is fine.
178
+ try ! stream. sendMessage ( response)
179
+ }
180
+
181
+ /// Returns true if there are response streams enqueued for 'Get'
182
+ public var hasGetResponsesRemaining : Bool {
183
+ return self . fakeChannel. hasFakeResponseEnqueued ( forPath: " /echo.Echo/Get " )
184
+ }
185
+
186
+ /// Make a streaming response for the Expand RPC. This must be called
187
+ /// before calling 'expand'. See also 'FakeStreamingResponse'.
188
+ ///
189
+ /// - Parameter requestHandler: a handler for request parts sent by the RPC.
190
+ public func makeExpandResponseStream(
191
+ _ requestHandler: @escaping ( FakeRequestPart < Echo_EchoRequest > ) -> ( ) = { _ in }
192
+ ) -> FakeStreamingResponse < Echo_EchoRequest , Echo_EchoResponse > {
193
+ return self . fakeChannel. makeFakeStreamingResponse ( path: " /echo.Echo/Expand " , requestHandler: requestHandler)
194
+ }
195
+
196
+ public func enqueueExpandResponses(
197
+ _ responses: [ Echo_EchoResponse ] ,
198
+ _ requestHandler: @escaping ( FakeRequestPart < Echo_EchoRequest > ) -> ( ) = { _ in }
199
+ ) {
200
+ let stream = self . makeExpandResponseStream ( requestHandler)
201
+ // These are the only operation on the stream; try! is fine.
202
+ responses. forEach { try ! stream. sendMessage ( $0) }
203
+ try ! stream. sendEnd ( )
204
+ }
205
+
206
+ /// Returns true if there are response streams enqueued for 'Expand'
207
+ public var hasExpandResponsesRemaining : Bool {
208
+ return self . fakeChannel. hasFakeResponseEnqueued ( forPath: " /echo.Echo/Expand " )
209
+ }
210
+
211
+ /// Make a unary response for the Collect RPC. This must be called
212
+ /// before calling 'collect'. See also 'FakeUnaryResponse'.
213
+ ///
214
+ /// - Parameter requestHandler: a handler for request parts sent by the RPC.
215
+ public func makeCollectResponseStream(
216
+ _ requestHandler: @escaping ( FakeRequestPart < Echo_EchoRequest > ) -> ( ) = { _ in }
217
+ ) -> FakeUnaryResponse < Echo_EchoRequest , Echo_EchoResponse > {
218
+ return self . fakeChannel. makeFakeUnaryResponse ( path: " /echo.Echo/Collect " , requestHandler: requestHandler)
219
+ }
220
+
221
+ public func enqueueCollectResponse(
222
+ _ response: Echo_EchoResponse ,
223
+ _ requestHandler: @escaping ( FakeRequestPart < Echo_EchoRequest > ) -> ( ) = { _ in }
224
+ ) {
225
+ let stream = self . makeCollectResponseStream ( requestHandler)
226
+ // This is the only operation on the stream; try! is fine.
227
+ try ! stream. sendMessage ( response)
228
+ }
229
+
230
+ /// Returns true if there are response streams enqueued for 'Collect'
231
+ public var hasCollectResponsesRemaining : Bool {
232
+ return self . fakeChannel. hasFakeResponseEnqueued ( forPath: " /echo.Echo/Collect " )
233
+ }
234
+
235
+ /// Make a streaming response for the Update RPC. This must be called
236
+ /// before calling 'update'. See also 'FakeStreamingResponse'.
237
+ ///
238
+ /// - Parameter requestHandler: a handler for request parts sent by the RPC.
239
+ public func makeUpdateResponseStream(
240
+ _ requestHandler: @escaping ( FakeRequestPart < Echo_EchoRequest > ) -> ( ) = { _ in }
241
+ ) -> FakeStreamingResponse < Echo_EchoRequest , Echo_EchoResponse > {
242
+ return self . fakeChannel. makeFakeStreamingResponse ( path: " /echo.Echo/Update " , requestHandler: requestHandler)
243
+ }
244
+
245
+ public func enqueueUpdateResponses(
246
+ _ responses: [ Echo_EchoResponse ] ,
247
+ _ requestHandler: @escaping ( FakeRequestPart < Echo_EchoRequest > ) -> ( ) = { _ in }
248
+ ) {
249
+ let stream = self . makeUpdateResponseStream ( requestHandler)
250
+ // These are the only operation on the stream; try! is fine.
251
+ responses. forEach { try ! stream. sendMessage ( $0) }
252
+ try ! stream. sendEnd ( )
253
+ }
254
+
255
+ /// Returns true if there are response streams enqueued for 'Update'
256
+ public var hasUpdateResponsesRemaining : Bool {
257
+ return self . fakeChannel. hasFakeResponseEnqueued ( forPath: " /echo.Echo/Update " )
258
+ }
259
+ }
260
+
169
261
/// To build a server, implement a class that conforms to this protocol.
170
262
public protocol Echo_EchoProvider : CallHandlerProvider {
171
263
/// Immediately returns an echo of a request.
0 commit comments