echo.grpc.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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) && canImport(_Concurrency)
  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. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  192. )
  193. }
  194. public func makeExpandCall(
  195. _ request: Echo_EchoRequest,
  196. callOptions: CallOptions? = nil
  197. ) -> GRPCAsyncServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  198. return self.makeAsyncServerStreamingCall(
  199. path: "/echo.Echo/Expand",
  200. request: request,
  201. callOptions: callOptions ?? self.defaultCallOptions,
  202. interceptors: self.interceptors?.makeExpandInterceptors() ?? []
  203. )
  204. }
  205. public func makeCollectCall(
  206. callOptions: CallOptions? = nil
  207. ) -> GRPCAsyncClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  208. return self.makeAsyncClientStreamingCall(
  209. path: "/echo.Echo/Collect",
  210. callOptions: callOptions ?? self.defaultCallOptions,
  211. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  212. )
  213. }
  214. public func makeUpdateCall(
  215. callOptions: CallOptions? = nil
  216. ) -> GRPCAsyncBidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  217. return self.makeAsyncBidirectionalStreamingCall(
  218. path: "/echo.Echo/Update",
  219. callOptions: callOptions ?? self.defaultCallOptions,
  220. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  221. )
  222. }
  223. }
  224. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
  225. extension Echo_EchoAsyncClientProtocol {
  226. public func get(
  227. _ request: Echo_EchoRequest,
  228. callOptions: CallOptions? = nil
  229. ) async throws -> Echo_EchoResponse {
  230. return try await self.performAsyncUnaryCall(
  231. path: "/echo.Echo/Get",
  232. request: request,
  233. callOptions: callOptions ?? self.defaultCallOptions,
  234. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  235. )
  236. }
  237. public func expand(
  238. _ request: Echo_EchoRequest,
  239. callOptions: CallOptions? = nil
  240. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> {
  241. return self.performAsyncServerStreamingCall(
  242. path: "/echo.Echo/Expand",
  243. request: request,
  244. callOptions: callOptions ?? self.defaultCallOptions,
  245. interceptors: self.interceptors?.makeExpandInterceptors() ?? []
  246. )
  247. }
  248. public func collect<RequestStream>(
  249. _ requests: RequestStream,
  250. callOptions: CallOptions? = nil
  251. ) async throws -> Echo_EchoResponse where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
  252. return try await self.performAsyncClientStreamingCall(
  253. path: "/echo.Echo/Collect",
  254. requests: requests,
  255. callOptions: callOptions ?? self.defaultCallOptions,
  256. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  257. )
  258. }
  259. public func collect<RequestStream>(
  260. _ requests: RequestStream,
  261. callOptions: CallOptions? = nil
  262. ) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
  263. return try await self.performAsyncClientStreamingCall(
  264. path: "/echo.Echo/Collect",
  265. requests: requests,
  266. callOptions: callOptions ?? self.defaultCallOptions,
  267. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  268. )
  269. }
  270. public func update<RequestStream>(
  271. _ requests: RequestStream,
  272. callOptions: CallOptions? = nil
  273. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
  274. return self.performAsyncBidirectionalStreamingCall(
  275. path: "/echo.Echo/Update",
  276. requests: requests,
  277. callOptions: callOptions ?? self.defaultCallOptions,
  278. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  279. )
  280. }
  281. public func update<RequestStream>(
  282. _ requests: RequestStream,
  283. callOptions: CallOptions? = nil
  284. ) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
  285. return self.performAsyncBidirectionalStreamingCall(
  286. path: "/echo.Echo/Update",
  287. requests: requests,
  288. callOptions: callOptions ?? self.defaultCallOptions,
  289. interceptors: self.interceptors?.makeUpdateInterceptors() ?? []
  290. )
  291. }
  292. }
  293. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
  294. public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
  295. public var channel: GRPCChannel
  296. public var defaultCallOptions: CallOptions
  297. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  298. public init(
  299. channel: GRPCChannel,
  300. defaultCallOptions: CallOptions = CallOptions(),
  301. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  302. ) {
  303. self.channel = channel
  304. self.defaultCallOptions = defaultCallOptions
  305. self.interceptors = interceptors
  306. }
  307. }
  308. #endif // compiler(>=5.5) && canImport(_Concurrency)
  309. public final class Echo_EchoTestClient: Echo_EchoClientProtocol {
  310. private let fakeChannel: FakeChannel
  311. public var defaultCallOptions: CallOptions
  312. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  313. public var channel: GRPCChannel {
  314. return self.fakeChannel
  315. }
  316. public init(
  317. fakeChannel: FakeChannel = FakeChannel(),
  318. defaultCallOptions callOptions: CallOptions = CallOptions(),
  319. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  320. ) {
  321. self.fakeChannel = fakeChannel
  322. self.defaultCallOptions = callOptions
  323. self.interceptors = interceptors
  324. }
  325. /// Make a unary response for the Get RPC. This must be called
  326. /// before calling 'get'. See also 'FakeUnaryResponse'.
  327. ///
  328. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  329. public func makeGetResponseStream(
  330. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  331. ) -> FakeUnaryResponse<Echo_EchoRequest, Echo_EchoResponse> {
  332. return self.fakeChannel.makeFakeUnaryResponse(path: "/echo.Echo/Get", requestHandler: requestHandler)
  333. }
  334. public func enqueueGetResponse(
  335. _ response: Echo_EchoResponse,
  336. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  337. ) {
  338. let stream = self.makeGetResponseStream(requestHandler)
  339. // This is the only operation on the stream; try! is fine.
  340. try! stream.sendMessage(response)
  341. }
  342. /// Returns true if there are response streams enqueued for 'Get'
  343. public var hasGetResponsesRemaining: Bool {
  344. return self.fakeChannel.hasFakeResponseEnqueued(forPath: "/echo.Echo/Get")
  345. }
  346. /// Make a streaming response for the Expand RPC. This must be called
  347. /// before calling 'expand'. See also 'FakeStreamingResponse'.
  348. ///
  349. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  350. public func makeExpandResponseStream(
  351. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  352. ) -> FakeStreamingResponse<Echo_EchoRequest, Echo_EchoResponse> {
  353. return self.fakeChannel.makeFakeStreamingResponse(path: "/echo.Echo/Expand", requestHandler: requestHandler)
  354. }
  355. public func enqueueExpandResponses(
  356. _ responses: [Echo_EchoResponse],
  357. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  358. ) {
  359. let stream = self.makeExpandResponseStream(requestHandler)
  360. // These are the only operation on the stream; try! is fine.
  361. responses.forEach { try! stream.sendMessage($0) }
  362. try! stream.sendEnd()
  363. }
  364. /// Returns true if there are response streams enqueued for 'Expand'
  365. public var hasExpandResponsesRemaining: Bool {
  366. return self.fakeChannel.hasFakeResponseEnqueued(forPath: "/echo.Echo/Expand")
  367. }
  368. /// Make a unary response for the Collect RPC. This must be called
  369. /// before calling 'collect'. See also 'FakeUnaryResponse'.
  370. ///
  371. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  372. public func makeCollectResponseStream(
  373. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  374. ) -> FakeUnaryResponse<Echo_EchoRequest, Echo_EchoResponse> {
  375. return self.fakeChannel.makeFakeUnaryResponse(path: "/echo.Echo/Collect", requestHandler: requestHandler)
  376. }
  377. public func enqueueCollectResponse(
  378. _ response: Echo_EchoResponse,
  379. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  380. ) {
  381. let stream = self.makeCollectResponseStream(requestHandler)
  382. // This is the only operation on the stream; try! is fine.
  383. try! stream.sendMessage(response)
  384. }
  385. /// Returns true if there are response streams enqueued for 'Collect'
  386. public var hasCollectResponsesRemaining: Bool {
  387. return self.fakeChannel.hasFakeResponseEnqueued(forPath: "/echo.Echo/Collect")
  388. }
  389. /// Make a streaming response for the Update RPC. This must be called
  390. /// before calling 'update'. See also 'FakeStreamingResponse'.
  391. ///
  392. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  393. public func makeUpdateResponseStream(
  394. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  395. ) -> FakeStreamingResponse<Echo_EchoRequest, Echo_EchoResponse> {
  396. return self.fakeChannel.makeFakeStreamingResponse(path: "/echo.Echo/Update", requestHandler: requestHandler)
  397. }
  398. public func enqueueUpdateResponses(
  399. _ responses: [Echo_EchoResponse],
  400. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  401. ) {
  402. let stream = self.makeUpdateResponseStream(requestHandler)
  403. // These are the only operation on the stream; try! is fine.
  404. responses.forEach { try! stream.sendMessage($0) }
  405. try! stream.sendEnd()
  406. }
  407. /// Returns true if there are response streams enqueued for 'Update'
  408. public var hasUpdateResponsesRemaining: Bool {
  409. return self.fakeChannel.hasFakeResponseEnqueued(forPath: "/echo.Echo/Update")
  410. }
  411. }
  412. /// To build a server, implement a class that conforms to this protocol.
  413. public protocol Echo_EchoProvider: CallHandlerProvider {
  414. var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
  415. /// Immediately returns an echo of a request.
  416. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  417. /// Splits a request into words and returns each word in a stream of messages.
  418. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  419. /// Collects a stream of messages and returns them concatenated when the caller closes.
  420. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  421. /// Streams back messages as they are received in an input stream.
  422. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  423. }
  424. extension Echo_EchoProvider {
  425. public var serviceName: Substring { return "echo.Echo" }
  426. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  427. /// Returns nil for methods not handled by this service.
  428. public func handle(
  429. method name: Substring,
  430. context: CallHandlerContext
  431. ) -> GRPCServerHandlerProtocol? {
  432. switch name {
  433. case "Get":
  434. return UnaryServerHandler(
  435. context: context,
  436. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  437. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  438. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  439. userFunction: self.get(request:context:)
  440. )
  441. case "Expand":
  442. return ServerStreamingServerHandler(
  443. context: context,
  444. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  445. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  446. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  447. userFunction: self.expand(request:context:)
  448. )
  449. case "Collect":
  450. return ClientStreamingServerHandler(
  451. context: context,
  452. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  453. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  454. interceptors: self.interceptors?.makeCollectInterceptors() ?? [],
  455. observerFactory: self.collect(context:)
  456. )
  457. case "Update":
  458. return BidirectionalStreamingServerHandler(
  459. context: context,
  460. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  461. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  462. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  463. observerFactory: self.update(context:)
  464. )
  465. default:
  466. return nil
  467. }
  468. }
  469. }
  470. public protocol Echo_EchoServerInterceptorFactoryProtocol {
  471. /// - Returns: Interceptors to use when handling 'get'.
  472. /// Defaults to calling `self.makeInterceptors()`.
  473. func makeGetInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  474. /// - Returns: Interceptors to use when handling 'expand'.
  475. /// Defaults to calling `self.makeInterceptors()`.
  476. func makeExpandInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  477. /// - Returns: Interceptors to use when handling 'collect'.
  478. /// Defaults to calling `self.makeInterceptors()`.
  479. func makeCollectInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  480. /// - Returns: Interceptors to use when handling 'update'.
  481. /// Defaults to calling `self.makeInterceptors()`.
  482. func makeUpdateInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  483. }
  484. #if compiler(>=5.5) && canImport(_Concurrency)
  485. /// To implement a server, implement an object which conforms to this protocol.
  486. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
  487. public protocol Echo_EchoAsyncProvider: CallHandlerProvider {
  488. var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
  489. /// Immediately returns an echo of a request.
  490. @Sendable func get(
  491. request: Echo_EchoRequest,
  492. context: GRPCAsyncServerCallContext
  493. ) async throws -> Echo_EchoResponse
  494. /// Splits a request into words and returns each word in a stream of messages.
  495. @Sendable func expand(
  496. request: Echo_EchoRequest,
  497. responseStream: GRPCAsyncResponseStreamWriter<Echo_EchoResponse>,
  498. context: GRPCAsyncServerCallContext
  499. ) async throws
  500. /// Collects a stream of messages and returns them concatenated when the caller closes.
  501. @Sendable func collect(
  502. requests: GRPCAsyncRequestStream<Echo_EchoRequest>,
  503. context: GRPCAsyncServerCallContext
  504. ) async throws -> Echo_EchoResponse
  505. /// Streams back messages as they are received in an input stream.
  506. @Sendable func update(
  507. requests: GRPCAsyncRequestStream<Echo_EchoRequest>,
  508. responseStream: GRPCAsyncResponseStreamWriter<Echo_EchoResponse>,
  509. context: GRPCAsyncServerCallContext
  510. ) async throws
  511. }
  512. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
  513. extension Echo_EchoAsyncProvider {
  514. public var serviceName: Substring {
  515. return "echo.Echo"
  516. }
  517. public var interceptors: Echo_EchoServerInterceptorFactoryProtocol? {
  518. return nil
  519. }
  520. public func handle(
  521. method name: Substring,
  522. context: CallHandlerContext
  523. ) -> GRPCServerHandlerProtocol? {
  524. switch name {
  525. case "Get":
  526. return GRPCAsyncServerHandler(
  527. context: context,
  528. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  529. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  530. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  531. wrapping: self.get(request:context:)
  532. )
  533. case "Expand":
  534. return GRPCAsyncServerHandler(
  535. context: context,
  536. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  537. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  538. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  539. wrapping: self.expand(request:responseStream:context:)
  540. )
  541. case "Collect":
  542. return GRPCAsyncServerHandler(
  543. context: context,
  544. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  545. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  546. interceptors: self.interceptors?.makeCollectInterceptors() ?? [],
  547. wrapping: self.collect(requests:context:)
  548. )
  549. case "Update":
  550. return GRPCAsyncServerHandler(
  551. context: context,
  552. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  553. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  554. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  555. wrapping: self.update(requests:responseStream:context:)
  556. )
  557. default:
  558. return nil
  559. }
  560. }
  561. }
  562. #endif // compiler(>=5.5) && canImport(_Concurrency)