echo.grpc.swift 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. // Copyright (c) 2015, Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // DO NOT EDIT.
  15. // swift-format-ignore-file
  16. //
  17. // Generated by the gRPC Swift generator plugin for the protocol buffer compiler.
  18. // Source: echo.proto
  19. //
  20. // For information on using the generated types, please see the documentation:
  21. // https://github.com/grpc/grpc-swift
  22. import GRPCCore
  23. import GRPCProtobuf
  24. // MARK: - echo.Echo
  25. /// Namespace containing generated types for the "echo.Echo" service.
  26. internal enum Echo_Echo {
  27. /// Service descriptor for the "echo.Echo" service.
  28. internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo")
  29. /// Namespace for method metadata.
  30. internal enum Method {
  31. /// Namespace for "Get" metadata.
  32. internal enum Get {
  33. /// Request type for "Get".
  34. internal typealias Input = Echo_EchoRequest
  35. /// Response type for "Get".
  36. internal typealias Output = Echo_EchoResponse
  37. /// Descriptor for "Get".
  38. internal static let descriptor = GRPCCore.MethodDescriptor(
  39. service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"),
  40. method: "Get"
  41. )
  42. }
  43. /// Namespace for "Expand" metadata.
  44. internal enum Expand {
  45. /// Request type for "Expand".
  46. internal typealias Input = Echo_EchoRequest
  47. /// Response type for "Expand".
  48. internal typealias Output = Echo_EchoResponse
  49. /// Descriptor for "Expand".
  50. internal static let descriptor = GRPCCore.MethodDescriptor(
  51. service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"),
  52. method: "Expand"
  53. )
  54. }
  55. /// Namespace for "Collect" metadata.
  56. internal enum Collect {
  57. /// Request type for "Collect".
  58. internal typealias Input = Echo_EchoRequest
  59. /// Response type for "Collect".
  60. internal typealias Output = Echo_EchoResponse
  61. /// Descriptor for "Collect".
  62. internal static let descriptor = GRPCCore.MethodDescriptor(
  63. service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"),
  64. method: "Collect"
  65. )
  66. }
  67. /// Namespace for "Update" metadata.
  68. internal enum Update {
  69. /// Request type for "Update".
  70. internal typealias Input = Echo_EchoRequest
  71. /// Response type for "Update".
  72. internal typealias Output = Echo_EchoResponse
  73. /// Descriptor for "Update".
  74. internal static let descriptor = GRPCCore.MethodDescriptor(
  75. service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"),
  76. method: "Update"
  77. )
  78. }
  79. /// Descriptors for all methods in the "echo.Echo" service.
  80. internal static let descriptors: [GRPCCore.MethodDescriptor] = [
  81. Get.descriptor,
  82. Expand.descriptor,
  83. Collect.descriptor,
  84. Update.descriptor
  85. ]
  86. }
  87. }
  88. extension GRPCCore.ServiceDescriptor {
  89. /// Service descriptor for the "echo.Echo" service.
  90. internal static let echo_Echo = GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo")
  91. }
  92. // MARK: echo.Echo (server)
  93. extension Echo_Echo {
  94. /// Streaming variant of the service protocol for the "echo.Echo" service.
  95. ///
  96. /// This protocol is the lowest-level of the service protocols generated for this service
  97. /// giving you the most flexibility over the implementation of your service. This comes at
  98. /// the cost of more verbose and less strict APIs. Each RPC requires you to implement it in
  99. /// terms of a request stream and response stream. Where only a single request or response
  100. /// message is expected, you are responsible for enforcing this invariant is maintained.
  101. ///
  102. /// Where possible, prefer using the stricter, less-verbose ``ServiceProtocol``
  103. /// or ``SimpleServiceProtocol`` instead.
  104. internal protocol StreamingServiceProtocol: GRPCCore.RegistrableRPCService {
  105. /// Handle the "Get" method.
  106. ///
  107. /// > Source IDL Documentation:
  108. /// >
  109. /// > Immediately returns an echo of a request.
  110. ///
  111. /// - Parameters:
  112. /// - request: A streaming request of `Echo_EchoRequest` messages.
  113. /// - context: Context providing information about the RPC.
  114. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  115. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  116. /// to an internal error.
  117. /// - Returns: A streaming response of `Echo_EchoResponse` messages.
  118. func get(
  119. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  120. context: GRPCCore.ServerContext
  121. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
  122. /// Handle the "Expand" method.
  123. ///
  124. /// > Source IDL Documentation:
  125. /// >
  126. /// > Splits a request into words and returns each word in a stream of messages.
  127. ///
  128. /// - Parameters:
  129. /// - request: A streaming request of `Echo_EchoRequest` messages.
  130. /// - context: Context providing information about the RPC.
  131. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  132. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  133. /// to an internal error.
  134. /// - Returns: A streaming response of `Echo_EchoResponse` messages.
  135. func expand(
  136. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  137. context: GRPCCore.ServerContext
  138. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
  139. /// Handle the "Collect" method.
  140. ///
  141. /// > Source IDL Documentation:
  142. /// >
  143. /// > Collects a stream of messages and returns them concatenated when the caller closes.
  144. ///
  145. /// - Parameters:
  146. /// - request: A streaming request of `Echo_EchoRequest` messages.
  147. /// - context: Context providing information about the RPC.
  148. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  149. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  150. /// to an internal error.
  151. /// - Returns: A streaming response of `Echo_EchoResponse` messages.
  152. func collect(
  153. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  154. context: GRPCCore.ServerContext
  155. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
  156. /// Handle the "Update" method.
  157. ///
  158. /// > Source IDL Documentation:
  159. /// >
  160. /// > Streams back messages as they are received in an input stream.
  161. ///
  162. /// - Parameters:
  163. /// - request: A streaming request of `Echo_EchoRequest` messages.
  164. /// - context: Context providing information about the RPC.
  165. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  166. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  167. /// to an internal error.
  168. /// - Returns: A streaming response of `Echo_EchoResponse` messages.
  169. func update(
  170. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  171. context: GRPCCore.ServerContext
  172. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
  173. }
  174. /// Service protocol for the "echo.Echo" service.
  175. ///
  176. /// This protocol is higher level than ``StreamingServiceProtocol`` but lower level than
  177. /// the ``SimpleServiceProtocol``, it provides access to request and response metadata and
  178. /// trailing response metadata. If you don't need these then consider using
  179. /// the ``SimpleServiceProtocol``. If you need fine grained control over your RPCs then
  180. /// use ``StreamingServiceProtocol``.
  181. internal protocol ServiceProtocol: Echo_Echo.StreamingServiceProtocol {
  182. /// Handle the "Get" method.
  183. ///
  184. /// > Source IDL Documentation:
  185. /// >
  186. /// > Immediately returns an echo of a request.
  187. ///
  188. /// - Parameters:
  189. /// - request: A request containing a single `Echo_EchoRequest` message.
  190. /// - context: Context providing information about the RPC.
  191. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  192. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  193. /// to an internal error.
  194. /// - Returns: A response containing a single `Echo_EchoResponse` message.
  195. func get(
  196. request: GRPCCore.ServerRequest<Echo_EchoRequest>,
  197. context: GRPCCore.ServerContext
  198. ) async throws -> GRPCCore.ServerResponse<Echo_EchoResponse>
  199. /// Handle the "Expand" method.
  200. ///
  201. /// > Source IDL Documentation:
  202. /// >
  203. /// > Splits a request into words and returns each word in a stream of messages.
  204. ///
  205. /// - Parameters:
  206. /// - request: A request containing a single `Echo_EchoRequest` message.
  207. /// - context: Context providing information about the RPC.
  208. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  209. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  210. /// to an internal error.
  211. /// - Returns: A streaming response of `Echo_EchoResponse` messages.
  212. func expand(
  213. request: GRPCCore.ServerRequest<Echo_EchoRequest>,
  214. context: GRPCCore.ServerContext
  215. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
  216. /// Handle the "Collect" method.
  217. ///
  218. /// > Source IDL Documentation:
  219. /// >
  220. /// > Collects a stream of messages and returns them concatenated when the caller closes.
  221. ///
  222. /// - Parameters:
  223. /// - request: A streaming request of `Echo_EchoRequest` messages.
  224. /// - context: Context providing information about the RPC.
  225. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  226. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  227. /// to an internal error.
  228. /// - Returns: A response containing a single `Echo_EchoResponse` message.
  229. func collect(
  230. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  231. context: GRPCCore.ServerContext
  232. ) async throws -> GRPCCore.ServerResponse<Echo_EchoResponse>
  233. /// Handle the "Update" method.
  234. ///
  235. /// > Source IDL Documentation:
  236. /// >
  237. /// > Streams back messages as they are received in an input stream.
  238. ///
  239. /// - Parameters:
  240. /// - request: A streaming request of `Echo_EchoRequest` messages.
  241. /// - context: Context providing information about the RPC.
  242. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  243. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  244. /// to an internal error.
  245. /// - Returns: A streaming response of `Echo_EchoResponse` messages.
  246. func update(
  247. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  248. context: GRPCCore.ServerContext
  249. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
  250. }
  251. /// Simple service protocol for the "echo.Echo" service.
  252. ///
  253. /// This is the highest level protocol for the service. The API is the easiest to use but
  254. /// doesn't provide access to request or response metadata. If you need access to these
  255. /// then use ``ServiceProtocol`` instead.
  256. internal protocol SimpleServiceProtocol: Echo_Echo.ServiceProtocol {
  257. /// Handle the "Get" method.
  258. ///
  259. /// > Source IDL Documentation:
  260. /// >
  261. /// > Immediately returns an echo of a request.
  262. ///
  263. /// - Parameters:
  264. /// - request: A `Echo_EchoRequest` message.
  265. /// - context: Context providing information about the RPC.
  266. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  267. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  268. /// to an internal error.
  269. /// - Returns: A `Echo_EchoResponse` to respond with.
  270. func get(
  271. request: Echo_EchoRequest,
  272. context: GRPCCore.ServerContext
  273. ) async throws -> Echo_EchoResponse
  274. /// Handle the "Expand" method.
  275. ///
  276. /// > Source IDL Documentation:
  277. /// >
  278. /// > Splits a request into words and returns each word in a stream of messages.
  279. ///
  280. /// - Parameters:
  281. /// - request: A `Echo_EchoRequest` message.
  282. /// - response: A response stream of `Echo_EchoResponse` messages.
  283. /// - context: Context providing information about the RPC.
  284. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  285. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  286. /// to an internal error.
  287. func expand(
  288. request: Echo_EchoRequest,
  289. response: GRPCCore.RPCWriter<Echo_EchoResponse>,
  290. context: GRPCCore.ServerContext
  291. ) async throws
  292. /// Handle the "Collect" method.
  293. ///
  294. /// > Source IDL Documentation:
  295. /// >
  296. /// > Collects a stream of messages and returns them concatenated when the caller closes.
  297. ///
  298. /// - Parameters:
  299. /// - request: A stream of `Echo_EchoRequest` messages.
  300. /// - context: Context providing information about the RPC.
  301. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  302. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  303. /// to an internal error.
  304. /// - Returns: A `Echo_EchoResponse` to respond with.
  305. func collect(
  306. request: GRPCCore.RPCAsyncSequence<Echo_EchoRequest, any Swift.Error>,
  307. context: GRPCCore.ServerContext
  308. ) async throws -> Echo_EchoResponse
  309. /// Handle the "Update" method.
  310. ///
  311. /// > Source IDL Documentation:
  312. /// >
  313. /// > Streams back messages as they are received in an input stream.
  314. ///
  315. /// - Parameters:
  316. /// - request: A stream of `Echo_EchoRequest` messages.
  317. /// - response: A response stream of `Echo_EchoResponse` messages.
  318. /// - context: Context providing information about the RPC.
  319. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  320. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  321. /// to an internal error.
  322. func update(
  323. request: GRPCCore.RPCAsyncSequence<Echo_EchoRequest, any Swift.Error>,
  324. response: GRPCCore.RPCWriter<Echo_EchoResponse>,
  325. context: GRPCCore.ServerContext
  326. ) async throws
  327. }
  328. }
  329. // Default implementation of 'registerMethods(with:)'.
  330. extension Echo_Echo.StreamingServiceProtocol {
  331. internal func registerMethods(with router: inout GRPCCore.RPCRouter) {
  332. router.registerHandler(
  333. forMethod: Echo_Echo.Method.Get.descriptor,
  334. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
  335. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoResponse>(),
  336. handler: { request, context in
  337. try await self.get(
  338. request: request,
  339. context: context
  340. )
  341. }
  342. )
  343. router.registerHandler(
  344. forMethod: Echo_Echo.Method.Expand.descriptor,
  345. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
  346. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoResponse>(),
  347. handler: { request, context in
  348. try await self.expand(
  349. request: request,
  350. context: context
  351. )
  352. }
  353. )
  354. router.registerHandler(
  355. forMethod: Echo_Echo.Method.Collect.descriptor,
  356. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
  357. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoResponse>(),
  358. handler: { request, context in
  359. try await self.collect(
  360. request: request,
  361. context: context
  362. )
  363. }
  364. )
  365. router.registerHandler(
  366. forMethod: Echo_Echo.Method.Update.descriptor,
  367. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
  368. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoResponse>(),
  369. handler: { request, context in
  370. try await self.update(
  371. request: request,
  372. context: context
  373. )
  374. }
  375. )
  376. }
  377. }
  378. // Default implementation of streaming methods from 'StreamingServiceProtocol'.
  379. extension Echo_Echo.ServiceProtocol {
  380. internal func get(
  381. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  382. context: GRPCCore.ServerContext
  383. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
  384. let response = try await self.get(
  385. request: GRPCCore.ServerRequest(stream: request),
  386. context: context
  387. )
  388. return GRPCCore.StreamingServerResponse(single: response)
  389. }
  390. internal func expand(
  391. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  392. context: GRPCCore.ServerContext
  393. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
  394. let response = try await self.expand(
  395. request: GRPCCore.ServerRequest(stream: request),
  396. context: context
  397. )
  398. return response
  399. }
  400. internal func collect(
  401. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  402. context: GRPCCore.ServerContext
  403. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
  404. let response = try await self.collect(
  405. request: request,
  406. context: context
  407. )
  408. return GRPCCore.StreamingServerResponse(single: response)
  409. }
  410. }
  411. // Default implementation of methods from 'ServiceProtocol'.
  412. extension Echo_Echo.SimpleServiceProtocol {
  413. internal func get(
  414. request: GRPCCore.ServerRequest<Echo_EchoRequest>,
  415. context: GRPCCore.ServerContext
  416. ) async throws -> GRPCCore.ServerResponse<Echo_EchoResponse> {
  417. return GRPCCore.ServerResponse<Echo_EchoResponse>(
  418. message: try await self.get(
  419. request: request.message,
  420. context: context
  421. ),
  422. metadata: [:]
  423. )
  424. }
  425. internal func expand(
  426. request: GRPCCore.ServerRequest<Echo_EchoRequest>,
  427. context: GRPCCore.ServerContext
  428. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
  429. return GRPCCore.StreamingServerResponse<Echo_EchoResponse>(
  430. metadata: [:],
  431. producer: { writer in
  432. try await self.expand(
  433. request: request.message,
  434. response: writer,
  435. context: context
  436. )
  437. return [:]
  438. }
  439. )
  440. }
  441. internal func collect(
  442. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  443. context: GRPCCore.ServerContext
  444. ) async throws -> GRPCCore.ServerResponse<Echo_EchoResponse> {
  445. return GRPCCore.ServerResponse<Echo_EchoResponse>(
  446. message: try await self.collect(
  447. request: request.messages,
  448. context: context
  449. ),
  450. metadata: [:]
  451. )
  452. }
  453. internal func update(
  454. request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
  455. context: GRPCCore.ServerContext
  456. ) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
  457. return GRPCCore.StreamingServerResponse<Echo_EchoResponse>(
  458. metadata: [:],
  459. producer: { writer in
  460. try await self.update(
  461. request: request.messages,
  462. response: writer,
  463. context: context
  464. )
  465. return [:]
  466. }
  467. )
  468. }
  469. }
  470. // MARK: echo.Echo (client)
  471. extension Echo_Echo {
  472. /// Generated client protocol for the "echo.Echo" service.
  473. ///
  474. /// You don't need to implement this protocol directly, use the generated
  475. /// implementation, ``Client``.
  476. internal protocol ClientProtocol: Sendable {
  477. /// Call the "Get" method.
  478. ///
  479. /// > Source IDL Documentation:
  480. /// >
  481. /// > Immediately returns an echo of a request.
  482. ///
  483. /// - Parameters:
  484. /// - request: A request containing a single `Echo_EchoRequest` message.
  485. /// - serializer: A serializer for `Echo_EchoRequest` messages.
  486. /// - deserializer: A deserializer for `Echo_EchoResponse` messages.
  487. /// - options: Options to apply to this RPC.
  488. /// - handleResponse: A closure which handles the response, the result of which is
  489. /// returned to the caller. Returning from the closure will cancel the RPC if it
  490. /// hasn't already finished.
  491. /// - Returns: The result of `handleResponse`.
  492. func get<Result>(
  493. request: GRPCCore.ClientRequest<Echo_EchoRequest>,
  494. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  495. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  496. options: GRPCCore.CallOptions,
  497. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result
  498. ) async throws -> Result where Result: Sendable
  499. /// Call the "Expand" method.
  500. ///
  501. /// > Source IDL Documentation:
  502. /// >
  503. /// > Splits a request into words and returns each word in a stream of messages.
  504. ///
  505. /// - Parameters:
  506. /// - request: A request containing a single `Echo_EchoRequest` message.
  507. /// - serializer: A serializer for `Echo_EchoRequest` messages.
  508. /// - deserializer: A deserializer for `Echo_EchoResponse` messages.
  509. /// - options: Options to apply to this RPC.
  510. /// - handleResponse: A closure which handles the response, the result of which is
  511. /// returned to the caller. Returning from the closure will cancel the RPC if it
  512. /// hasn't already finished.
  513. /// - Returns: The result of `handleResponse`.
  514. func expand<Result>(
  515. request: GRPCCore.ClientRequest<Echo_EchoRequest>,
  516. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  517. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  518. options: GRPCCore.CallOptions,
  519. onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
  520. ) async throws -> Result where Result: Sendable
  521. /// Call the "Collect" method.
  522. ///
  523. /// > Source IDL Documentation:
  524. /// >
  525. /// > Collects a stream of messages and returns them concatenated when the caller closes.
  526. ///
  527. /// - Parameters:
  528. /// - request: A streaming request producing `Echo_EchoRequest` messages.
  529. /// - serializer: A serializer for `Echo_EchoRequest` messages.
  530. /// - deserializer: A deserializer for `Echo_EchoResponse` messages.
  531. /// - options: Options to apply to this RPC.
  532. /// - handleResponse: A closure which handles the response, the result of which is
  533. /// returned to the caller. Returning from the closure will cancel the RPC if it
  534. /// hasn't already finished.
  535. /// - Returns: The result of `handleResponse`.
  536. func collect<Result>(
  537. request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
  538. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  539. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  540. options: GRPCCore.CallOptions,
  541. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result
  542. ) async throws -> Result where Result: Sendable
  543. /// Call the "Update" method.
  544. ///
  545. /// > Source IDL Documentation:
  546. /// >
  547. /// > Streams back messages as they are received in an input stream.
  548. ///
  549. /// - Parameters:
  550. /// - request: A streaming request producing `Echo_EchoRequest` messages.
  551. /// - serializer: A serializer for `Echo_EchoRequest` messages.
  552. /// - deserializer: A deserializer for `Echo_EchoResponse` messages.
  553. /// - options: Options to apply to this RPC.
  554. /// - handleResponse: A closure which handles the response, the result of which is
  555. /// returned to the caller. Returning from the closure will cancel the RPC if it
  556. /// hasn't already finished.
  557. /// - Returns: The result of `handleResponse`.
  558. func update<Result>(
  559. request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
  560. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  561. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  562. options: GRPCCore.CallOptions,
  563. onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
  564. ) async throws -> Result where Result: Sendable
  565. }
  566. /// Generated client for the "echo.Echo" service.
  567. ///
  568. /// The ``Client`` provides an implementation of ``ClientProtocol`` which wraps
  569. /// a `GRPCCore.GRPCCClient`. The underlying `GRPCClient` provides the long-lived
  570. /// means of communication with the remote peer.
  571. internal struct Client: ClientProtocol {
  572. private let client: GRPCCore.GRPCClient
  573. /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`.
  574. ///
  575. /// - Parameters:
  576. /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service.
  577. internal init(wrapping client: GRPCCore.GRPCClient) {
  578. self.client = client
  579. }
  580. /// Call the "Get" method.
  581. ///
  582. /// > Source IDL Documentation:
  583. /// >
  584. /// > Immediately returns an echo of a request.
  585. ///
  586. /// - Parameters:
  587. /// - request: A request containing a single `Echo_EchoRequest` message.
  588. /// - serializer: A serializer for `Echo_EchoRequest` messages.
  589. /// - deserializer: A deserializer for `Echo_EchoResponse` messages.
  590. /// - options: Options to apply to this RPC.
  591. /// - handleResponse: A closure which handles the response, the result of which is
  592. /// returned to the caller. Returning from the closure will cancel the RPC if it
  593. /// hasn't already finished.
  594. /// - Returns: The result of `handleResponse`.
  595. internal func get<Result>(
  596. request: GRPCCore.ClientRequest<Echo_EchoRequest>,
  597. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  598. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  599. options: GRPCCore.CallOptions = .defaults,
  600. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = { response in
  601. try response.message
  602. }
  603. ) async throws -> Result where Result: Sendable {
  604. try await self.client.unary(
  605. request: request,
  606. descriptor: Echo_Echo.Method.Get.descriptor,
  607. serializer: serializer,
  608. deserializer: deserializer,
  609. options: options,
  610. onResponse: handleResponse
  611. )
  612. }
  613. /// Call the "Expand" method.
  614. ///
  615. /// > Source IDL Documentation:
  616. /// >
  617. /// > Splits a request into words and returns each word in a stream of messages.
  618. ///
  619. /// - Parameters:
  620. /// - request: A request containing a single `Echo_EchoRequest` message.
  621. /// - serializer: A serializer for `Echo_EchoRequest` messages.
  622. /// - deserializer: A deserializer for `Echo_EchoResponse` messages.
  623. /// - options: Options to apply to this RPC.
  624. /// - handleResponse: A closure which handles the response, the result of which is
  625. /// returned to the caller. Returning from the closure will cancel the RPC if it
  626. /// hasn't already finished.
  627. /// - Returns: The result of `handleResponse`.
  628. internal func expand<Result>(
  629. request: GRPCCore.ClientRequest<Echo_EchoRequest>,
  630. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  631. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  632. options: GRPCCore.CallOptions = .defaults,
  633. onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
  634. ) async throws -> Result where Result: Sendable {
  635. try await self.client.serverStreaming(
  636. request: request,
  637. descriptor: Echo_Echo.Method.Expand.descriptor,
  638. serializer: serializer,
  639. deserializer: deserializer,
  640. options: options,
  641. onResponse: handleResponse
  642. )
  643. }
  644. /// Call the "Collect" method.
  645. ///
  646. /// > Source IDL Documentation:
  647. /// >
  648. /// > Collects a stream of messages and returns them concatenated when the caller closes.
  649. ///
  650. /// - Parameters:
  651. /// - request: A streaming request producing `Echo_EchoRequest` messages.
  652. /// - serializer: A serializer for `Echo_EchoRequest` messages.
  653. /// - deserializer: A deserializer for `Echo_EchoResponse` messages.
  654. /// - options: Options to apply to this RPC.
  655. /// - handleResponse: A closure which handles the response, the result of which is
  656. /// returned to the caller. Returning from the closure will cancel the RPC if it
  657. /// hasn't already finished.
  658. /// - Returns: The result of `handleResponse`.
  659. internal func collect<Result>(
  660. request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
  661. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  662. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  663. options: GRPCCore.CallOptions = .defaults,
  664. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = { response in
  665. try response.message
  666. }
  667. ) async throws -> Result where Result: Sendable {
  668. try await self.client.clientStreaming(
  669. request: request,
  670. descriptor: Echo_Echo.Method.Collect.descriptor,
  671. serializer: serializer,
  672. deserializer: deserializer,
  673. options: options,
  674. onResponse: handleResponse
  675. )
  676. }
  677. /// Call the "Update" method.
  678. ///
  679. /// > Source IDL Documentation:
  680. /// >
  681. /// > Streams back messages as they are received in an input stream.
  682. ///
  683. /// - Parameters:
  684. /// - request: A streaming request producing `Echo_EchoRequest` messages.
  685. /// - serializer: A serializer for `Echo_EchoRequest` messages.
  686. /// - deserializer: A deserializer for `Echo_EchoResponse` messages.
  687. /// - options: Options to apply to this RPC.
  688. /// - handleResponse: A closure which handles the response, the result of which is
  689. /// returned to the caller. Returning from the closure will cancel the RPC if it
  690. /// hasn't already finished.
  691. /// - Returns: The result of `handleResponse`.
  692. internal func update<Result>(
  693. request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
  694. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  695. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  696. options: GRPCCore.CallOptions = .defaults,
  697. onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
  698. ) async throws -> Result where Result: Sendable {
  699. try await self.client.bidirectionalStreaming(
  700. request: request,
  701. descriptor: Echo_Echo.Method.Update.descriptor,
  702. serializer: serializer,
  703. deserializer: deserializer,
  704. options: options,
  705. onResponse: handleResponse
  706. )
  707. }
  708. }
  709. }
  710. // Helpers providing default arguments to 'ClientProtocol' methods.
  711. extension Echo_Echo.ClientProtocol {
  712. /// Call the "Get" method.
  713. ///
  714. /// > Source IDL Documentation:
  715. /// >
  716. /// > Immediately returns an echo of a request.
  717. ///
  718. /// - Parameters:
  719. /// - request: A request containing a single `Echo_EchoRequest` message.
  720. /// - options: Options to apply to this RPC.
  721. /// - handleResponse: A closure which handles the response, the result of which is
  722. /// returned to the caller. Returning from the closure will cancel the RPC if it
  723. /// hasn't already finished.
  724. /// - Returns: The result of `handleResponse`.
  725. internal func get<Result>(
  726. request: GRPCCore.ClientRequest<Echo_EchoRequest>,
  727. options: GRPCCore.CallOptions = .defaults,
  728. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = { response in
  729. try response.message
  730. }
  731. ) async throws -> Result where Result: Sendable {
  732. try await self.get(
  733. request: request,
  734. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoRequest>(),
  735. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoResponse>(),
  736. options: options,
  737. onResponse: handleResponse
  738. )
  739. }
  740. /// Call the "Expand" method.
  741. ///
  742. /// > Source IDL Documentation:
  743. /// >
  744. /// > Splits a request into words and returns each word in a stream of messages.
  745. ///
  746. /// - Parameters:
  747. /// - request: A request containing a single `Echo_EchoRequest` message.
  748. /// - options: Options to apply to this RPC.
  749. /// - handleResponse: A closure which handles the response, the result of which is
  750. /// returned to the caller. Returning from the closure will cancel the RPC if it
  751. /// hasn't already finished.
  752. /// - Returns: The result of `handleResponse`.
  753. internal func expand<Result>(
  754. request: GRPCCore.ClientRequest<Echo_EchoRequest>,
  755. options: GRPCCore.CallOptions = .defaults,
  756. onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
  757. ) async throws -> Result where Result: Sendable {
  758. try await self.expand(
  759. request: request,
  760. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoRequest>(),
  761. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoResponse>(),
  762. options: options,
  763. onResponse: handleResponse
  764. )
  765. }
  766. /// Call the "Collect" method.
  767. ///
  768. /// > Source IDL Documentation:
  769. /// >
  770. /// > Collects a stream of messages and returns them concatenated when the caller closes.
  771. ///
  772. /// - Parameters:
  773. /// - request: A streaming request producing `Echo_EchoRequest` messages.
  774. /// - options: Options to apply to this RPC.
  775. /// - handleResponse: A closure which handles the response, the result of which is
  776. /// returned to the caller. Returning from the closure will cancel the RPC if it
  777. /// hasn't already finished.
  778. /// - Returns: The result of `handleResponse`.
  779. internal func collect<Result>(
  780. request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
  781. options: GRPCCore.CallOptions = .defaults,
  782. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = { response in
  783. try response.message
  784. }
  785. ) async throws -> Result where Result: Sendable {
  786. try await self.collect(
  787. request: request,
  788. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoRequest>(),
  789. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoResponse>(),
  790. options: options,
  791. onResponse: handleResponse
  792. )
  793. }
  794. /// Call the "Update" method.
  795. ///
  796. /// > Source IDL Documentation:
  797. /// >
  798. /// > Streams back messages as they are received in an input stream.
  799. ///
  800. /// - Parameters:
  801. /// - request: A streaming request producing `Echo_EchoRequest` messages.
  802. /// - options: Options to apply to this RPC.
  803. /// - handleResponse: A closure which handles the response, the result of which is
  804. /// returned to the caller. Returning from the closure will cancel the RPC if it
  805. /// hasn't already finished.
  806. /// - Returns: The result of `handleResponse`.
  807. internal func update<Result>(
  808. request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
  809. options: GRPCCore.CallOptions = .defaults,
  810. onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
  811. ) async throws -> Result where Result: Sendable {
  812. try await self.update(
  813. request: request,
  814. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoRequest>(),
  815. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoResponse>(),
  816. options: options,
  817. onResponse: handleResponse
  818. )
  819. }
  820. }
  821. // Helpers providing sugared APIs for 'ClientProtocol' methods.
  822. extension Echo_Echo.ClientProtocol {
  823. /// Call the "Get" method.
  824. ///
  825. /// > Source IDL Documentation:
  826. /// >
  827. /// > Immediately returns an echo of a request.
  828. ///
  829. /// - Parameters:
  830. /// - message: request message to send.
  831. /// - metadata: Additional metadata to send, defaults to empty.
  832. /// - options: Options to apply to this RPC, defaults to `.defaults`.
  833. /// - handleResponse: A closure which handles the response, the result of which is
  834. /// returned to the caller. Returning from the closure will cancel the RPC if it
  835. /// hasn't already finished.
  836. /// - Returns: The result of `handleResponse`.
  837. internal func get<Result>(
  838. _ message: Echo_EchoRequest,
  839. metadata: GRPCCore.Metadata = [:],
  840. options: GRPCCore.CallOptions = .defaults,
  841. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = { response in
  842. try response.message
  843. }
  844. ) async throws -> Result where Result: Sendable {
  845. let request = GRPCCore.ClientRequest<Echo_EchoRequest>(
  846. message: message,
  847. metadata: metadata
  848. )
  849. return try await self.get(
  850. request: request,
  851. options: options,
  852. onResponse: handleResponse
  853. )
  854. }
  855. /// Call the "Expand" method.
  856. ///
  857. /// > Source IDL Documentation:
  858. /// >
  859. /// > Splits a request into words and returns each word in a stream of messages.
  860. ///
  861. /// - Parameters:
  862. /// - message: request message to send.
  863. /// - metadata: Additional metadata to send, defaults to empty.
  864. /// - options: Options to apply to this RPC, defaults to `.defaults`.
  865. /// - handleResponse: A closure which handles the response, the result of which is
  866. /// returned to the caller. Returning from the closure will cancel the RPC if it
  867. /// hasn't already finished.
  868. /// - Returns: The result of `handleResponse`.
  869. internal func expand<Result>(
  870. _ message: Echo_EchoRequest,
  871. metadata: GRPCCore.Metadata = [:],
  872. options: GRPCCore.CallOptions = .defaults,
  873. onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
  874. ) async throws -> Result where Result: Sendable {
  875. let request = GRPCCore.ClientRequest<Echo_EchoRequest>(
  876. message: message,
  877. metadata: metadata
  878. )
  879. return try await self.expand(
  880. request: request,
  881. options: options,
  882. onResponse: handleResponse
  883. )
  884. }
  885. /// Call the "Collect" method.
  886. ///
  887. /// > Source IDL Documentation:
  888. /// >
  889. /// > Collects a stream of messages and returns them concatenated when the caller closes.
  890. ///
  891. /// - Parameters:
  892. /// - metadata: Additional metadata to send, defaults to empty.
  893. /// - options: Options to apply to this RPC, defaults to `.defaults`.
  894. /// - producer: A closure producing request messages to send to the server. The request
  895. /// stream is closed when the closure returns.
  896. /// - handleResponse: A closure which handles the response, the result of which is
  897. /// returned to the caller. Returning from the closure will cancel the RPC if it
  898. /// hasn't already finished.
  899. /// - Returns: The result of `handleResponse`.
  900. internal func collect<Result>(
  901. metadata: GRPCCore.Metadata = [:],
  902. options: GRPCCore.CallOptions = .defaults,
  903. requestProducer producer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
  904. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = { response in
  905. try response.message
  906. }
  907. ) async throws -> Result where Result: Sendable {
  908. let request = GRPCCore.StreamingClientRequest<Echo_EchoRequest>(
  909. metadata: metadata,
  910. producer: producer
  911. )
  912. return try await self.collect(
  913. request: request,
  914. options: options,
  915. onResponse: handleResponse
  916. )
  917. }
  918. /// Call the "Update" method.
  919. ///
  920. /// > Source IDL Documentation:
  921. /// >
  922. /// > Streams back messages as they are received in an input stream.
  923. ///
  924. /// - Parameters:
  925. /// - metadata: Additional metadata to send, defaults to empty.
  926. /// - options: Options to apply to this RPC, defaults to `.defaults`.
  927. /// - producer: A closure producing request messages to send to the server. The request
  928. /// stream is closed when the closure returns.
  929. /// - handleResponse: A closure which handles the response, the result of which is
  930. /// returned to the caller. Returning from the closure will cancel the RPC if it
  931. /// hasn't already finished.
  932. /// - Returns: The result of `handleResponse`.
  933. internal func update<Result>(
  934. metadata: GRPCCore.Metadata = [:],
  935. options: GRPCCore.CallOptions = .defaults,
  936. requestProducer producer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
  937. onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
  938. ) async throws -> Result where Result: Sendable {
  939. let request = GRPCCore.StreamingClientRequest<Echo_EchoRequest>(
  940. metadata: metadata,
  941. producer: producer
  942. )
  943. return try await self.update(
  944. request: request,
  945. options: options,
  946. onResponse: handleResponse
  947. )
  948. }
  949. }