echo.grpc.swift 27 KB

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