echo.grpc.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. internal enum Echo_Echo {
  25. internal static let descriptor = GRPCCore.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 = GRPCCore.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 = GRPCCore.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 = GRPCCore.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 = GRPCCore.MethodDescriptor(
  55. service: Echo_Echo.descriptor.fullyQualifiedService,
  56. method: "Update"
  57. )
  58. }
  59. internal static let descriptors: [GRPCCore.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 GRPCCore.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(
  85. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  86. context: GRPCCore.ServerContext
  87. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
  88. /// Splits a request into words and returns each word in a stream of messages.
  89. func expand(
  90. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  91. context: GRPCCore.ServerContext
  92. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
  93. /// Collects a stream of messages and returns them concatenated when the caller closes.
  94. func collect(
  95. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  96. context: GRPCCore.ServerContext
  97. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
  98. /// Streams back messages as they are received in an input stream.
  99. func update(
  100. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  101. context: GRPCCore.ServerContext
  102. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
  103. }
  104. /// Conformance to `GRPCCore.RegistrableRPCService`.
  105. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  106. extension Echo_Echo.StreamingServiceProtocol {
  107. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  108. internal func registerMethods(with router: inout GRPCCore.RPCRouter) {
  109. router.registerHandler(
  110. forMethod: Echo_Echo.Method.Get.descriptor,
  111. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
  112. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoResponse>(),
  113. handler: { request, context in
  114. try await self.get(
  115. request: request,
  116. context: context
  117. )
  118. }
  119. )
  120. router.registerHandler(
  121. forMethod: Echo_Echo.Method.Expand.descriptor,
  122. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
  123. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoResponse>(),
  124. handler: { request, context in
  125. try await self.expand(
  126. request: request,
  127. context: context
  128. )
  129. }
  130. )
  131. router.registerHandler(
  132. forMethod: Echo_Echo.Method.Collect.descriptor,
  133. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
  134. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoResponse>(),
  135. handler: { request, context in
  136. try await self.collect(
  137. request: request,
  138. context: context
  139. )
  140. }
  141. )
  142. router.registerHandler(
  143. forMethod: Echo_Echo.Method.Update.descriptor,
  144. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
  145. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoResponse>(),
  146. handler: { request, context in
  147. try await self.update(
  148. request: request,
  149. context: context
  150. )
  151. }
  152. )
  153. }
  154. }
  155. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  156. internal protocol Echo_EchoServiceProtocol: Echo_Echo.StreamingServiceProtocol {
  157. /// Immediately returns an echo of a request.
  158. func get(
  159. request: GRPCCore.ServerRequest.Single<Echo_EchoRequest>,
  160. context: GRPCCore.ServerContext
  161. ) async throws -> GRPCCore.ServerResponse.Single<Echo_EchoResponse>
  162. /// Splits a request into words and returns each word in a stream of messages.
  163. func expand(
  164. request: GRPCCore.ServerRequest.Single<Echo_EchoRequest>,
  165. context: GRPCCore.ServerContext
  166. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
  167. /// Collects a stream of messages and returns them concatenated when the caller closes.
  168. func collect(
  169. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  170. context: GRPCCore.ServerContext
  171. ) async throws -> GRPCCore.ServerResponse.Single<Echo_EchoResponse>
  172. /// Streams back messages as they are received in an input stream.
  173. func update(
  174. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  175. context: GRPCCore.ServerContext
  176. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
  177. }
  178. /// Partial conformance to `Echo_EchoStreamingServiceProtocol`.
  179. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  180. extension Echo_Echo.ServiceProtocol {
  181. internal func get(
  182. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  183. context: GRPCCore.ServerContext
  184. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
  185. let response = try await self.get(
  186. request: GRPCCore.ServerRequest.Single(stream: request),
  187. context: context
  188. )
  189. return GRPCCore.ServerResponse.Stream(single: response)
  190. }
  191. internal func expand(
  192. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  193. context: GRPCCore.ServerContext
  194. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
  195. let response = try await self.expand(
  196. request: GRPCCore.ServerRequest.Single(stream: request),
  197. context: context
  198. )
  199. return response
  200. }
  201. internal func collect(
  202. request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
  203. context: GRPCCore.ServerContext
  204. ) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
  205. let response = try await self.collect(
  206. request: request,
  207. context: context
  208. )
  209. return GRPCCore.ServerResponse.Stream(single: response)
  210. }
  211. }
  212. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  213. internal protocol Echo_EchoClientProtocol: Sendable {
  214. /// Immediately returns an echo of a request.
  215. func get<R>(
  216. request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
  217. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  218. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  219. options: GRPCCore.CallOptions,
  220. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R
  221. ) async throws -> R where R: Sendable
  222. /// Splits a request into words and returns each word in a stream of messages.
  223. func expand<R>(
  224. request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
  225. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  226. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  227. options: GRPCCore.CallOptions,
  228. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  229. ) async throws -> R where R: Sendable
  230. /// Collects a stream of messages and returns them concatenated when the caller closes.
  231. func collect<R>(
  232. request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
  233. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  234. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  235. options: GRPCCore.CallOptions,
  236. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R
  237. ) async throws -> R where R: Sendable
  238. /// Streams back messages as they are received in an input stream.
  239. func update<R>(
  240. request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
  241. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  242. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  243. options: GRPCCore.CallOptions,
  244. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  245. ) async throws -> R where R: Sendable
  246. }
  247. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  248. extension Echo_Echo.ClientProtocol {
  249. internal func get<R>(
  250. request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
  251. options: GRPCCore.CallOptions = .defaults,
  252. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  253. try $0.message
  254. }
  255. ) async throws -> R where R: Sendable {
  256. try await self.get(
  257. request: request,
  258. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoRequest>(),
  259. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoResponse>(),
  260. options: options,
  261. body
  262. )
  263. }
  264. internal func expand<R>(
  265. request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
  266. options: GRPCCore.CallOptions = .defaults,
  267. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  268. ) async throws -> R where R: Sendable {
  269. try await self.expand(
  270. request: request,
  271. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoRequest>(),
  272. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoResponse>(),
  273. options: options,
  274. body
  275. )
  276. }
  277. internal func collect<R>(
  278. request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
  279. options: GRPCCore.CallOptions = .defaults,
  280. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  281. try $0.message
  282. }
  283. ) async throws -> R where R: Sendable {
  284. try await self.collect(
  285. request: request,
  286. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoRequest>(),
  287. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoResponse>(),
  288. options: options,
  289. body
  290. )
  291. }
  292. internal func update<R>(
  293. request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
  294. options: GRPCCore.CallOptions = .defaults,
  295. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  296. ) async throws -> R where R: Sendable {
  297. try await self.update(
  298. request: request,
  299. serializer: GRPCProtobuf.ProtobufSerializer<Echo_EchoRequest>(),
  300. deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoResponse>(),
  301. options: options,
  302. body
  303. )
  304. }
  305. }
  306. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  307. extension Echo_Echo.ClientProtocol {
  308. /// Immediately returns an echo of a request.
  309. internal func get<Result>(
  310. _ message: Echo_EchoRequest,
  311. metadata: GRPCCore.Metadata = [:],
  312. options: GRPCCore.CallOptions = .defaults,
  313. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> Result = {
  314. try $0.message
  315. }
  316. ) async throws -> Result where Result: Sendable {
  317. let request = GRPCCore.ClientRequest.Single<Echo_EchoRequest>(
  318. message: message,
  319. metadata: metadata
  320. )
  321. return try await self.get(
  322. request: request,
  323. options: options,
  324. handleResponse
  325. )
  326. }
  327. /// Splits a request into words and returns each word in a stream of messages.
  328. internal func expand<Result>(
  329. _ message: Echo_EchoRequest,
  330. metadata: GRPCCore.Metadata = [:],
  331. options: GRPCCore.CallOptions = .defaults,
  332. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> Result
  333. ) async throws -> Result where Result: Sendable {
  334. let request = GRPCCore.ClientRequest.Single<Echo_EchoRequest>(
  335. message: message,
  336. metadata: metadata
  337. )
  338. return try await self.expand(
  339. request: request,
  340. options: options,
  341. handleResponse
  342. )
  343. }
  344. /// Collects a stream of messages and returns them concatenated when the caller closes.
  345. internal func collect<Result>(
  346. metadata: GRPCCore.Metadata = [:],
  347. options: GRPCCore.CallOptions = .defaults,
  348. requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
  349. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> Result = {
  350. try $0.message
  351. }
  352. ) async throws -> Result where Result: Sendable {
  353. let request = GRPCCore.ClientRequest.Stream<Echo_EchoRequest>(
  354. metadata: metadata,
  355. producer: requestProducer
  356. )
  357. return try await self.collect(
  358. request: request,
  359. options: options,
  360. handleResponse
  361. )
  362. }
  363. /// Streams back messages as they are received in an input stream.
  364. internal func update<Result>(
  365. metadata: GRPCCore.Metadata = [:],
  366. options: GRPCCore.CallOptions = .defaults,
  367. requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
  368. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> Result
  369. ) async throws -> Result where Result: Sendable {
  370. let request = GRPCCore.ClientRequest.Stream<Echo_EchoRequest>(
  371. metadata: metadata,
  372. producer: requestProducer
  373. )
  374. return try await self.update(
  375. request: request,
  376. options: options,
  377. handleResponse
  378. )
  379. }
  380. }
  381. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  382. internal struct Echo_EchoClient: Echo_Echo.ClientProtocol {
  383. private let client: GRPCCore.GRPCClient
  384. internal init(wrapping client: GRPCCore.GRPCClient) {
  385. self.client = client
  386. }
  387. /// Immediately returns an echo of a request.
  388. internal func get<R>(
  389. request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
  390. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  391. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  392. options: GRPCCore.CallOptions = .defaults,
  393. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  394. try $0.message
  395. }
  396. ) async throws -> R where R: Sendable {
  397. try await self.client.unary(
  398. request: request,
  399. descriptor: Echo_Echo.Method.Get.descriptor,
  400. serializer: serializer,
  401. deserializer: deserializer,
  402. options: options,
  403. handler: body
  404. )
  405. }
  406. /// Splits a request into words and returns each word in a stream of messages.
  407. internal func expand<R>(
  408. request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
  409. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  410. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  411. options: GRPCCore.CallOptions = .defaults,
  412. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  413. ) async throws -> R where R: Sendable {
  414. try await self.client.serverStreaming(
  415. request: request,
  416. descriptor: Echo_Echo.Method.Expand.descriptor,
  417. serializer: serializer,
  418. deserializer: deserializer,
  419. options: options,
  420. handler: body
  421. )
  422. }
  423. /// Collects a stream of messages and returns them concatenated when the caller closes.
  424. internal func collect<R>(
  425. request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
  426. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  427. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  428. options: GRPCCore.CallOptions = .defaults,
  429. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  430. try $0.message
  431. }
  432. ) async throws -> R where R: Sendable {
  433. try await self.client.clientStreaming(
  434. request: request,
  435. descriptor: Echo_Echo.Method.Collect.descriptor,
  436. serializer: serializer,
  437. deserializer: deserializer,
  438. options: options,
  439. handler: body
  440. )
  441. }
  442. /// Streams back messages as they are received in an input stream.
  443. internal func update<R>(
  444. request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
  445. serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
  446. deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
  447. options: GRPCCore.CallOptions = .defaults,
  448. _ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  449. ) async throws -> R where R: Sendable {
  450. try await self.client.bidirectionalStreaming(
  451. request: request,
  452. descriptor: Echo_Echo.Method.Update.descriptor,
  453. serializer: serializer,
  454. deserializer: deserializer,
  455. options: options,
  456. handler: body
  457. )
  458. }
  459. }