echo.grpc.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. 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. internal struct Echo_EchoClient: Echo_Echo.ClientProtocol {
  254. private let client: GRPCCore.GRPCClient
  255. internal init(wrapping client: GRPCCore.GRPCClient) {
  256. self.client = client
  257. }
  258. /// Immediately returns an echo of a request.
  259. internal func get<R>(
  260. request: ClientRequest.Single<Echo_EchoRequest>,
  261. serializer: some MessageSerializer<Echo_EchoRequest>,
  262. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  263. options: CallOptions = .defaults,
  264. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  265. try $0.message
  266. }
  267. ) async throws -> R where R: Sendable {
  268. try await self.client.unary(
  269. request: request,
  270. descriptor: Echo_Echo.Method.Get.descriptor,
  271. serializer: serializer,
  272. deserializer: deserializer,
  273. options: options,
  274. handler: body
  275. )
  276. }
  277. /// Splits a request into words and returns each word in a stream of messages.
  278. internal func expand<R>(
  279. request: ClientRequest.Single<Echo_EchoRequest>,
  280. serializer: some MessageSerializer<Echo_EchoRequest>,
  281. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  282. options: CallOptions = .defaults,
  283. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  284. ) async throws -> R where R: Sendable {
  285. try await self.client.serverStreaming(
  286. request: request,
  287. descriptor: Echo_Echo.Method.Expand.descriptor,
  288. serializer: serializer,
  289. deserializer: deserializer,
  290. options: options,
  291. handler: body
  292. )
  293. }
  294. /// Collects a stream of messages and returns them concatenated when the caller closes.
  295. internal func collect<R>(
  296. request: ClientRequest.Stream<Echo_EchoRequest>,
  297. serializer: some MessageSerializer<Echo_EchoRequest>,
  298. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  299. options: CallOptions = .defaults,
  300. _ body: @Sendable @escaping (ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
  301. try $0.message
  302. }
  303. ) async throws -> R where R: Sendable {
  304. try await self.client.clientStreaming(
  305. request: request,
  306. descriptor: Echo_Echo.Method.Collect.descriptor,
  307. serializer: serializer,
  308. deserializer: deserializer,
  309. options: options,
  310. handler: body
  311. )
  312. }
  313. /// Streams back messages as they are received in an input stream.
  314. internal func update<R>(
  315. request: ClientRequest.Stream<Echo_EchoRequest>,
  316. serializer: some MessageSerializer<Echo_EchoRequest>,
  317. deserializer: some MessageDeserializer<Echo_EchoResponse>,
  318. options: CallOptions = .defaults,
  319. _ body: @Sendable @escaping (ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
  320. ) async throws -> R where R: Sendable {
  321. try await self.client.bidirectionalStreaming(
  322. request: request,
  323. descriptor: Echo_Echo.Method.Update.descriptor,
  324. serializer: serializer,
  325. deserializer: deserializer,
  326. options: options,
  327. handler: body
  328. )
  329. }
  330. }