echo.grpc.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 = 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. ) async throws -> R where R: Sendable {
  200. try await self.get(
  201. request: request,
  202. serializer: ProtobufSerializer<Echo_EchoRequest>(),
  203. deserializer: ProtobufDeserializer<Echo_EchoResponse>(),
  204. options: options,
  205. body
  206. )
  207. }
  208. internal func expand<R>(
  209. request: ClientRequest.Single<Echo_EchoRequest>,
  210. options: CallOptions = .defaults,
  211. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  212. ) async throws -> R where R: Sendable {
  213. try await self.expand(
  214. request: request,
  215. serializer: ProtobufSerializer<Echo_EchoRequest>(),
  216. deserializer: ProtobufDeserializer<Echo_EchoResponse>(),
  217. options: options,
  218. body
  219. )
  220. }
  221. internal func collect<R>(
  222. request: ClientRequest.Stream<Echo_EchoRequest>,
  223. options: CallOptions = .defaults,
  224. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R
  225. ) async throws -> R where R: Sendable {
  226. try await self.collect(
  227. request: request,
  228. serializer: ProtobufSerializer<Echo_EchoRequest>(),
  229. deserializer: ProtobufDeserializer<Echo_EchoResponse>(),
  230. options: options,
  231. body
  232. )
  233. }
  234. internal func update<R>(
  235. request: ClientRequest.Stream<Echo_EchoRequest>,
  236. options: CallOptions = .defaults,
  237. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  238. ) async throws -> R where R: Sendable {
  239. try await self.update(
  240. request: request,
  241. serializer: ProtobufSerializer<Echo_EchoRequest>(),
  242. deserializer: ProtobufDeserializer<Echo_EchoResponse>(),
  243. options: options,
  244. body
  245. )
  246. }
  247. }
  248. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  249. internal struct Echo_EchoClient: Echo_Echo.ClientProtocol {
  250. private let client: GRPCCore.GRPCClient
  251. internal init(wrapping client: GRPCCore.GRPCClient) {
  252. self.client = client
  253. }
  254. /// Immediately returns an echo of a request.
  255. internal func get<R>(
  256. request: ClientRequest.Single<Echo_EchoRequest>,
  257. serializer: some MessageSerializer<Echo_EchoRequest>,
  258. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  259. options: CallOptions = .defaults,
  260. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R
  261. ) async throws -> R where R: Sendable {
  262. try await self.client.unary(
  263. request: request,
  264. descriptor: Echo_Echo.Method.Get.descriptor,
  265. serializer: serializer,
  266. deserializer: deserializer,
  267. options: options,
  268. handler: body
  269. )
  270. }
  271. /// Splits a request into words and returns each word in a stream of messages.
  272. internal func expand<R>(
  273. request: ClientRequest.Single<Echo_EchoRequest>,
  274. serializer: some MessageSerializer<Echo_EchoRequest>,
  275. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  276. options: CallOptions = .defaults,
  277. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  278. ) async throws -> R where R: Sendable {
  279. try await self.client.serverStreaming(
  280. request: request,
  281. descriptor: Echo_Echo.Method.Expand.descriptor,
  282. serializer: serializer,
  283. deserializer: deserializer,
  284. options: options,
  285. handler: body
  286. )
  287. }
  288. /// Collects a stream of messages and returns them concatenated when the caller closes.
  289. internal func collect<R>(
  290. request: ClientRequest.Stream<Echo_EchoRequest>,
  291. serializer: some MessageSerializer<Echo_EchoRequest>,
  292. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  293. options: CallOptions = .defaults,
  294. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R
  295. ) async throws -> R where R: Sendable {
  296. try await self.client.clientStreaming(
  297. request: request,
  298. descriptor: Echo_Echo.Method.Collect.descriptor,
  299. serializer: serializer,
  300. deserializer: deserializer,
  301. options: options,
  302. handler: body
  303. )
  304. }
  305. /// Streams back messages as they are received in an input stream.
  306. internal func update<R>(
  307. request: ClientRequest.Stream<Echo_EchoRequest>,
  308. serializer: some MessageSerializer<Echo_EchoRequest>,
  309. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  310. options: CallOptions = .defaults,
  311. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  312. ) async throws -> R where R: Sendable {
  313. try await self.client.bidirectionalStreaming(
  314. request: request,
  315. descriptor: Echo_Echo.Method.Update.descriptor,
  316. serializer: serializer,
  317. deserializer: deserializer,
  318. options: options,
  319. handler: body
  320. )
  321. }
  322. }