@@ -37,6 +37,9 @@ extension Generator {
37
37
printServiceClientProtocol ( asynchronousCode: asynchronousCode,
38
38
synchronousCode: synchronousCode)
39
39
println ( )
40
+ printServiceClientProtocolExtension ( asynchronousCode: asynchronousCode,
41
+ synchronousCode: synchronousCode)
42
+ println ( )
40
43
printServiceClientImplementation ( asynchronousCode: asynchronousCode,
41
44
synchronousCode: synchronousCode)
42
45
if options. generateTestStubs {
@@ -158,27 +161,79 @@ extension Generator {
158
161
case . unary:
159
162
if synchronousCode {
160
163
println ( " /// Synchronous. Unary. " )
161
- println ( " func \( methodFunctionName) (_ request: \( methodInputName) ) throws -> \( methodOutputName) " )
164
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata ) throws -> \( methodOutputName) " )
162
165
}
163
166
if asynchronousCode {
164
167
println ( " /// Asynchronous. Unary. " )
165
- println ( " func \( methodFunctionName) (_ request: \( methodInputName) , completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) " )
168
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata, completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) " )
166
169
}
167
170
case . serverStreaming:
168
171
println ( " /// Asynchronous. Server-streaming. " )
169
172
println ( " /// Send the initial message. " )
170
173
println ( " /// Use methods on the returned object to get streamed responses. " )
171
- println ( " func \( methodFunctionName) (_ request: \( methodInputName) , completion: ((CallResult) -> Void)?) throws -> \( callName) " )
174
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) " )
172
175
case . clientStreaming:
173
176
println ( " /// Asynchronous. Client-streaming. " )
174
177
println ( " /// Use methods on the returned object to stream messages and " )
175
178
println ( " /// to close the connection and wait for a final response. " )
176
- println ( " func \( methodFunctionName) (completion: ((CallResult) -> Void)?) throws -> \( callName) " )
179
+ println ( " func \( methodFunctionName) (metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) " )
177
180
case . bidirectionalStreaming:
178
181
println ( " /// Asynchronous. Bidirectional-streaming. " )
179
182
println ( " /// Use methods on the returned object to stream messages, " )
180
183
println ( " /// to wait for replies, and to close the connection. " )
181
- println ( " func \( methodFunctionName) (completion: ((CallResult) -> Void)?) throws -> \( callName) " )
184
+ println ( " func \( methodFunctionName) (metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) " )
185
+ }
186
+ println ( )
187
+ }
188
+ outdent ( )
189
+ println ( " } " )
190
+ }
191
+
192
+ private func printServiceClientProtocolExtension( asynchronousCode: Bool ,
193
+ synchronousCode: Bool ) {
194
+ println ( " \( options. visibility. sourceSnippet) extension \( serviceClassName) { " )
195
+ indent ( )
196
+ for method in service. methods {
197
+ self . method = method
198
+ switch streamingType ( method) {
199
+ case . unary:
200
+ if synchronousCode {
201
+ println ( " /// Synchronous. Unary. " )
202
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) ) throws -> \( methodOutputName) { " )
203
+ indent ( )
204
+ println ( " return try self. \( methodFunctionName) (request, metadata: self.metadata) " )
205
+ outdent ( )
206
+ println ( " } " )
207
+ }
208
+ if asynchronousCode {
209
+ println ( " /// Asynchronous. Unary. " )
210
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) { " )
211
+ indent ( )
212
+ println ( " return try self. \( methodFunctionName) (request, metadata: self.metadata, completion: completion) " )
213
+ outdent ( )
214
+ println ( " } " )
215
+ }
216
+ case . serverStreaming:
217
+ println ( " /// Asynchronous. Server-streaming. " )
218
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
219
+ indent ( )
220
+ println ( " return try self. \( methodFunctionName) (request, metadata: self.metadata, completion: completion) " )
221
+ outdent ( )
222
+ println ( " } " )
223
+ case . clientStreaming:
224
+ println ( " /// Asynchronous. Client-streaming. " )
225
+ println ( " func \( methodFunctionName) (completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
226
+ indent ( )
227
+ println ( " return try self. \( methodFunctionName) (metadata: self.metadata, completion: completion) " )
228
+ outdent ( )
229
+ println ( " } " )
230
+ case . bidirectionalStreaming:
231
+ println ( " /// Asynchronous. Bidirectional-streaming. " )
232
+ println ( " func \( methodFunctionName) (completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
233
+ indent ( )
234
+ println ( " return try self. \( methodFunctionName) (metadata: self.metadata, completion: completion) " )
235
+ outdent ( )
236
+ println ( " } " )
182
237
}
183
238
println ( )
184
239
}
@@ -196,22 +251,22 @@ extension Generator {
196
251
case . unary:
197
252
if synchronousCode {
198
253
println ( " /// Synchronous. Unary. " )
199
- println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) ) throws -> \( methodOutputName) { " )
254
+ println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata ) throws -> \( methodOutputName) { " )
200
255
indent ( )
201
256
println ( " return try \( callName) Base(channel) " )
202
257
indent ( )
203
- println ( " .run(request: request, metadata: metadata ) " )
258
+ println ( " .run(request: request, metadata: customMetadata ) " )
204
259
outdent ( )
205
260
outdent ( )
206
261
println ( " } " )
207
262
}
208
263
if asynchronousCode {
209
264
println ( " /// Asynchronous. Unary. " )
210
- println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) , completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) { " )
265
+ println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata, completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) { " )
211
266
indent ( )
212
267
println ( " return try \( callName) Base(channel) " )
213
268
indent ( )
214
- println ( " .start(request: request, metadata: metadata , completion: completion) " )
269
+ println ( " .start(request: request, metadata: customMetadata , completion: completion) " )
215
270
outdent ( )
216
271
outdent ( )
217
272
println ( " } " )
@@ -220,35 +275,35 @@ extension Generator {
220
275
println ( " /// Asynchronous. Server-streaming. " )
221
276
println ( " /// Send the initial message. " )
222
277
println ( " /// Use methods on the returned object to get streamed responses. " )
223
- println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) , completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
278
+ println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
224
279
indent ( )
225
280
println ( " return try \( callName) Base(channel) " )
226
281
indent ( )
227
- println ( " .start(request: request, metadata: metadata , completion: completion) " )
282
+ println ( " .start(request: request, metadata: customMetadata , completion: completion) " )
228
283
outdent ( )
229
284
outdent ( )
230
285
println ( " } " )
231
286
case . clientStreaming:
232
287
println ( " /// Asynchronous. Client-streaming. " )
233
288
println ( " /// Use methods on the returned object to stream messages and " )
234
289
println ( " /// to close the connection and wait for a final response. " )
235
- println ( " \( access) func \( methodFunctionName) (completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
290
+ println ( " \( access) func \( methodFunctionName) (metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
236
291
indent ( )
237
292
println ( " return try \( callName) Base(channel) " )
238
293
indent ( )
239
- println ( " .start(metadata: metadata , completion: completion) " )
294
+ println ( " .start(metadata: customMetadata , completion: completion) " )
240
295
outdent ( )
241
296
outdent ( )
242
297
println ( " } " )
243
298
case . bidirectionalStreaming:
244
299
println ( " /// Asynchronous. Bidirectional-streaming. " )
245
300
println ( " /// Use methods on the returned object to stream messages, " )
246
301
println ( " /// to wait for replies, and to close the connection. " )
247
- println ( " \( access) func \( methodFunctionName) (completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
302
+ println ( " \( access) func \( methodFunctionName) (metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
248
303
indent ( )
249
304
println ( " return try \( callName) Base(channel) " )
250
305
indent ( )
251
- println ( " .start(metadata: metadata , completion: completion) " )
306
+ println ( " .start(metadata: customMetadata , completion: completion) " )
252
307
outdent ( )
253
308
outdent ( )
254
309
println ( " } " )
@@ -268,22 +323,22 @@ extension Generator {
268
323
case . unary:
269
324
println ( " var \( methodFunctionName) Requests: [ \( methodInputName) ] = [] " )
270
325
println ( " var \( methodFunctionName) Responses: [ \( methodOutputName) ] = [] " )
271
- println ( " func \( methodFunctionName) (_ request: \( methodInputName) ) throws -> \( methodOutputName) { " )
326
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata ) throws -> \( methodOutputName) { " )
272
327
indent ( )
273
328
println ( " \( methodFunctionName) Requests.append(request) " )
274
329
println ( " defer { \( methodFunctionName) Responses.removeFirst() } " )
275
330
println ( " return \( methodFunctionName) Responses.first! " )
276
331
outdent ( )
277
332
println ( " } " )
278
- println ( " func \( methodFunctionName) (_ request: \( methodInputName) , completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) { " )
333
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata, completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) { " )
279
334
indent ( )
280
335
println ( " fatalError( \" not implemented \" ) " )
281
336
outdent ( )
282
337
println ( " } " )
283
338
case . serverStreaming:
284
339
println ( " var \( methodFunctionName) Requests: [ \( methodInputName) ] = [] " )
285
340
println ( " var \( methodFunctionName) Calls: [ \( callName) ] = [] " )
286
- println ( " func \( methodFunctionName) (_ request: \( methodInputName) , completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
341
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
287
342
indent ( )
288
343
println ( " \( methodFunctionName) Requests.append(request) " )
289
344
println ( " defer { \( methodFunctionName) Calls.removeFirst() } " )
@@ -292,15 +347,15 @@ extension Generator {
292
347
println ( " } " )
293
348
case . clientStreaming:
294
349
println ( " var \( methodFunctionName) Calls: [ \( callName) ] = [] " )
295
- println ( " func \( methodFunctionName) (completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
350
+ println ( " func \( methodFunctionName) (metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
296
351
indent ( )
297
352
println ( " defer { \( methodFunctionName) Calls.removeFirst() } " )
298
353
println ( " return \( methodFunctionName) Calls.first! " )
299
354
outdent ( )
300
355
println ( " } " )
301
356
case . bidirectionalStreaming:
302
357
println ( " var \( methodFunctionName) Calls: [ \( callName) ] = [] " )
303
- println ( " func \( methodFunctionName) (completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
358
+ println ( " func \( methodFunctionName) (metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \( callName) { " )
304
359
indent ( )
305
360
println ( " defer { \( methodFunctionName) Calls.removeFirst() } " )
306
361
println ( " return \( methodFunctionName) Calls.first! " )
0 commit comments