echo.grpc.swift 28 KB

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