2
0

echo.grpc.swift 27 KB

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