echo.grpc.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. @available(*, deprecated)
  127. extension Echo_EchoClient: @unchecked Sendable {}
  128. @available(*, deprecated, renamed: "Echo_EchoNIOClient")
  129. public final class Echo_EchoClient: Echo_EchoClientProtocol {
  130. private let lock = Lock()
  131. private var _defaultCallOptions: CallOptions
  132. private var _interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  133. public let channel: GRPCChannel
  134. public var defaultCallOptions: CallOptions {
  135. get { self.lock.withLock { return self._defaultCallOptions } }
  136. set { self.lock.withLockVoid { self._defaultCallOptions = newValue } }
  137. }
  138. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol? {
  139. get { self.lock.withLock { return self._interceptors } }
  140. set { self.lock.withLockVoid { self._interceptors = newValue } }
  141. }
  142. /// Creates a client for the echo.Echo service.
  143. ///
  144. /// - Parameters:
  145. /// - channel: `GRPCChannel` to the service host.
  146. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  147. /// - interceptors: A factory providing interceptors for each RPC.
  148. public init(
  149. channel: GRPCChannel,
  150. defaultCallOptions: CallOptions = CallOptions(),
  151. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  152. ) {
  153. self.channel = channel
  154. self._defaultCallOptions = defaultCallOptions
  155. self._interceptors = interceptors
  156. }
  157. }
  158. public struct Echo_EchoNIOClient: Echo_EchoClientProtocol {
  159. public var channel: GRPCChannel
  160. public var defaultCallOptions: CallOptions
  161. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  162. /// Creates a client for the echo.Echo service.
  163. ///
  164. /// - Parameters:
  165. /// - channel: `GRPCChannel` to the service host.
  166. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  167. /// - interceptors: A factory providing interceptors for each RPC.
  168. public init(
  169. channel: GRPCChannel,
  170. defaultCallOptions: CallOptions = CallOptions(),
  171. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  172. ) {
  173. self.channel = channel
  174. self.defaultCallOptions = defaultCallOptions
  175. self.interceptors = interceptors
  176. }
  177. }
  178. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  179. public protocol Echo_EchoAsyncClientProtocol: GRPCClient {
  180. static var serviceDescriptor: GRPCServiceDescriptor { get }
  181. var interceptors: Echo_EchoClientInterceptorFactoryProtocol? { get }
  182. func makeGetCall(
  183. _ request: Echo_EchoRequest,
  184. callOptions: CallOptions?
  185. ) -> GRPCAsyncUnaryCall<Echo_EchoRequest, Echo_EchoResponse>
  186. func makeExpandCall(
  187. _ request: Echo_EchoRequest,
  188. callOptions: CallOptions?
  189. ) -> GRPCAsyncServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  190. func makeCollectCall(
  191. callOptions: CallOptions?
  192. ) -> GRPCAsyncClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  193. func makeUpdateCall(
  194. callOptions: CallOptions?
  195. ) -> GRPCAsyncBidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  196. }
  197. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  198. extension Echo_EchoAsyncClientProtocol {
  199. public static var serviceDescriptor: GRPCServiceDescriptor {
  200. return Echo_EchoClientMetadata.serviceDescriptor
  201. }
  202. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol? {
  203. return nil
  204. }
  205. public func makeGetCall(
  206. _ request: Echo_EchoRequest,
  207. callOptions: CallOptions? = nil
  208. ) -> GRPCAsyncUnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
  209. return self.makeAsyncUnaryCall(
  210. path: Echo_EchoClientMetadata.Methods.get.path,
  211. request: request,
  212. callOptions: callOptions ?? self.defaultCallOptions,
  213. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  214. )
  215. }
  216. public func makeExpandCall(
  217. _ request: Echo_EchoRequest,
  218. callOptions: CallOptions? = nil
  219. ) -> GRPCAsyncServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  220. return self.makeAsyncServerStreamingCall(
  221. path: Echo_EchoClientMetadata.Methods.expand.path,
  222. request: request,
  223. callOptions: callOptions ?? self.defaultCallOptions,
  224. interceptors: self.interceptors?.makeExpandInterceptors() ?? []
  225. )
  226. }
  227. public func makeCollectCall(
  228. callOptions: CallOptions? = nil
  229. ) -> GRPCAsyncClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  230. return self.makeAsyncClientStreamingCall(
  231. path: Echo_EchoClientMetadata.Methods.collect.path,
  232. callOptions: callOptions ?? self.defaultCallOptions,
  233. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  234. )
  235. }
  236. public func makeUpdateCall(
  237. callOptions: CallOptions? = nil
  238. ) -> GRPCAsyncBidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  239. return self.makeAsyncBidirectionalStreamingCall(
  240. path: Echo_EchoClientMetadata.Methods.update.path,
  241. callOptions: callOptions ?? self.defaultCallOptions,
  242. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  243. )
  244. }
  245. }
  246. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  247. extension Echo_EchoAsyncClientProtocol {
  248. public func get(
  249. _ request: Echo_EchoRequest,
  250. callOptions: CallOptions? = nil
  251. ) async throws -> Echo_EchoResponse {
  252. return try await self.performAsyncUnaryCall(
  253. path: Echo_EchoClientMetadata.Methods.get.path,
  254. request: request,
  255. callOptions: callOptions ?? self.defaultCallOptions,
  256. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  257. )
  258. }
  259. public func expand(
  260. _ request: Echo_EchoRequest,
  261. callOptions: CallOptions? = nil
  262. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> {
  263. return self.performAsyncServerStreamingCall(
  264. path: Echo_EchoClientMetadata.Methods.expand.path,
  265. request: request,
  266. callOptions: callOptions ?? self.defaultCallOptions,
  267. interceptors: self.interceptors?.makeExpandInterceptors() ?? []
  268. )
  269. }
  270. public func collect<RequestStream>(
  271. _ requests: RequestStream,
  272. callOptions: CallOptions? = nil
  273. ) async throws -> Echo_EchoResponse where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
  274. return try await self.performAsyncClientStreamingCall(
  275. path: Echo_EchoClientMetadata.Methods.collect.path,
  276. requests: requests,
  277. callOptions: callOptions ?? self.defaultCallOptions,
  278. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  279. )
  280. }
  281. public func collect<RequestStream>(
  282. _ requests: RequestStream,
  283. callOptions: CallOptions? = nil
  284. ) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Echo_EchoRequest {
  285. return try await self.performAsyncClientStreamingCall(
  286. path: Echo_EchoClientMetadata.Methods.collect.path,
  287. requests: requests,
  288. callOptions: callOptions ?? self.defaultCallOptions,
  289. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  290. )
  291. }
  292. public func update<RequestStream>(
  293. _ requests: RequestStream,
  294. callOptions: CallOptions? = nil
  295. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
  296. return self.performAsyncBidirectionalStreamingCall(
  297. path: Echo_EchoClientMetadata.Methods.update.path,
  298. requests: requests,
  299. callOptions: callOptions ?? self.defaultCallOptions,
  300. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  301. )
  302. }
  303. public func update<RequestStream>(
  304. _ requests: RequestStream,
  305. callOptions: CallOptions? = nil
  306. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Echo_EchoRequest {
  307. return self.performAsyncBidirectionalStreamingCall(
  308. path: Echo_EchoClientMetadata.Methods.update.path,
  309. requests: requests,
  310. callOptions: callOptions ?? self.defaultCallOptions,
  311. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  312. )
  313. }
  314. }
  315. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  316. public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
  317. public var channel: GRPCChannel
  318. public var defaultCallOptions: CallOptions
  319. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  320. public init(
  321. channel: GRPCChannel,
  322. defaultCallOptions: CallOptions = CallOptions(),
  323. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  324. ) {
  325. self.channel = channel
  326. self.defaultCallOptions = defaultCallOptions
  327. self.interceptors = interceptors
  328. }
  329. }
  330. public protocol Echo_EchoClientInterceptorFactoryProtocol: Sendable {
  331. /// - Returns: Interceptors to use when invoking 'get'.
  332. func makeGetInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  333. /// - Returns: Interceptors to use when invoking 'expand'.
  334. func makeExpandInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  335. /// - Returns: Interceptors to use when invoking 'collect'.
  336. func makeCollectInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  337. /// - Returns: Interceptors to use when invoking 'update'.
  338. func makeUpdateInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  339. }
  340. public enum Echo_EchoClientMetadata {
  341. public static let serviceDescriptor = GRPCServiceDescriptor(
  342. name: "Echo",
  343. fullName: "echo.Echo",
  344. methods: [
  345. Echo_EchoClientMetadata.Methods.get,
  346. Echo_EchoClientMetadata.Methods.expand,
  347. Echo_EchoClientMetadata.Methods.collect,
  348. Echo_EchoClientMetadata.Methods.update,
  349. ]
  350. )
  351. public enum Methods {
  352. public static let get = GRPCMethodDescriptor(
  353. name: "Get",
  354. path: "/echo.Echo/Get",
  355. type: GRPCCallType.unary
  356. )
  357. public static let expand = GRPCMethodDescriptor(
  358. name: "Expand",
  359. path: "/echo.Echo/Expand",
  360. type: GRPCCallType.serverStreaming
  361. )
  362. public static let collect = GRPCMethodDescriptor(
  363. name: "Collect",
  364. path: "/echo.Echo/Collect",
  365. type: GRPCCallType.clientStreaming
  366. )
  367. public static let update = GRPCMethodDescriptor(
  368. name: "Update",
  369. path: "/echo.Echo/Update",
  370. type: GRPCCallType.bidirectionalStreaming
  371. )
  372. }
  373. }
  374. @available(swift, deprecated: 5.6)
  375. extension Echo_EchoTestClient: @unchecked Sendable {}
  376. @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.")
  377. public final class Echo_EchoTestClient: Echo_EchoClientProtocol {
  378. private let fakeChannel: FakeChannel
  379. public var defaultCallOptions: CallOptions
  380. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  381. public var channel: GRPCChannel {
  382. return self.fakeChannel
  383. }
  384. public init(
  385. fakeChannel: FakeChannel = FakeChannel(),
  386. defaultCallOptions callOptions: CallOptions = CallOptions(),
  387. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  388. ) {
  389. self.fakeChannel = fakeChannel
  390. self.defaultCallOptions = callOptions
  391. self.interceptors = interceptors
  392. }
  393. /// Make a unary response for the Get RPC. This must be called
  394. /// before calling 'get'. See also 'FakeUnaryResponse'.
  395. ///
  396. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  397. public func makeGetResponseStream(
  398. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  399. ) -> FakeUnaryResponse<Echo_EchoRequest, Echo_EchoResponse> {
  400. return self.fakeChannel.makeFakeUnaryResponse(path: Echo_EchoClientMetadata.Methods.get.path, requestHandler: requestHandler)
  401. }
  402. public func enqueueGetResponse(
  403. _ response: Echo_EchoResponse,
  404. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  405. ) {
  406. let stream = self.makeGetResponseStream(requestHandler)
  407. // This is the only operation on the stream; try! is fine.
  408. try! stream.sendMessage(response)
  409. }
  410. /// Returns true if there are response streams enqueued for 'Get'
  411. public var hasGetResponsesRemaining: Bool {
  412. return self.fakeChannel.hasFakeResponseEnqueued(forPath: Echo_EchoClientMetadata.Methods.get.path)
  413. }
  414. /// Make a streaming response for the Expand RPC. This must be called
  415. /// before calling 'expand'. See also 'FakeStreamingResponse'.
  416. ///
  417. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  418. public func makeExpandResponseStream(
  419. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  420. ) -> FakeStreamingResponse<Echo_EchoRequest, Echo_EchoResponse> {
  421. return self.fakeChannel.makeFakeStreamingResponse(path: Echo_EchoClientMetadata.Methods.expand.path, requestHandler: requestHandler)
  422. }
  423. public func enqueueExpandResponses(
  424. _ responses: [Echo_EchoResponse],
  425. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  426. ) {
  427. let stream = self.makeExpandResponseStream(requestHandler)
  428. // These are the only operation on the stream; try! is fine.
  429. responses.forEach { try! stream.sendMessage($0) }
  430. try! stream.sendEnd()
  431. }
  432. /// Returns true if there are response streams enqueued for 'Expand'
  433. public var hasExpandResponsesRemaining: Bool {
  434. return self.fakeChannel.hasFakeResponseEnqueued(forPath: Echo_EchoClientMetadata.Methods.expand.path)
  435. }
  436. /// Make a unary response for the Collect RPC. This must be called
  437. /// before calling 'collect'. See also 'FakeUnaryResponse'.
  438. ///
  439. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  440. public func makeCollectResponseStream(
  441. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  442. ) -> FakeUnaryResponse<Echo_EchoRequest, Echo_EchoResponse> {
  443. return self.fakeChannel.makeFakeUnaryResponse(path: Echo_EchoClientMetadata.Methods.collect.path, requestHandler: requestHandler)
  444. }
  445. public func enqueueCollectResponse(
  446. _ response: Echo_EchoResponse,
  447. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  448. ) {
  449. let stream = self.makeCollectResponseStream(requestHandler)
  450. // This is the only operation on the stream; try! is fine.
  451. try! stream.sendMessage(response)
  452. }
  453. /// Returns true if there are response streams enqueued for 'Collect'
  454. public var hasCollectResponsesRemaining: Bool {
  455. return self.fakeChannel.hasFakeResponseEnqueued(forPath: Echo_EchoClientMetadata.Methods.collect.path)
  456. }
  457. /// Make a streaming response for the Update RPC. This must be called
  458. /// before calling 'update'. See also 'FakeStreamingResponse'.
  459. ///
  460. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  461. public func makeUpdateResponseStream(
  462. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  463. ) -> FakeStreamingResponse<Echo_EchoRequest, Echo_EchoResponse> {
  464. return self.fakeChannel.makeFakeStreamingResponse(path: Echo_EchoClientMetadata.Methods.update.path, requestHandler: requestHandler)
  465. }
  466. public func enqueueUpdateResponses(
  467. _ responses: [Echo_EchoResponse],
  468. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  469. ) {
  470. let stream = self.makeUpdateResponseStream(requestHandler)
  471. // These are the only operation on the stream; try! is fine.
  472. responses.forEach { try! stream.sendMessage($0) }
  473. try! stream.sendEnd()
  474. }
  475. /// Returns true if there are response streams enqueued for 'Update'
  476. public var hasUpdateResponsesRemaining: Bool {
  477. return self.fakeChannel.hasFakeResponseEnqueued(forPath: Echo_EchoClientMetadata.Methods.update.path)
  478. }
  479. }
  480. /// To build a server, implement a class that conforms to this protocol.
  481. public protocol Echo_EchoProvider: CallHandlerProvider {
  482. var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
  483. /// Immediately returns an echo of a request.
  484. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  485. /// Splits a request into words and returns each word in a stream of messages.
  486. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  487. /// Collects a stream of messages and returns them concatenated when the caller closes.
  488. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  489. /// Streams back messages as they are received in an input stream.
  490. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  491. }
  492. extension Echo_EchoProvider {
  493. public var serviceName: Substring {
  494. return Echo_EchoServerMetadata.serviceDescriptor.fullName[...]
  495. }
  496. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  497. /// Returns nil for methods not handled by this service.
  498. public func handle(
  499. method name: Substring,
  500. context: CallHandlerContext
  501. ) -> GRPCServerHandlerProtocol? {
  502. switch name {
  503. case "Get":
  504. return UnaryServerHandler(
  505. context: context,
  506. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  507. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  508. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  509. userFunction: self.get(request:context:)
  510. )
  511. case "Expand":
  512. return ServerStreamingServerHandler(
  513. context: context,
  514. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  515. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  516. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  517. userFunction: self.expand(request:context:)
  518. )
  519. case "Collect":
  520. return ClientStreamingServerHandler(
  521. context: context,
  522. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  523. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  524. interceptors: self.interceptors?.makeCollectInterceptors() ?? [],
  525. observerFactory: self.collect(context:)
  526. )
  527. case "Update":
  528. return BidirectionalStreamingServerHandler(
  529. context: context,
  530. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  531. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  532. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  533. observerFactory: self.update(context:)
  534. )
  535. default:
  536. return nil
  537. }
  538. }
  539. }
  540. /// To implement a server, implement an object which conforms to this protocol.
  541. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  542. public protocol Echo_EchoAsyncProvider: CallHandlerProvider, Sendable {
  543. static var serviceDescriptor: GRPCServiceDescriptor { get }
  544. var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
  545. /// Immediately returns an echo of a request.
  546. func get(
  547. request: Echo_EchoRequest,
  548. context: GRPCAsyncServerCallContext
  549. ) async throws -> Echo_EchoResponse
  550. /// Splits a request into words and returns each word in a stream of messages.
  551. func expand(
  552. request: Echo_EchoRequest,
  553. responseStream: GRPCAsyncResponseStreamWriter<Echo_EchoResponse>,
  554. context: GRPCAsyncServerCallContext
  555. ) async throws
  556. /// Collects a stream of messages and returns them concatenated when the caller closes.
  557. func collect(
  558. requestStream: GRPCAsyncRequestStream<Echo_EchoRequest>,
  559. context: GRPCAsyncServerCallContext
  560. ) async throws -> Echo_EchoResponse
  561. /// Streams back messages as they are received in an input stream.
  562. func update(
  563. requestStream: GRPCAsyncRequestStream<Echo_EchoRequest>,
  564. responseStream: GRPCAsyncResponseStreamWriter<Echo_EchoResponse>,
  565. context: GRPCAsyncServerCallContext
  566. ) async throws
  567. }
  568. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  569. extension Echo_EchoAsyncProvider {
  570. public static var serviceDescriptor: GRPCServiceDescriptor {
  571. return Echo_EchoServerMetadata.serviceDescriptor
  572. }
  573. public var serviceName: Substring {
  574. return Echo_EchoServerMetadata.serviceDescriptor.fullName[...]
  575. }
  576. public var interceptors: Echo_EchoServerInterceptorFactoryProtocol? {
  577. return nil
  578. }
  579. public func handle(
  580. method name: Substring,
  581. context: CallHandlerContext
  582. ) -> GRPCServerHandlerProtocol? {
  583. switch name {
  584. case "Get":
  585. return GRPCAsyncServerHandler(
  586. context: context,
  587. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  588. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  589. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  590. wrapping: { try await self.get(request: $0, context: $1) }
  591. )
  592. case "Expand":
  593. return GRPCAsyncServerHandler(
  594. context: context,
  595. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  596. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  597. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  598. wrapping: { try await self.expand(request: $0, responseStream: $1, context: $2) }
  599. )
  600. case "Collect":
  601. return GRPCAsyncServerHandler(
  602. context: context,
  603. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  604. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  605. interceptors: self.interceptors?.makeCollectInterceptors() ?? [],
  606. wrapping: { try await self.collect(requestStream: $0, context: $1) }
  607. )
  608. case "Update":
  609. return GRPCAsyncServerHandler(
  610. context: context,
  611. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  612. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  613. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  614. wrapping: { try await self.update(requestStream: $0, responseStream: $1, context: $2) }
  615. )
  616. default:
  617. return nil
  618. }
  619. }
  620. }
  621. public protocol Echo_EchoServerInterceptorFactoryProtocol: Sendable {
  622. /// - Returns: Interceptors to use when handling 'get'.
  623. /// Defaults to calling `self.makeInterceptors()`.
  624. func makeGetInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  625. /// - Returns: Interceptors to use when handling 'expand'.
  626. /// Defaults to calling `self.makeInterceptors()`.
  627. func makeExpandInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  628. /// - Returns: Interceptors to use when handling 'collect'.
  629. /// Defaults to calling `self.makeInterceptors()`.
  630. func makeCollectInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  631. /// - Returns: Interceptors to use when handling 'update'.
  632. /// Defaults to calling `self.makeInterceptors()`.
  633. func makeUpdateInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  634. }
  635. public enum Echo_EchoServerMetadata {
  636. public static let serviceDescriptor = GRPCServiceDescriptor(
  637. name: "Echo",
  638. fullName: "echo.Echo",
  639. methods: [
  640. Echo_EchoServerMetadata.Methods.get,
  641. Echo_EchoServerMetadata.Methods.expand,
  642. Echo_EchoServerMetadata.Methods.collect,
  643. Echo_EchoServerMetadata.Methods.update,
  644. ]
  645. )
  646. public enum Methods {
  647. public static let get = GRPCMethodDescriptor(
  648. name: "Get",
  649. path: "/echo.Echo/Get",
  650. type: GRPCCallType.unary
  651. )
  652. public static let expand = GRPCMethodDescriptor(
  653. name: "Expand",
  654. path: "/echo.Echo/Expand",
  655. type: GRPCCallType.serverStreaming
  656. )
  657. public static let collect = GRPCMethodDescriptor(
  658. name: "Collect",
  659. path: "/echo.Echo/Collect",
  660. type: GRPCCallType.clientStreaming
  661. )
  662. public static let update = GRPCMethodDescriptor(
  663. name: "Update",
  664. path: "/echo.Echo/Update",
  665. type: GRPCCallType.bidirectionalStreaming
  666. )
  667. }
  668. }