echo.grpc.swift 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. internal import GRPCCore
  23. internal import GRPCProtobuf
  24. internal enum Echo_Echo {
  25. internal static let descriptor = ServiceDescriptor.echo_Echo
  26. internal enum Method {
  27. internal enum Get {
  28. internal typealias Input = Echo_EchoRequest
  29. internal typealias Output = Echo_EchoResponse
  30. internal static let descriptor = MethodDescriptor(
  31. service: Echo_Echo.descriptor.fullyQualifiedService,
  32. method: "Get"
  33. )
  34. }
  35. internal enum Expand {
  36. internal typealias Input = Echo_EchoRequest
  37. internal typealias Output = Echo_EchoResponse
  38. internal static let descriptor = MethodDescriptor(
  39. service: Echo_Echo.descriptor.fullyQualifiedService,
  40. method: "Expand"
  41. )
  42. }
  43. internal enum Collect {
  44. internal typealias Input = Echo_EchoRequest
  45. internal typealias Output = Echo_EchoResponse
  46. internal static let descriptor = MethodDescriptor(
  47. service: Echo_Echo.descriptor.fullyQualifiedService,
  48. method: "Collect"
  49. )
  50. }
  51. internal enum Update {
  52. internal typealias Input = Echo_EchoRequest
  53. internal typealias Output = Echo_EchoResponse
  54. internal static let descriptor = MethodDescriptor(
  55. service: Echo_Echo.descriptor.fullyQualifiedService,
  56. method: "Update"
  57. )
  58. }
  59. internal static let descriptors: [MethodDescriptor] = [
  60. Get.descriptor,
  61. Expand.descriptor,
  62. Collect.descriptor,
  63. Update.descriptor
  64. ]
  65. }
  66. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  67. internal typealias StreamingServiceProtocol = Echo_EchoStreamingServiceProtocol
  68. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  69. internal typealias ServiceProtocol = Echo_EchoServiceProtocol
  70. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  71. internal typealias ClientProtocol = Echo_EchoClientProtocol
  72. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  73. internal typealias Client = Echo_EchoClient
  74. }
  75. extension ServiceDescriptor {
  76. internal static let echo_Echo = Self(
  77. package: "echo",
  78. service: "Echo"
  79. )
  80. }
  81. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  82. internal protocol Echo_EchoStreamingServiceProtocol: GRPCCore.RegistrableRPCService {
  83. /// Immediately returns an echo of a request.
  84. func get(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse>
  85. /// Splits a request into words and returns each word in a stream of messages.
  86. func expand(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse>
  87. /// Collects a stream of messages and returns them concatenated when the caller closes.
  88. func collect(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse>
  89. /// Streams back messages as they are received in an input stream.
  90. func update(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse>
  91. }
  92. /// Conformance to `GRPCCore.RegistrableRPCService`.
  93. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  94. extension Echo_Echo.StreamingServiceProtocol {
  95. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  96. internal func registerMethods(with router: inout GRPCCore.RPCRouter) {
  97. router.registerHandler(
  98. forMethod: Echo_Echo.Method.Get.descriptor,
  99. deserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  100. serializer: ProtobufSerializer<Echo_EchoResponse>(),
  101. handler: { request in
  102. try await self.get(request: request)
  103. }
  104. )
  105. router.registerHandler(
  106. forMethod: Echo_Echo.Method.Expand.descriptor,
  107. deserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  108. serializer: ProtobufSerializer<Echo_EchoResponse>(),
  109. handler: { request in
  110. try await self.expand(request: request)
  111. }
  112. )
  113. router.registerHandler(
  114. forMethod: Echo_Echo.Method.Collect.descriptor,
  115. deserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  116. serializer: ProtobufSerializer<Echo_EchoResponse>(),
  117. handler: { request in
  118. try await self.collect(request: request)
  119. }
  120. )
  121. router.registerHandler(
  122. forMethod: Echo_Echo.Method.Update.descriptor,
  123. deserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  124. serializer: ProtobufSerializer<Echo_EchoResponse>(),
  125. handler: { request in
  126. try await self.update(request: request)
  127. }
  128. )
  129. }
  130. }
  131. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  132. internal protocol Echo_EchoServiceProtocol: Echo_Echo.StreamingServiceProtocol {
  133. /// Immediately returns an echo of a request.
  134. func get(request: ServerRequest.Single<Echo_EchoRequest>) async throws -> ServerResponse.Single<Echo_EchoResponse>
  135. /// Splits a request into words and returns each word in a stream of messages.
  136. func expand(request: ServerRequest.Single<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse>
  137. /// Collects a stream of messages and returns them concatenated when the caller closes.
  138. func collect(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Single<Echo_EchoResponse>
  139. /// Streams back messages as they are received in an input stream.
  140. func update(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse>
  141. }
  142. /// Partial conformance to `Echo_EchoStreamingServiceProtocol`.
  143. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  144. extension Echo_Echo.ServiceProtocol {
  145. internal func get(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse> {
  146. let response = try await self.get(request: ServerRequest.Single(stream: request))
  147. return ServerResponse.Stream(single: response)
  148. }
  149. internal func expand(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse> {
  150. let response = try await self.expand(request: ServerRequest.Single(stream: request))
  151. return response
  152. }
  153. internal func collect(request: ServerRequest.Stream<Echo_EchoRequest>) async throws -> ServerResponse.Stream<Echo_EchoResponse> {
  154. let response = try await self.collect(request: request)
  155. return ServerResponse.Stream(single: response)
  156. }
  157. }
  158. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  159. internal protocol Echo_EchoClientProtocol: Sendable {
  160. /// Immediately returns an echo of a request.
  161. func get<R>(
  162. request: ClientRequest.Single<Echo_EchoRequest>,
  163. serializer: some MessageSerializer<Echo_EchoRequest>,
  164. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  165. options: CallOptions,
  166. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R
  167. ) async throws -> R where R: Sendable
  168. /// Splits a request into words and returns each word in a stream of messages.
  169. func expand<R>(
  170. request: ClientRequest.Single<Echo_EchoRequest>,
  171. serializer: some MessageSerializer<Echo_EchoRequest>,
  172. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  173. options: CallOptions,
  174. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  175. ) async throws -> R where R: Sendable
  176. /// Collects a stream of messages and returns them concatenated when the caller closes.
  177. func collect<R>(
  178. request: ClientRequest.Stream<Echo_EchoRequest>,
  179. serializer: some MessageSerializer<Echo_EchoRequest>,
  180. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  181. options: CallOptions,
  182. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R
  183. ) async throws -> R where R: Sendable
  184. /// Streams back messages as they are received in an input stream.
  185. func update<R>(
  186. request: ClientRequest.Stream<Echo_EchoRequest>,
  187. serializer: some MessageSerializer<Echo_EchoRequest>,
  188. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  189. options: CallOptions,
  190. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  191. ) async throws -> R where R: Sendable
  192. }
  193. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  194. extension Echo_Echo.ClientProtocol {
  195. internal func get<R>(
  196. request: ClientRequest.Single<Echo_EchoRequest>,
  197. options: CallOptions = .defaults,
  198. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  199. try $0.message
  200. }
  201. ) async throws -> R where R: Sendable {
  202. try await self.get(
  203. request: request,
  204. serializer: ProtobufSerializer<Echo_EchoRequest>(),
  205. deserializer: ProtobufDeserializer<Echo_EchoResponse>(),
  206. options: options,
  207. body
  208. )
  209. }
  210. internal func expand<R>(
  211. request: ClientRequest.Single<Echo_EchoRequest>,
  212. options: CallOptions = .defaults,
  213. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  214. ) async throws -> R where R: Sendable {
  215. try await self.expand(
  216. request: request,
  217. serializer: ProtobufSerializer<Echo_EchoRequest>(),
  218. deserializer: ProtobufDeserializer<Echo_EchoResponse>(),
  219. options: options,
  220. body
  221. )
  222. }
  223. internal func collect<R>(
  224. request: ClientRequest.Stream<Echo_EchoRequest>,
  225. options: CallOptions = .defaults,
  226. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  227. try $0.message
  228. }
  229. ) async throws -> R where R: Sendable {
  230. try await self.collect(
  231. request: request,
  232. serializer: ProtobufSerializer<Echo_EchoRequest>(),
  233. deserializer: ProtobufDeserializer<Echo_EchoResponse>(),
  234. options: options,
  235. body
  236. )
  237. }
  238. internal func update<R>(
  239. request: ClientRequest.Stream<Echo_EchoRequest>,
  240. options: CallOptions = .defaults,
  241. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  242. ) async throws -> R where R: Sendable {
  243. try await self.update(
  244. request: request,
  245. serializer: ProtobufSerializer<Echo_EchoRequest>(),
  246. deserializer: ProtobufDeserializer<Echo_EchoResponse>(),
  247. options: options,
  248. body
  249. )
  250. }
  251. }
  252. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  253. extension Echo_Echo.ClientProtocol {
  254. /// Immediately returns an echo of a request.
  255. internal func get<Result>(
  256. _ message: Echo_EchoRequest,
  257. metadata: GRPCCore.Metadata = [:],
  258. options: GRPCCore.CallOptions = .defaults,
  259. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> Result = {
  260. try $0.message
  261. }
  262. ) async throws -> Result where Result: Sendable {
  263. let request = GRPCCore.ClientRequest.Single<Echo_EchoRequest>(
  264. message: message,
  265. metadata: metadata
  266. )
  267. return try await self.get(
  268. request: request,
  269. options: options,
  270. handleResponse
  271. )
  272. }
  273. /// Splits a request into words and returns each word in a stream of messages.
  274. internal func expand<Result>(
  275. _ message: Echo_EchoRequest,
  276. metadata: GRPCCore.Metadata = [:],
  277. options: GRPCCore.CallOptions = .defaults,
  278. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> Result
  279. ) async throws -> Result where Result: Sendable {
  280. let request = GRPCCore.ClientRequest.Single<Echo_EchoRequest>(
  281. message: message,
  282. metadata: metadata
  283. )
  284. return try await self.expand(
  285. request: request,
  286. options: options,
  287. handleResponse
  288. )
  289. }
  290. /// Collects a stream of messages and returns them concatenated when the caller closes.
  291. internal func collect<Result>(
  292. metadata: GRPCCore.Metadata = [:],
  293. options: GRPCCore.CallOptions = .defaults,
  294. requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
  295. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> Result = {
  296. try $0.message
  297. }
  298. ) async throws -> Result where Result: Sendable {
  299. let request = GRPCCore.ClientRequest.Stream<Echo_EchoRequest>(
  300. metadata: metadata,
  301. producer: requestProducer
  302. )
  303. return try await self.collect(
  304. request: request,
  305. options: options,
  306. handleResponse
  307. )
  308. }
  309. /// Streams back messages as they are received in an input stream.
  310. internal func update<Result>(
  311. metadata: GRPCCore.Metadata = [:],
  312. options: GRPCCore.CallOptions = .defaults,
  313. requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
  314. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> Result
  315. ) async throws -> Result where Result: Sendable {
  316. let request = GRPCCore.ClientRequest.Stream<Echo_EchoRequest>(
  317. metadata: metadata,
  318. producer: requestProducer
  319. )
  320. return try await self.update(
  321. request: request,
  322. options: options,
  323. handleResponse
  324. )
  325. }
  326. }
  327. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  328. internal struct Echo_EchoClient: Echo_Echo.ClientProtocol {
  329. private let client: GRPCCore.GRPCClient
  330. internal init(wrapping client: GRPCCore.GRPCClient) {
  331. self.client = client
  332. }
  333. /// Immediately returns an echo of a request.
  334. internal func get<R>(
  335. request: ClientRequest.Single<Echo_EchoRequest>,
  336. serializer: some MessageSerializer<Echo_EchoRequest>,
  337. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  338. options: CallOptions = .defaults,
  339. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  340. try $0.message
  341. }
  342. ) async throws -> R where R: Sendable {
  343. try await self.client.unary(
  344. request: request,
  345. descriptor: Echo_Echo.Method.Get.descriptor,
  346. serializer: serializer,
  347. deserializer: deserializer,
  348. options: options,
  349. handler: body
  350. )
  351. }
  352. /// Splits a request into words and returns each word in a stream of messages.
  353. internal func expand<R>(
  354. request: ClientRequest.Single<Echo_EchoRequest>,
  355. serializer: some MessageSerializer<Echo_EchoRequest>,
  356. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  357. options: CallOptions = .defaults,
  358. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  359. ) async throws -> R where R: Sendable {
  360. try await self.client.serverStreaming(
  361. request: request,
  362. descriptor: Echo_Echo.Method.Expand.descriptor,
  363. serializer: serializer,
  364. deserializer: deserializer,
  365. options: options,
  366. handler: body
  367. )
  368. }
  369. /// Collects a stream of messages and returns them concatenated when the caller closes.
  370. internal func collect<R>(
  371. request: ClientRequest.Stream<Echo_EchoRequest>,
  372. serializer: some MessageSerializer<Echo_EchoRequest>,
  373. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  374. options: CallOptions = .defaults,
  375. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  376. try $0.message
  377. }
  378. ) async throws -> R where R: Sendable {
  379. try await self.client.clientStreaming(
  380. request: request,
  381. descriptor: Echo_Echo.Method.Collect.descriptor,
  382. serializer: serializer,
  383. deserializer: deserializer,
  384. options: options,
  385. handler: body
  386. )
  387. }
  388. /// Streams back messages as they are received in an input stream.
  389. internal func update<R>(
  390. request: ClientRequest.Stream<Echo_EchoRequest>,
  391. serializer: some MessageSerializer<Echo_EchoRequest>,
  392. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  393. options: CallOptions = .defaults,
  394. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  395. ) async throws -> R where R: Sendable {
  396. try await self.client.bidirectionalStreaming(
  397. request: request,
  398. descriptor: Echo_Echo.Method.Update.descriptor,
  399. serializer: serializer,
  400. deserializer: deserializer,
  401. options: options,
  402. handler: body
  403. )
  404. }
  405. }