echo.grpc.swift 23 KB

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