Generator-Client.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /*
  2. * Copyright 2018, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. import SwiftProtobuf
  18. import SwiftProtobufPluginLibrary
  19. extension Generator {
  20. internal func printClient(asynchronousCode: Bool,
  21. synchronousCode: Bool) {
  22. if options.generateNIOImplementation {
  23. printNIOGRPCClient()
  24. } else {
  25. printCGRPCClient(asynchronousCode: asynchronousCode,
  26. synchronousCode: synchronousCode)
  27. }
  28. }
  29. private func printCGRPCClient(asynchronousCode: Bool,
  30. synchronousCode: Bool) {
  31. for method in service.methods {
  32. self.method = method
  33. switch streamingType(method) {
  34. case .unary:
  35. printServiceClientMethodCallUnary()
  36. case .serverStreaming:
  37. printServiceClientMethodCallServerStreaming()
  38. case .clientStreaming:
  39. printServiceClientMethodCallClientStreaming()
  40. case .bidirectionalStreaming:
  41. printServiceClientMethodCallBidiStreaming()
  42. }
  43. }
  44. println()
  45. printServiceClientProtocol(asynchronousCode: asynchronousCode,
  46. synchronousCode: synchronousCode)
  47. println()
  48. printServiceClientProtocolExtension(asynchronousCode: asynchronousCode,
  49. synchronousCode: synchronousCode)
  50. println()
  51. printServiceClientImplementation(asynchronousCode: asynchronousCode,
  52. synchronousCode: synchronousCode)
  53. }
  54. func printCGRPCClientTestStubs(asynchronousCode: Bool,
  55. synchronousCode: Bool) {
  56. for method in service.methods {
  57. self.method = method
  58. switch streamingType(method) {
  59. case .unary:
  60. printServiceClientMethodCallUnaryTestStub()
  61. case .serverStreaming:
  62. printServiceClientMethodCallServerStreamingTestStub()
  63. case .clientStreaming:
  64. printServiceClientMethodCallClientStreamingTestStub()
  65. case .bidirectionalStreaming:
  66. printServiceClientMethodCallBidiStreamingTestStub()
  67. }
  68. }
  69. println()
  70. printServiceClientTestStubs(asynchronousCode: asynchronousCode, synchronousCode: synchronousCode)
  71. }
  72. private func printServiceClientMethodCallUnary() {
  73. println("\(access) protocol \(callName): ClientCallUnary {}")
  74. println()
  75. println("fileprivate final class \(callName)Base: ClientCallUnaryBase<\(methodInputName), \(methodOutputName)>, \(callName) {")
  76. indent()
  77. println("override class var method: String { return \(methodPath) }")
  78. outdent()
  79. println("}")
  80. println()
  81. }
  82. private func printServiceClientMethodCallUnaryTestStub() {
  83. println()
  84. println("class \(callName)TestStub: ClientCallUnaryTestStub, \(callName) {")
  85. indent()
  86. println("override class var method: String { return \(methodPath) }")
  87. outdent()
  88. println("}")
  89. }
  90. private func printServiceClientMethodCallServerStreaming() {
  91. println("\(access) protocol \(callName): ClientCallServerStreaming {")
  92. indent()
  93. printStreamReceiveMethods(receivedType: methodOutputName)
  94. outdent()
  95. println("}")
  96. println()
  97. printStreamReceiveExtension(extendedType: callName, receivedType: methodOutputName)
  98. println()
  99. println("fileprivate final class \(callName)Base: ClientCallServerStreamingBase<\(methodInputName), \(methodOutputName)>, \(callName) {")
  100. indent()
  101. println("override class var method: String { return \(methodPath) }")
  102. outdent()
  103. println("}")
  104. println()
  105. }
  106. private func printServiceClientMethodCallServerStreamingTestStub() {
  107. println()
  108. println("class \(callName)TestStub: ClientCallServerStreamingTestStub<\(methodOutputName)>, \(callName) {")
  109. indent()
  110. println("override class var method: String { return \(methodPath) }")
  111. outdent()
  112. println("}")
  113. }
  114. private func printServiceClientMethodCallClientStreaming() {
  115. println("\(options.visibility.sourceSnippet) protocol \(callName): ClientCallClientStreaming {")
  116. indent()
  117. printStreamSendMethods(sentType: methodInputName)
  118. println()
  119. println("/// Call this to close the connection and wait for a response. Blocking.")
  120. println("func closeAndReceive() throws -> \(methodOutputName)")
  121. println("/// Call this to close the connection and wait for a response. Nonblocking.")
  122. println("func closeAndReceive(completion: @escaping (ResultOrRPCError<\(methodOutputName)>) -> Void) throws")
  123. outdent()
  124. println("}")
  125. println()
  126. printStreamSendExtension(extendedType: callName, sentType: methodInputName)
  127. println()
  128. println("fileprivate final class \(callName)Base: ClientCallClientStreamingBase<\(methodInputName), \(methodOutputName)>, \(callName) {")
  129. indent()
  130. println("override class var method: String { return \(methodPath) }")
  131. outdent()
  132. println("}")
  133. println()
  134. }
  135. private func printServiceClientMethodCallClientStreamingTestStub() {
  136. println()
  137. println("/// Simple fake implementation of \(callName)")
  138. println("/// stores sent values for later verification and finall returns a previously-defined result.")
  139. println("class \(callName)TestStub: ClientCallClientStreamingTestStub<\(methodInputName), \(methodOutputName)>, \(callName) {")
  140. indent()
  141. println("override class var method: String { return \(methodPath) }")
  142. outdent()
  143. println("}")
  144. }
  145. private func printServiceClientMethodCallBidiStreaming() {
  146. println("\(access) protocol \(callName): ClientCallBidirectionalStreaming {")
  147. indent()
  148. printStreamReceiveMethods(receivedType: methodOutputName)
  149. println()
  150. printStreamSendMethods(sentType: methodInputName)
  151. println()
  152. println("/// Call this to close the sending connection. Blocking.")
  153. println("func closeSend() throws")
  154. println("/// Call this to close the sending connection. Nonblocking.")
  155. println("func closeSend(completion: (() -> Void)?) throws")
  156. outdent()
  157. println("}")
  158. println()
  159. printStreamReceiveExtension(extendedType: callName, receivedType: methodOutputName)
  160. println()
  161. printStreamSendExtension(extendedType: callName, sentType: methodInputName)
  162. println()
  163. println("fileprivate final class \(callName)Base: ClientCallBidirectionalStreamingBase<\(methodInputName), \(methodOutputName)>, \(callName) {")
  164. indent()
  165. println("override class var method: String { return \(methodPath) }")
  166. outdent()
  167. println("}")
  168. println()
  169. }
  170. private func printServiceClientMethodCallBidiStreamingTestStub() {
  171. println()
  172. println("class \(callName)TestStub: ClientCallBidirectionalStreamingTestStub<\(methodInputName), \(methodOutputName)>, \(callName) {")
  173. indent()
  174. println("override class var method: String { return \(methodPath) }")
  175. outdent()
  176. println("}")
  177. }
  178. private func printServiceClientProtocol(asynchronousCode: Bool,
  179. synchronousCode: Bool) {
  180. println("/// Instantiate \(serviceClassName)Client, then call methods of this protocol to make API calls.")
  181. println("\(options.visibility.sourceSnippet) protocol \(serviceClassName): ServiceClient {")
  182. indent()
  183. for method in service.methods {
  184. self.method = method
  185. switch streamingType(method) {
  186. case .unary:
  187. if synchronousCode {
  188. println("/// Synchronous. Unary.")
  189. println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata) throws -> \(methodOutputName)")
  190. }
  191. if asynchronousCode {
  192. println("/// Asynchronous. Unary.")
  193. println("@discardableResult")
  194. println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName)")
  195. }
  196. case .serverStreaming:
  197. println("/// Asynchronous. Server-streaming.")
  198. println("/// Send the initial message.")
  199. println("/// Use methods on the returned object to get streamed responses.")
  200. println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName)")
  201. case .clientStreaming:
  202. println("/// Asynchronous. Client-streaming.")
  203. println("/// Use methods on the returned object to stream messages and")
  204. println("/// to close the connection and wait for a final response.")
  205. println("func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName)")
  206. case .bidirectionalStreaming:
  207. println("/// Asynchronous. Bidirectional-streaming.")
  208. println("/// Use methods on the returned object to stream messages,")
  209. println("/// to wait for replies, and to close the connection.")
  210. println("func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName)")
  211. }
  212. println()
  213. }
  214. outdent()
  215. println("}")
  216. }
  217. private func printServiceClientProtocolExtension(asynchronousCode: Bool,
  218. synchronousCode: Bool) {
  219. println("\(options.visibility.sourceSnippet) extension \(serviceClassName) {")
  220. indent()
  221. for method in service.methods {
  222. self.method = method
  223. switch streamingType(method) {
  224. case .unary:
  225. if synchronousCode {
  226. println("/// Synchronous. Unary.")
  227. println("func \(methodFunctionName)(_ request: \(methodInputName)) throws -> \(methodOutputName) {")
  228. indent()
  229. println("return try self.\(methodFunctionName)(request, metadata: self.metadata)")
  230. outdent()
  231. println("}")
  232. }
  233. if asynchronousCode {
  234. println("/// Asynchronous. Unary.")
  235. println("@discardableResult")
  236. println("func \(methodFunctionName)(_ request: \(methodInputName), completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {")
  237. indent()
  238. println("return try self.\(methodFunctionName)(request, metadata: self.metadata, completion: completion)")
  239. outdent()
  240. println("}")
  241. }
  242. case .serverStreaming:
  243. println("/// Asynchronous. Server-streaming.")
  244. println("func \(methodFunctionName)(_ request: \(methodInputName), completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  245. indent()
  246. println("return try self.\(methodFunctionName)(request, metadata: self.metadata, completion: completion)")
  247. outdent()
  248. println("}")
  249. case .clientStreaming:
  250. println("/// Asynchronous. Client-streaming.")
  251. println("func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  252. indent()
  253. println("return try self.\(methodFunctionName)(metadata: self.metadata, completion: completion)")
  254. outdent()
  255. println("}")
  256. case .bidirectionalStreaming:
  257. println("/// Asynchronous. Bidirectional-streaming.")
  258. println("func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  259. indent()
  260. println("return try self.\(methodFunctionName)(metadata: self.metadata, completion: completion)")
  261. outdent()
  262. println("}")
  263. }
  264. println()
  265. }
  266. outdent()
  267. println("}")
  268. }
  269. private func printServiceClientImplementation(asynchronousCode: Bool,
  270. synchronousCode: Bool) {
  271. println("\(access) final class \(serviceClassName)Client: ServiceClientBase, \(serviceClassName) {")
  272. indent()
  273. for method in service.methods {
  274. self.method = method
  275. switch streamingType(method) {
  276. case .unary:
  277. if synchronousCode {
  278. println("/// Synchronous. Unary.")
  279. println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata) throws -> \(methodOutputName) {")
  280. indent()
  281. println("return try \(callName)Base(channel)")
  282. indent()
  283. println(".run(request: request, metadata: customMetadata)")
  284. outdent()
  285. outdent()
  286. println("}")
  287. }
  288. if asynchronousCode {
  289. println("/// Asynchronous. Unary.")
  290. println("@discardableResult")
  291. println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {")
  292. indent()
  293. println("return try \(callName)Base(channel)")
  294. indent()
  295. println(".start(request: request, metadata: customMetadata, completion: completion)")
  296. outdent()
  297. outdent()
  298. println("}")
  299. }
  300. case .serverStreaming:
  301. println("/// Asynchronous. Server-streaming.")
  302. println("/// Send the initial message.")
  303. println("/// Use methods on the returned object to get streamed responses.")
  304. println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  305. indent()
  306. println("return try \(callName)Base(channel)")
  307. indent()
  308. println(".start(request: request, metadata: customMetadata, completion: completion)")
  309. outdent()
  310. outdent()
  311. println("}")
  312. case .clientStreaming:
  313. println("/// Asynchronous. Client-streaming.")
  314. println("/// Use methods on the returned object to stream messages and")
  315. println("/// to close the connection and wait for a final response.")
  316. println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  317. indent()
  318. println("return try \(callName)Base(channel)")
  319. indent()
  320. println(".start(metadata: customMetadata, completion: completion)")
  321. outdent()
  322. outdent()
  323. println("}")
  324. case .bidirectionalStreaming:
  325. println("/// Asynchronous. Bidirectional-streaming.")
  326. println("/// Use methods on the returned object to stream messages,")
  327. println("/// to wait for replies, and to close the connection.")
  328. println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  329. indent()
  330. println("return try \(callName)Base(channel)")
  331. indent()
  332. println(".start(metadata: customMetadata, completion: completion)")
  333. outdent()
  334. outdent()
  335. println("}")
  336. }
  337. println()
  338. }
  339. outdent()
  340. println("}")
  341. }
  342. private func printServiceClientTestStubs(asynchronousCode: Bool,
  343. synchronousCode: Bool) {
  344. println("class \(serviceClassName)TestStub: ServiceClientTestStubBase, \(serviceClassName) {")
  345. indent()
  346. for method in service.methods {
  347. self.method = method
  348. switch streamingType(method) {
  349. case .unary:
  350. println("var \(methodFunctionName)Requests: [\(methodInputName)] = []")
  351. println("var \(methodFunctionName)Responses: [\(methodOutputName)] = []")
  352. if synchronousCode {
  353. println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata) throws -> \(methodOutputName) {")
  354. indent()
  355. println("\(methodFunctionName)Requests.append(request)")
  356. println("defer { \(methodFunctionName)Responses.removeFirst() }")
  357. println("return \(methodFunctionName)Responses.first!")
  358. outdent()
  359. println("}")
  360. }
  361. if asynchronousCode {
  362. println("@discardableResult")
  363. println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {")
  364. indent()
  365. println("let response = try self.\(methodFunctionName)(request)")
  366. println("let callResult = CallResult(success: true, statusCode: .ok, statusMessage: \"OK\", resultData: nil, initialMetadata: nil, trailingMetadata: nil)")
  367. println("completion(response, callResult)")
  368. println("return \(callName)TestStub()")
  369. outdent()
  370. println("}")
  371. }
  372. case .serverStreaming:
  373. println("var \(methodFunctionName)Requests: [\(methodInputName)] = []")
  374. println("var \(methodFunctionName)Calls: [\(callName)] = []")
  375. println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  376. indent()
  377. println("\(methodFunctionName)Requests.append(request)")
  378. println("defer { \(methodFunctionName)Calls.removeFirst() }")
  379. println("return \(methodFunctionName)Calls.first!")
  380. outdent()
  381. println("}")
  382. case .clientStreaming:
  383. println("var \(methodFunctionName)Calls: [\(callName)] = []")
  384. println("func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  385. indent()
  386. println("defer { \(methodFunctionName)Calls.removeFirst() }")
  387. println("return \(methodFunctionName)Calls.first!")
  388. outdent()
  389. println("}")
  390. case .bidirectionalStreaming:
  391. println("var \(methodFunctionName)Calls: [\(callName)] = []")
  392. println("func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {")
  393. indent()
  394. println("defer { \(methodFunctionName)Calls.removeFirst() }")
  395. println("return \(methodFunctionName)Calls.first!")
  396. outdent()
  397. println("}")
  398. }
  399. println()
  400. }
  401. outdent()
  402. println("}")
  403. }
  404. private func printNIOGRPCClient() {
  405. println()
  406. printNIOServiceClientProtocol()
  407. println()
  408. printNIOServiceClientImplementation()
  409. }
  410. private func printNIOServiceClientProtocol() {
  411. println("/// Usage: instantiate \(serviceClassName)Client, then call methods of this protocol to make API calls.")
  412. println("\(options.visibility.sourceSnippet) protocol \(serviceClassName) {")
  413. indent()
  414. for method in service.methods {
  415. self.method = method
  416. switch streamingType(method) {
  417. case .unary:
  418. println("func \(methodFunctionName)(_ request: \(methodInputName), callOptions: CallOptions?) -> UnaryClientCall<\(methodInputName), \(methodOutputName)>")
  419. case .serverStreaming:
  420. println("func \(methodFunctionName)(_ request: \(methodInputName), callOptions: CallOptions?, handler: @escaping (\(methodOutputName)) -> Void) -> ServerStreamingClientCall<\(methodInputName), \(methodOutputName)>")
  421. case .clientStreaming:
  422. println("func \(methodFunctionName)(callOptions: CallOptions?) -> ClientStreamingClientCall<\(methodInputName), \(methodOutputName)>")
  423. case .bidirectionalStreaming:
  424. println("func \(methodFunctionName)(callOptions: CallOptions?, handler: @escaping (\(methodOutputName)) -> Void) -> BidirectionalStreamingClientCall<\(methodInputName), \(methodOutputName)>")
  425. }
  426. }
  427. outdent()
  428. println("}")
  429. }
  430. private func printNIOServiceClientImplementation() {
  431. println("\(access) final class \(serviceClassName)Client: GRPCServiceClient, \(serviceClassName) {")
  432. indent()
  433. println("\(access) let client: GRPCClient")
  434. println("\(access) let service = \"\(servicePath)\"")
  435. println("\(access) var defaultCallOptions: CallOptions")
  436. println()
  437. println("/// Creates a client for the \(servicePath) service.")
  438. println("///")
  439. printParameters()
  440. println("/// - client: `GRPCClient` with a connection to the service host.")
  441. println("/// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. Defaults to `client.defaultCallOptions`.")
  442. println("\(access) init(client: GRPCClient, defaultCallOptions: CallOptions? = nil) {")
  443. indent()
  444. println("self.client = client")
  445. println("self.defaultCallOptions = defaultCallOptions ?? client.defaultCallOptions")
  446. outdent()
  447. println("}")
  448. println()
  449. for method in service.methods {
  450. self.method = method
  451. switch streamingType(method) {
  452. case .unary:
  453. println("/// Asynchronous unary call to \(method.name).")
  454. println("///")
  455. printParameters()
  456. printRequestParameter()
  457. printCallOptionsParameter()
  458. println("/// - Returns: A `UnaryClientCall` with futures for the metadata, status and response.")
  459. println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), callOptions: CallOptions? = nil) -> UnaryClientCall<\(methodInputName), \(methodOutputName)> {")
  460. indent()
  461. println("return UnaryClientCall(client: client, path: path(forMethod: \"\(method.name)\"), request: request, callOptions: callOptions ?? self.defaultCallOptions)")
  462. outdent()
  463. println("}")
  464. case .serverStreaming:
  465. println("/// Asynchronous server-streaming call to \(method.name).")
  466. println("///")
  467. printParameters()
  468. printRequestParameter()
  469. printCallOptionsParameter()
  470. printHandlerParameter()
  471. println("/// - Returns: A `ServerStreamingClientCall` with futures for the metadata and status.")
  472. println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), callOptions: CallOptions? = nil, handler: @escaping (\(methodOutputName)) -> Void) -> ServerStreamingClientCall<\(methodInputName), \(methodOutputName)> {")
  473. indent()
  474. println("return ServerStreamingClientCall(client: client, path: path(forMethod: \"\(method.name)\"), request: request, callOptions: callOptions ?? self.defaultCallOptions, handler: handler)")
  475. outdent()
  476. println("}")
  477. case .clientStreaming:
  478. println("/// Asynchronous client-streaming call to \(method.name).")
  479. println("///")
  480. printClientStreamingDetails()
  481. println("///")
  482. printParameters()
  483. printCallOptionsParameter()
  484. println("/// - Returns: A `ClientStreamingClientCall` with futures for the metadata, status and response.")
  485. println("\(access) func \(methodFunctionName)(callOptions: CallOptions? = nil) -> ClientStreamingClientCall<\(methodInputName), \(methodOutputName)> {")
  486. indent()
  487. println("return ClientStreamingClientCall(client: client, path: path(forMethod: \"\(method.name)\"), callOptions: callOptions ?? self.defaultCallOptions)")
  488. outdent()
  489. println("}")
  490. case .bidirectionalStreaming:
  491. println("/// Asynchronous bidirectional-streaming call to \(method.name).")
  492. println("///")
  493. printClientStreamingDetails()
  494. println("///")
  495. printParameters()
  496. printCallOptionsParameter()
  497. printHandlerParameter()
  498. println("/// - Returns: A `ClientStreamingClientCall` with futures for the metadata and status.")
  499. println("\(access) func \(methodFunctionName)(callOptions: CallOptions? = nil, handler: @escaping (\(methodOutputName)) -> Void) -> BidirectionalStreamingClientCall<\(methodInputName), \(methodOutputName)> {")
  500. indent()
  501. println("return BidirectionalStreamingClientCall(client: client, path: path(forMethod: \"\(method.name)\"), callOptions: callOptions ?? self.defaultCallOptions, handler: handler)")
  502. outdent()
  503. println("}")
  504. }
  505. println()
  506. }
  507. outdent()
  508. println("}")
  509. }
  510. private func printClientStreamingDetails() {
  511. println("/// Callers should use the `send` method on the returned object to send messages")
  512. println("/// to the server. The caller should send an `.end` after the final message has been sent.")
  513. }
  514. private func printParameters() {
  515. println("/// - Parameters:")
  516. }
  517. private func printRequestParameter() {
  518. println("/// - request: Request to send to \(method.name).")
  519. }
  520. private func printCallOptionsParameter() {
  521. println("/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.")
  522. }
  523. private func printHandlerParameter() {
  524. println("/// - handler: A closure called when each response is received from the server.")
  525. }
  526. }