echo.grpc.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: echo.proto
  6. //
  7. //
  8. // Copyright 2018, gRPC Authors All rights reserved.
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. //
  22. import GRPC
  23. import NIO
  24. import NIOConcurrencyHelpers
  25. import SwiftProtobuf
  26. /// Usage: instantiate `Echo_EchoClient`, then call methods of this protocol to make API calls.
  27. public protocol Echo_EchoClientProtocol: GRPCClient {
  28. var serviceName: String { get }
  29. var interceptors: Echo_EchoClientInterceptorFactoryProtocol? { get }
  30. func get(
  31. _ request: Echo_EchoRequest,
  32. callOptions: CallOptions?
  33. ) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse>
  34. func expand(
  35. _ request: Echo_EchoRequest,
  36. callOptions: CallOptions?,
  37. handler: @escaping (Echo_EchoResponse) -> Void
  38. ) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  39. func collect(
  40. callOptions: CallOptions?
  41. ) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  42. func update(
  43. callOptions: CallOptions?,
  44. handler: @escaping (Echo_EchoResponse) -> Void
  45. ) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  46. }
  47. extension Echo_EchoClientProtocol {
  48. public var serviceName: String {
  49. return "echo.Echo"
  50. }
  51. /// Immediately returns an echo of a request.
  52. ///
  53. /// - Parameters:
  54. /// - request: Request to send to Get.
  55. /// - callOptions: Call options.
  56. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  57. public func get(
  58. _ request: Echo_EchoRequest,
  59. callOptions: CallOptions? = nil
  60. ) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
  61. return self.makeUnaryCall(
  62. path: Echo_EchoClientMetadata.Methods.get.path,
  63. request: request,
  64. callOptions: callOptions ?? self.defaultCallOptions,
  65. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  66. )
  67. }
  68. /// Splits a request into words and returns each word in a stream of messages.
  69. ///
  70. /// - Parameters:
  71. /// - request: Request to send to Expand.
  72. /// - callOptions: Call options.
  73. /// - handler: A closure called when each response is received from the server.
  74. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
  75. public func expand(
  76. _ request: Echo_EchoRequest,
  77. callOptions: CallOptions? = nil,
  78. handler: @escaping (Echo_EchoResponse) -> Void
  79. ) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  80. return self.makeServerStreamingCall(
  81. path: Echo_EchoClientMetadata.Methods.expand.path,
  82. request: request,
  83. callOptions: callOptions ?? self.defaultCallOptions,
  84. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  85. handler: handler
  86. )
  87. }
  88. /// Collects a stream of messages and returns them concatenated when the caller closes.
  89. ///
  90. /// Callers should use the `send` method on the returned object to send messages
  91. /// to the server. The caller should send an `.end` after the final message has been sent.
  92. ///
  93. /// - Parameters:
  94. /// - callOptions: Call options.
  95. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
  96. public func collect(
  97. callOptions: CallOptions? = nil
  98. ) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  99. return self.makeClientStreamingCall(
  100. path: Echo_EchoClientMetadata.Methods.collect.path,
  101. callOptions: callOptions ?? self.defaultCallOptions,
  102. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  103. )
  104. }
  105. /// Streams back messages as they are received in an input stream.
  106. ///
  107. /// Callers should use the `send` method on the returned object to send messages
  108. /// to the server. The caller should send an `.end` after the final message has been sent.
  109. ///
  110. /// - Parameters:
  111. /// - callOptions: Call options.
  112. /// - handler: A closure called when each response is received from the server.
  113. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  114. public func update(
  115. callOptions: CallOptions? = nil,
  116. handler: @escaping (Echo_EchoResponse) -> Void
  117. ) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  118. return self.makeBidirectionalStreamingCall(
  119. path: Echo_EchoClientMetadata.Methods.update.path,
  120. callOptions: callOptions ?? self.defaultCallOptions,
  121. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  122. handler: handler
  123. )
  124. }
  125. }
  126. #if compiler(>=5.6)
  127. @available(*, deprecated)
  128. extension Echo_EchoClient: @unchecked Sendable {}
  129. #endif // compiler(>=5.6)
  130. @available(*, deprecated, renamed: "Echo_EchoNIOClient")
  131. public final class Echo_EchoClient: Echo_EchoClientProtocol {
  132. private let lock = Lock()
  133. private var _defaultCallOptions: CallOptions
  134. private var _interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  135. public let channel: GRPCChannel
  136. public var defaultCallOptions: CallOptions {
  137. get { self.lock.withLock { return self._defaultCallOptions } }
  138. set { self.lock.withLockVoid { self._defaultCallOptions = newValue } }
  139. }
  140. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol? {
  141. get { self.lock.withLock { return self._interceptors } }
  142. set { self.lock.withLockVoid { self._interceptors = newValue } }
  143. }
  144. /// Creates a client for the echo.Echo service.
  145. ///
  146. /// - Parameters:
  147. /// - channel: `GRPCChannel` to the service host.
  148. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  149. /// - interceptors: A factory providing interceptors for each RPC.
  150. public init(
  151. channel: GRPCChannel,
  152. defaultCallOptions: CallOptions = CallOptions(),
  153. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  154. ) {
  155. self.channel = channel
  156. self._defaultCallOptions = defaultCallOptions
  157. self._interceptors = interceptors
  158. }
  159. }
  160. public struct Echo_EchoNIOClient: Echo_EchoClientProtocol {
  161. public var channel: GRPCChannel
  162. public var defaultCallOptions: CallOptions
  163. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  164. /// Creates a client for the echo.Echo service.
  165. ///
  166. /// - Parameters:
  167. /// - channel: `GRPCChannel` to the service host.
  168. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  169. /// - interceptors: A factory providing interceptors for each RPC.
  170. public init(
  171. channel: GRPCChannel,
  172. defaultCallOptions: CallOptions = CallOptions(),
  173. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  174. ) {
  175. self.channel = channel
  176. self.defaultCallOptions = defaultCallOptions
  177. self.interceptors = interceptors
  178. }
  179. }
  180. #if compiler(>=5.6)
  181. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  182. public protocol Echo_EchoAsyncClientProtocol: GRPCClient {
  183. static var serviceDescriptor: GRPCServiceDescriptor { get }
  184. var interceptors: Echo_EchoClientInterceptorFactoryProtocol? { get }
  185. func makeGetCall(
  186. _ request: Echo_EchoRequest,
  187. callOptions: CallOptions?
  188. ) -> GRPCAsyncUnaryCall<Echo_EchoRequest, Echo_EchoResponse>
  189. func makeExpandCall(
  190. _ request: Echo_EchoRequest,
  191. callOptions: CallOptions?
  192. ) -> GRPCAsyncServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  193. func makeCollectCall(
  194. callOptions: CallOptions?
  195. ) -> GRPCAsyncClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  196. func makeUpdateCall(
  197. callOptions: CallOptions?
  198. ) -> GRPCAsyncBidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  199. }
  200. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  201. extension Echo_EchoAsyncClientProtocol {
  202. public static var serviceDescriptor: GRPCServiceDescriptor {
  203. return Echo_EchoClientMetadata.serviceDescriptor
  204. }
  205. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol? {
  206. return nil
  207. }
  208. public func makeGetCall(
  209. _ request: Echo_EchoRequest,
  210. callOptions: CallOptions? = nil
  211. ) -> GRPCAsyncUnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
  212. return self.makeAsyncUnaryCall(
  213. path: Echo_EchoClientMetadata.Methods.get.path,
  214. request: request,
  215. callOptions: callOptions ?? self.defaultCallOptions,
  216. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  217. )
  218. }
  219. public func makeExpandCall(
  220. _ request: Echo_EchoRequest,
  221. callOptions: CallOptions? = nil
  222. ) -> GRPCAsyncServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  223. return self.makeAsyncServerStreamingCall(
  224. path: Echo_EchoClientMetadata.Methods.expand.path,
  225. request: request,
  226. callOptions: callOptions ?? self.defaultCallOptions,
  227. interceptors: self.interceptors?.makeExpandInterceptors() ?? []
  228. )
  229. }
  230. public func makeCollectCall(
  231. callOptions: CallOptions? = nil
  232. ) -> GRPCAsyncClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  233. return self.makeAsyncClientStreamingCall(
  234. path: Echo_EchoClientMetadata.Methods.collect.path,
  235. callOptions: callOptions ?? self.defaultCallOptions,
  236. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  237. )
  238. }
  239. public func makeUpdateCall(
  240. callOptions: CallOptions? = nil
  241. ) -> GRPCAsyncBidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  242. return self.makeAsyncBidirectionalStreamingCall(
  243. path: Echo_EchoClientMetadata.Methods.update.path,
  244. callOptions: callOptions ?? self.defaultCallOptions,
  245. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  246. )
  247. }
  248. }
  249. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  250. extension Echo_EchoAsyncClientProtocol {
  251. public func get(
  252. _ request: Echo_EchoRequest,
  253. callOptions: CallOptions? = nil
  254. ) async throws -> Echo_EchoResponse {
  255. return try await self.performAsyncUnaryCall(
  256. path: Echo_EchoClientMetadata.Methods.get.path,
  257. request: request,
  258. callOptions: callOptions ?? self.defaultCallOptions,
  259. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  260. )
  261. }
  262. public func expand(
  263. _ request: Echo_EchoRequest,
  264. callOptions: CallOptions? = nil
  265. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> {
  266. return self.performAsyncServerStreamingCall(
  267. path: Echo_EchoClientMetadata.Methods.expand.path,
  268. request: request,
  269. callOptions: callOptions ?? self.defaultCallOptions,
  270. interceptors: self.interceptors?.makeExpandInterceptors() ?? []
  271. )
  272. }
  273. public func collect<RequestStream>(
  274. _ requests: RequestStream,
  275. callOptions: CallOptions? = nil
  276. ) async throws -> Echo_EchoResponse where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
  277. return try await self.performAsyncClientStreamingCall(
  278. path: Echo_EchoClientMetadata.Methods.collect.path,
  279. requests: requests,
  280. callOptions: callOptions ?? self.defaultCallOptions,
  281. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  282. )
  283. }
  284. public func collect<RequestStream>(
  285. _ requests: RequestStream,
  286. callOptions: CallOptions? = nil
  287. ) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Echo_EchoRequest {
  288. return try await self.performAsyncClientStreamingCall(
  289. path: Echo_EchoClientMetadata.Methods.collect.path,
  290. requests: requests,
  291. callOptions: callOptions ?? self.defaultCallOptions,
  292. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  293. )
  294. }
  295. public func update<RequestStream>(
  296. _ requests: RequestStream,
  297. callOptions: CallOptions? = nil
  298. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
  299. return self.performAsyncBidirectionalStreamingCall(
  300. path: Echo_EchoClientMetadata.Methods.update.path,
  301. requests: requests,
  302. callOptions: callOptions ?? self.defaultCallOptions,
  303. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  304. )
  305. }
  306. public func update<RequestStream>(
  307. _ requests: RequestStream,
  308. callOptions: CallOptions? = nil
  309. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Echo_EchoRequest {
  310. return self.performAsyncBidirectionalStreamingCall(
  311. path: Echo_EchoClientMetadata.Methods.update.path,
  312. requests: requests,
  313. callOptions: callOptions ?? self.defaultCallOptions,
  314. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  315. )
  316. }
  317. }
  318. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  319. public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
  320. public var channel: GRPCChannel
  321. public var defaultCallOptions: CallOptions
  322. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  323. public init(
  324. channel: GRPCChannel,
  325. defaultCallOptions: CallOptions = CallOptions(),
  326. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  327. ) {
  328. self.channel = channel
  329. self.defaultCallOptions = defaultCallOptions
  330. self.interceptors = interceptors
  331. }
  332. }
  333. #endif // compiler(>=5.6)
  334. public protocol Echo_EchoClientInterceptorFactoryProtocol: GRPCSendable {
  335. /// - Returns: Interceptors to use when invoking 'get'.
  336. func makeGetInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  337. /// - Returns: Interceptors to use when invoking 'expand'.
  338. func makeExpandInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  339. /// - Returns: Interceptors to use when invoking 'collect'.
  340. func makeCollectInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  341. /// - Returns: Interceptors to use when invoking 'update'.
  342. func makeUpdateInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  343. }
  344. public enum Echo_EchoClientMetadata {
  345. public static let serviceDescriptor = GRPCServiceDescriptor(
  346. name: "Echo",
  347. fullName: "echo.Echo",
  348. methods: [
  349. Echo_EchoClientMetadata.Methods.get,
  350. Echo_EchoClientMetadata.Methods.expand,
  351. Echo_EchoClientMetadata.Methods.collect,
  352. Echo_EchoClientMetadata.Methods.update,
  353. ]
  354. )
  355. public enum Methods {
  356. public static let get = GRPCMethodDescriptor(
  357. name: "Get",
  358. path: "/echo.Echo/Get",
  359. type: GRPCCallType.unary
  360. )
  361. public static let expand = GRPCMethodDescriptor(
  362. name: "Expand",
  363. path: "/echo.Echo/Expand",
  364. type: GRPCCallType.serverStreaming
  365. )
  366. public static let collect = GRPCMethodDescriptor(
  367. name: "Collect",
  368. path: "/echo.Echo/Collect",
  369. type: GRPCCallType.clientStreaming
  370. )
  371. public static let update = GRPCMethodDescriptor(
  372. name: "Update",
  373. path: "/echo.Echo/Update",
  374. type: GRPCCallType.bidirectionalStreaming
  375. )
  376. }
  377. }
  378. #if compiler(>=5.6)
  379. @available(swift, deprecated: 5.6)
  380. extension Echo_EchoTestClient: @unchecked Sendable {}
  381. #endif // compiler(>=5.6)
  382. @available(swift, deprecated: 5.6, message: "Test clients are not Sendable but the 'GRPCClient' API requires clients to be Sendable. Using a localhost client and server is the recommended alternative.")
  383. public final class Echo_EchoTestClient: Echo_EchoClientProtocol {
  384. private let fakeChannel: FakeChannel
  385. public var defaultCallOptions: CallOptions
  386. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  387. public var channel: GRPCChannel {
  388. return self.fakeChannel
  389. }
  390. public init(
  391. fakeChannel: FakeChannel = FakeChannel(),
  392. defaultCallOptions callOptions: CallOptions = CallOptions(),
  393. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  394. ) {
  395. self.fakeChannel = fakeChannel
  396. self.defaultCallOptions = callOptions
  397. self.interceptors = interceptors
  398. }
  399. /// Make a unary response for the Get RPC. This must be called
  400. /// before calling 'get'. See also 'FakeUnaryResponse'.
  401. ///
  402. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  403. public func makeGetResponseStream(
  404. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  405. ) -> FakeUnaryResponse<Echo_EchoRequest, Echo_EchoResponse> {
  406. return self.fakeChannel.makeFakeUnaryResponse(path: Echo_EchoClientMetadata.Methods.get.path, requestHandler: requestHandler)
  407. }
  408. public func enqueueGetResponse(
  409. _ response: Echo_EchoResponse,
  410. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  411. ) {
  412. let stream = self.makeGetResponseStream(requestHandler)
  413. // This is the only operation on the stream; try! is fine.
  414. try! stream.sendMessage(response)
  415. }
  416. /// Returns true if there are response streams enqueued for 'Get'
  417. public var hasGetResponsesRemaining: Bool {
  418. return self.fakeChannel.hasFakeResponseEnqueued(forPath: Echo_EchoClientMetadata.Methods.get.path)
  419. }
  420. /// Make a streaming response for the Expand RPC. This must be called
  421. /// before calling 'expand'. See also 'FakeStreamingResponse'.
  422. ///
  423. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  424. public func makeExpandResponseStream(
  425. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  426. ) -> FakeStreamingResponse<Echo_EchoRequest, Echo_EchoResponse> {
  427. return self.fakeChannel.makeFakeStreamingResponse(path: Echo_EchoClientMetadata.Methods.expand.path, requestHandler: requestHandler)
  428. }
  429. public func enqueueExpandResponses(
  430. _ responses: [Echo_EchoResponse],
  431. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  432. ) {
  433. let stream = self.makeExpandResponseStream(requestHandler)
  434. // These are the only operation on the stream; try! is fine.
  435. responses.forEach { try! stream.sendMessage($0) }
  436. try! stream.sendEnd()
  437. }
  438. /// Returns true if there are response streams enqueued for 'Expand'
  439. public var hasExpandResponsesRemaining: Bool {
  440. return self.fakeChannel.hasFakeResponseEnqueued(forPath: Echo_EchoClientMetadata.Methods.expand.path)
  441. }
  442. /// Make a unary response for the Collect RPC. This must be called
  443. /// before calling 'collect'. See also 'FakeUnaryResponse'.
  444. ///
  445. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  446. public func makeCollectResponseStream(
  447. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  448. ) -> FakeUnaryResponse<Echo_EchoRequest, Echo_EchoResponse> {
  449. return self.fakeChannel.makeFakeUnaryResponse(path: Echo_EchoClientMetadata.Methods.collect.path, requestHandler: requestHandler)
  450. }
  451. public func enqueueCollectResponse(
  452. _ response: Echo_EchoResponse,
  453. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  454. ) {
  455. let stream = self.makeCollectResponseStream(requestHandler)
  456. // This is the only operation on the stream; try! is fine.
  457. try! stream.sendMessage(response)
  458. }
  459. /// Returns true if there are response streams enqueued for 'Collect'
  460. public var hasCollectResponsesRemaining: Bool {
  461. return self.fakeChannel.hasFakeResponseEnqueued(forPath: Echo_EchoClientMetadata.Methods.collect.path)
  462. }
  463. /// Make a streaming response for the Update RPC. This must be called
  464. /// before calling 'update'. See also 'FakeStreamingResponse'.
  465. ///
  466. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  467. public func makeUpdateResponseStream(
  468. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  469. ) -> FakeStreamingResponse<Echo_EchoRequest, Echo_EchoResponse> {
  470. return self.fakeChannel.makeFakeStreamingResponse(path: Echo_EchoClientMetadata.Methods.update.path, requestHandler: requestHandler)
  471. }
  472. public func enqueueUpdateResponses(
  473. _ responses: [Echo_EchoResponse],
  474. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  475. ) {
  476. let stream = self.makeUpdateResponseStream(requestHandler)
  477. // These are the only operation on the stream; try! is fine.
  478. responses.forEach { try! stream.sendMessage($0) }
  479. try! stream.sendEnd()
  480. }
  481. /// Returns true if there are response streams enqueued for 'Update'
  482. public var hasUpdateResponsesRemaining: Bool {
  483. return self.fakeChannel.hasFakeResponseEnqueued(forPath: Echo_EchoClientMetadata.Methods.update.path)
  484. }
  485. }
  486. /// To build a server, implement a class that conforms to this protocol.
  487. public protocol Echo_EchoProvider: CallHandlerProvider {
  488. var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
  489. /// Immediately returns an echo of a request.
  490. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  491. /// Splits a request into words and returns each word in a stream of messages.
  492. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  493. /// Collects a stream of messages and returns them concatenated when the caller closes.
  494. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  495. /// Streams back messages as they are received in an input stream.
  496. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  497. }
  498. extension Echo_EchoProvider {
  499. public var serviceName: Substring {
  500. return Echo_EchoServerMetadata.serviceDescriptor.fullName[...]
  501. }
  502. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  503. /// Returns nil for methods not handled by this service.
  504. public func handle(
  505. method name: Substring,
  506. context: CallHandlerContext
  507. ) -> GRPCServerHandlerProtocol? {
  508. switch name {
  509. case "Get":
  510. return UnaryServerHandler(
  511. context: context,
  512. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  513. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  514. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  515. userFunction: self.get(request:context:)
  516. )
  517. case "Expand":
  518. return ServerStreamingServerHandler(
  519. context: context,
  520. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  521. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  522. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  523. userFunction: self.expand(request:context:)
  524. )
  525. case "Collect":
  526. return ClientStreamingServerHandler(
  527. context: context,
  528. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  529. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  530. interceptors: self.interceptors?.makeCollectInterceptors() ?? [],
  531. observerFactory: self.collect(context:)
  532. )
  533. case "Update":
  534. return BidirectionalStreamingServerHandler(
  535. context: context,
  536. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  537. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  538. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  539. observerFactory: self.update(context:)
  540. )
  541. default:
  542. return nil
  543. }
  544. }
  545. }
  546. #if compiler(>=5.6)
  547. /// To implement a server, implement an object which conforms to this protocol.
  548. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  549. public protocol Echo_EchoAsyncProvider: CallHandlerProvider {
  550. static var serviceDescriptor: GRPCServiceDescriptor { get }
  551. var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
  552. /// Immediately returns an echo of a request.
  553. @Sendable func get(
  554. request: Echo_EchoRequest,
  555. context: GRPCAsyncServerCallContext
  556. ) async throws -> Echo_EchoResponse
  557. /// Splits a request into words and returns each word in a stream of messages.
  558. @Sendable func expand(
  559. request: Echo_EchoRequest,
  560. responseStream: GRPCAsyncResponseStreamWriter<Echo_EchoResponse>,
  561. context: GRPCAsyncServerCallContext
  562. ) async throws
  563. /// Collects a stream of messages and returns them concatenated when the caller closes.
  564. @Sendable func collect(
  565. requestStream: GRPCAsyncRequestStream<Echo_EchoRequest>,
  566. context: GRPCAsyncServerCallContext
  567. ) async throws -> Echo_EchoResponse
  568. /// Streams back messages as they are received in an input stream.
  569. @Sendable func update(
  570. requestStream: GRPCAsyncRequestStream<Echo_EchoRequest>,
  571. responseStream: GRPCAsyncResponseStreamWriter<Echo_EchoResponse>,
  572. context: GRPCAsyncServerCallContext
  573. ) async throws
  574. }
  575. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  576. extension Echo_EchoAsyncProvider {
  577. public static var serviceDescriptor: GRPCServiceDescriptor {
  578. return Echo_EchoServerMetadata.serviceDescriptor
  579. }
  580. public var serviceName: Substring {
  581. return Echo_EchoServerMetadata.serviceDescriptor.fullName[...]
  582. }
  583. public var interceptors: Echo_EchoServerInterceptorFactoryProtocol? {
  584. return nil
  585. }
  586. public func handle(
  587. method name: Substring,
  588. context: CallHandlerContext
  589. ) -> GRPCServerHandlerProtocol? {
  590. switch name {
  591. case "Get":
  592. return GRPCAsyncServerHandler(
  593. context: context,
  594. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  595. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  596. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  597. wrapping: self.get(request:context:)
  598. )
  599. case "Expand":
  600. return GRPCAsyncServerHandler(
  601. context: context,
  602. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  603. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  604. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  605. wrapping: self.expand(request:responseStream:context:)
  606. )
  607. case "Collect":
  608. return GRPCAsyncServerHandler(
  609. context: context,
  610. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  611. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  612. interceptors: self.interceptors?.makeCollectInterceptors() ?? [],
  613. wrapping: self.collect(requestStream:context:)
  614. )
  615. case "Update":
  616. return GRPCAsyncServerHandler(
  617. context: context,
  618. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  619. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  620. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  621. wrapping: self.update(requestStream:responseStream:context:)
  622. )
  623. default:
  624. return nil
  625. }
  626. }
  627. }
  628. #endif // compiler(>=5.6)
  629. public protocol Echo_EchoServerInterceptorFactoryProtocol {
  630. /// - Returns: Interceptors to use when handling 'get'.
  631. /// Defaults to calling `self.makeInterceptors()`.
  632. func makeGetInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  633. /// - Returns: Interceptors to use when handling 'expand'.
  634. /// Defaults to calling `self.makeInterceptors()`.
  635. func makeExpandInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  636. /// - Returns: Interceptors to use when handling 'collect'.
  637. /// Defaults to calling `self.makeInterceptors()`.
  638. func makeCollectInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  639. /// - Returns: Interceptors to use when handling 'update'.
  640. /// Defaults to calling `self.makeInterceptors()`.
  641. func makeUpdateInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  642. }
  643. public enum Echo_EchoServerMetadata {
  644. public static let serviceDescriptor = GRPCServiceDescriptor(
  645. name: "Echo",
  646. fullName: "echo.Echo",
  647. methods: [
  648. Echo_EchoServerMetadata.Methods.get,
  649. Echo_EchoServerMetadata.Methods.expand,
  650. Echo_EchoServerMetadata.Methods.collect,
  651. Echo_EchoServerMetadata.Methods.update,
  652. ]
  653. )
  654. public enum Methods {
  655. public static let get = GRPCMethodDescriptor(
  656. name: "Get",
  657. path: "/echo.Echo/Get",
  658. type: GRPCCallType.unary
  659. )
  660. public static let expand = GRPCMethodDescriptor(
  661. name: "Expand",
  662. path: "/echo.Echo/Expand",
  663. type: GRPCCallType.serverStreaming
  664. )
  665. public static let collect = GRPCMethodDescriptor(
  666. name: "Collect",
  667. path: "/echo.Echo/Collect",
  668. type: GRPCCallType.clientStreaming
  669. )
  670. public static let update = GRPCMethodDescriptor(
  671. name: "Update",
  672. path: "/echo.Echo/Update",
  673. type: GRPCCallType.bidirectionalStreaming
  674. )
  675. }
  676. }