control.grpc.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. //
  2. // Copyright 2024, gRPC Authors All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // DO NOT EDIT.
  16. // swift-format-ignore-file
  17. //
  18. // Generated by the gRPC Swift generator plugin for the protocol buffer compiler.
  19. // Source: control.proto
  20. //
  21. // For information on using the generated types, please see the documentation:
  22. // https://github.com/grpc/grpc-swift
  23. import GRPCCore
  24. import GRPCProtobuf
  25. internal enum Control {
  26. internal static let descriptor = ServiceDescriptor.Control
  27. internal enum Method {
  28. internal enum Unary {
  29. internal typealias Input = ControlInput
  30. internal typealias Output = ControlOutput
  31. internal static let descriptor = MethodDescriptor(
  32. service: Control.descriptor.fullyQualifiedService,
  33. method: "Unary"
  34. )
  35. }
  36. internal enum ServerStream {
  37. internal typealias Input = ControlInput
  38. internal typealias Output = ControlOutput
  39. internal static let descriptor = MethodDescriptor(
  40. service: Control.descriptor.fullyQualifiedService,
  41. method: "ServerStream"
  42. )
  43. }
  44. internal enum ClientStream {
  45. internal typealias Input = ControlInput
  46. internal typealias Output = ControlOutput
  47. internal static let descriptor = MethodDescriptor(
  48. service: Control.descriptor.fullyQualifiedService,
  49. method: "ClientStream"
  50. )
  51. }
  52. internal enum BidiStream {
  53. internal typealias Input = ControlInput
  54. internal typealias Output = ControlOutput
  55. internal static let descriptor = MethodDescriptor(
  56. service: Control.descriptor.fullyQualifiedService,
  57. method: "BidiStream"
  58. )
  59. }
  60. internal static let descriptors: [MethodDescriptor] = [
  61. Unary.descriptor,
  62. ServerStream.descriptor,
  63. ClientStream.descriptor,
  64. BidiStream.descriptor
  65. ]
  66. }
  67. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  68. internal typealias StreamingServiceProtocol = ControlStreamingServiceProtocol
  69. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  70. internal typealias ServiceProtocol = ControlServiceProtocol
  71. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  72. internal typealias ClientProtocol = ControlClientProtocol
  73. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  74. internal typealias Client = ControlClient
  75. }
  76. extension ServiceDescriptor {
  77. internal static let Control = Self(
  78. package: "",
  79. service: "Control"
  80. )
  81. }
  82. /// A controllable service for testing.
  83. ///
  84. /// The control service has one RPC of each kind, the input to each RPC controls
  85. /// the output.
  86. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  87. internal protocol ControlStreamingServiceProtocol: GRPCCore.RegistrableRPCService {
  88. func unary(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
  89. func serverStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
  90. func clientStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
  91. func bidiStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
  92. }
  93. /// Conformance to `GRPCCore.RegistrableRPCService`.
  94. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  95. extension Control.StreamingServiceProtocol {
  96. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  97. internal func registerMethods(with router: inout GRPCCore.RPCRouter) {
  98. router.registerHandler(
  99. forMethod: Control.Method.Unary.descriptor,
  100. deserializer: ProtobufDeserializer<ControlInput>(),
  101. serializer: ProtobufSerializer<ControlOutput>(),
  102. handler: { request in
  103. try await self.unary(request: request)
  104. }
  105. )
  106. router.registerHandler(
  107. forMethod: Control.Method.ServerStream.descriptor,
  108. deserializer: ProtobufDeserializer<ControlInput>(),
  109. serializer: ProtobufSerializer<ControlOutput>(),
  110. handler: { request in
  111. try await self.serverStream(request: request)
  112. }
  113. )
  114. router.registerHandler(
  115. forMethod: Control.Method.ClientStream.descriptor,
  116. deserializer: ProtobufDeserializer<ControlInput>(),
  117. serializer: ProtobufSerializer<ControlOutput>(),
  118. handler: { request in
  119. try await self.clientStream(request: request)
  120. }
  121. )
  122. router.registerHandler(
  123. forMethod: Control.Method.BidiStream.descriptor,
  124. deserializer: ProtobufDeserializer<ControlInput>(),
  125. serializer: ProtobufSerializer<ControlOutput>(),
  126. handler: { request in
  127. try await self.bidiStream(request: request)
  128. }
  129. )
  130. }
  131. }
  132. /// A controllable service for testing.
  133. ///
  134. /// The control service has one RPC of each kind, the input to each RPC controls
  135. /// the output.
  136. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  137. internal protocol ControlServiceProtocol: Control.StreamingServiceProtocol {
  138. func unary(request: ServerRequest.Single<ControlInput>) async throws -> ServerResponse.Single<ControlOutput>
  139. func serverStream(request: ServerRequest.Single<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
  140. func clientStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Single<ControlOutput>
  141. func bidiStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
  142. }
  143. /// Partial conformance to `ControlStreamingServiceProtocol`.
  144. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  145. extension Control.ServiceProtocol {
  146. internal func unary(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput> {
  147. let response = try await self.unary(request: ServerRequest.Single(stream: request))
  148. return ServerResponse.Stream(single: response)
  149. }
  150. internal func serverStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput> {
  151. let response = try await self.serverStream(request: ServerRequest.Single(stream: request))
  152. return response
  153. }
  154. internal func clientStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput> {
  155. let response = try await self.clientStream(request: request)
  156. return ServerResponse.Stream(single: response)
  157. }
  158. }
  159. /// A controllable service for testing.
  160. ///
  161. /// The control service has one RPC of each kind, the input to each RPC controls
  162. /// the output.
  163. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  164. internal protocol ControlClientProtocol: Sendable {
  165. func unary<R>(
  166. request: ClientRequest.Single<ControlInput>,
  167. serializer: some MessageSerializer<ControlInput>,
  168. deserializer: some MessageDeserializer<ControlOutput>,
  169. options: CallOptions,
  170. _ body: @Sendable @escaping (ClientResponse.Single<ControlOutput>) async throws -> R
  171. ) async throws -> R where R: Sendable
  172. func serverStream<R>(
  173. request: ClientRequest.Single<ControlInput>,
  174. serializer: some MessageSerializer<ControlInput>,
  175. deserializer: some MessageDeserializer<ControlOutput>,
  176. options: CallOptions,
  177. _ body: @Sendable @escaping (ClientResponse.Stream<ControlOutput>) async throws -> R
  178. ) async throws -> R where R: Sendable
  179. func clientStream<R>(
  180. request: ClientRequest.Stream<ControlInput>,
  181. serializer: some MessageSerializer<ControlInput>,
  182. deserializer: some MessageDeserializer<ControlOutput>,
  183. options: CallOptions,
  184. _ body: @Sendable @escaping (ClientResponse.Single<ControlOutput>) async throws -> R
  185. ) async throws -> R where R: Sendable
  186. func bidiStream<R>(
  187. request: ClientRequest.Stream<ControlInput>,
  188. serializer: some MessageSerializer<ControlInput>,
  189. deserializer: some MessageDeserializer<ControlOutput>,
  190. options: CallOptions,
  191. _ body: @Sendable @escaping (ClientResponse.Stream<ControlOutput>) async throws -> R
  192. ) async throws -> R where R: Sendable
  193. }
  194. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  195. extension Control.ClientProtocol {
  196. internal func unary<R>(
  197. request: ClientRequest.Single<ControlInput>,
  198. options: CallOptions = .defaults,
  199. _ body: @Sendable @escaping (ClientResponse.Single<ControlOutput>) async throws -> R = {
  200. try $0.message
  201. }
  202. ) async throws -> R where R: Sendable {
  203. try await self.unary(
  204. request: request,
  205. serializer: ProtobufSerializer<ControlInput>(),
  206. deserializer: ProtobufDeserializer<ControlOutput>(),
  207. options: options,
  208. body
  209. )
  210. }
  211. internal func serverStream<R>(
  212. request: ClientRequest.Single<ControlInput>,
  213. options: CallOptions = .defaults,
  214. _ body: @Sendable @escaping (ClientResponse.Stream<ControlOutput>) async throws -> R
  215. ) async throws -> R where R: Sendable {
  216. try await self.serverStream(
  217. request: request,
  218. serializer: ProtobufSerializer<ControlInput>(),
  219. deserializer: ProtobufDeserializer<ControlOutput>(),
  220. options: options,
  221. body
  222. )
  223. }
  224. internal func clientStream<R>(
  225. request: ClientRequest.Stream<ControlInput>,
  226. options: CallOptions = .defaults,
  227. _ body: @Sendable @escaping (ClientResponse.Single<ControlOutput>) async throws -> R = {
  228. try $0.message
  229. }
  230. ) async throws -> R where R: Sendable {
  231. try await self.clientStream(
  232. request: request,
  233. serializer: ProtobufSerializer<ControlInput>(),
  234. deserializer: ProtobufDeserializer<ControlOutput>(),
  235. options: options,
  236. body
  237. )
  238. }
  239. internal func bidiStream<R>(
  240. request: ClientRequest.Stream<ControlInput>,
  241. options: CallOptions = .defaults,
  242. _ body: @Sendable @escaping (ClientResponse.Stream<ControlOutput>) async throws -> R
  243. ) async throws -> R where R: Sendable {
  244. try await self.bidiStream(
  245. request: request,
  246. serializer: ProtobufSerializer<ControlInput>(),
  247. deserializer: ProtobufDeserializer<ControlOutput>(),
  248. options: options,
  249. body
  250. )
  251. }
  252. }
  253. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  254. extension Control.ClientProtocol {
  255. internal func unary<Result>(
  256. _ message: ControlInput,
  257. metadata: GRPCCore.Metadata = [:],
  258. options: GRPCCore.CallOptions = .defaults,
  259. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<ControlOutput>) async throws -> Result = {
  260. try $0.message
  261. }
  262. ) async throws -> Result where Result: Sendable {
  263. let request = GRPCCore.ClientRequest.Single<ControlInput>(
  264. message: message,
  265. metadata: metadata
  266. )
  267. return try await self.unary(
  268. request: request,
  269. options: options,
  270. handleResponse
  271. )
  272. }
  273. internal func serverStream<Result>(
  274. _ message: ControlInput,
  275. metadata: GRPCCore.Metadata = [:],
  276. options: GRPCCore.CallOptions = .defaults,
  277. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<ControlOutput>) async throws -> Result
  278. ) async throws -> Result where Result: Sendable {
  279. let request = GRPCCore.ClientRequest.Single<ControlInput>(
  280. message: message,
  281. metadata: metadata
  282. )
  283. return try await self.serverStream(
  284. request: request,
  285. options: options,
  286. handleResponse
  287. )
  288. }
  289. internal func clientStream<Result>(
  290. metadata: GRPCCore.Metadata = [:],
  291. options: GRPCCore.CallOptions = .defaults,
  292. requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<ControlInput>) async throws -> Void,
  293. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<ControlOutput>) async throws -> Result = {
  294. try $0.message
  295. }
  296. ) async throws -> Result where Result: Sendable {
  297. let request = GRPCCore.ClientRequest.Stream<ControlInput>(
  298. metadata: metadata,
  299. producer: requestProducer
  300. )
  301. return try await self.clientStream(
  302. request: request,
  303. options: options,
  304. handleResponse
  305. )
  306. }
  307. internal func bidiStream<Result>(
  308. metadata: GRPCCore.Metadata = [:],
  309. options: GRPCCore.CallOptions = .defaults,
  310. requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<ControlInput>) async throws -> Void,
  311. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<ControlOutput>) async throws -> Result
  312. ) async throws -> Result where Result: Sendable {
  313. let request = GRPCCore.ClientRequest.Stream<ControlInput>(
  314. metadata: metadata,
  315. producer: requestProducer
  316. )
  317. return try await self.bidiStream(
  318. request: request,
  319. options: options,
  320. handleResponse
  321. )
  322. }
  323. }
  324. /// A controllable service for testing.
  325. ///
  326. /// The control service has one RPC of each kind, the input to each RPC controls
  327. /// the output.
  328. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  329. internal struct ControlClient: Control.ClientProtocol {
  330. private let client: GRPCCore.GRPCClient
  331. internal init(wrapping client: GRPCCore.GRPCClient) {
  332. self.client = client
  333. }
  334. internal func unary<R>(
  335. request: ClientRequest.Single<ControlInput>,
  336. serializer: some MessageSerializer<ControlInput>,
  337. deserializer: some MessageDeserializer<ControlOutput>,
  338. options: CallOptions = .defaults,
  339. _ body: @Sendable @escaping (ClientResponse.Single<ControlOutput>) 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: Control.Method.Unary.descriptor,
  346. serializer: serializer,
  347. deserializer: deserializer,
  348. options: options,
  349. handler: body
  350. )
  351. }
  352. internal func serverStream<R>(
  353. request: ClientRequest.Single<ControlInput>,
  354. serializer: some MessageSerializer<ControlInput>,
  355. deserializer: some MessageDeserializer<ControlOutput>,
  356. options: CallOptions = .defaults,
  357. _ body: @Sendable @escaping (ClientResponse.Stream<ControlOutput>) async throws -> R
  358. ) async throws -> R where R: Sendable {
  359. try await self.client.serverStreaming(
  360. request: request,
  361. descriptor: Control.Method.ServerStream.descriptor,
  362. serializer: serializer,
  363. deserializer: deserializer,
  364. options: options,
  365. handler: body
  366. )
  367. }
  368. internal func clientStream<R>(
  369. request: ClientRequest.Stream<ControlInput>,
  370. serializer: some MessageSerializer<ControlInput>,
  371. deserializer: some MessageDeserializer<ControlOutput>,
  372. options: CallOptions = .defaults,
  373. _ body: @Sendable @escaping (ClientResponse.Single<ControlOutput>) async throws -> R = {
  374. try $0.message
  375. }
  376. ) async throws -> R where R: Sendable {
  377. try await self.client.clientStreaming(
  378. request: request,
  379. descriptor: Control.Method.ClientStream.descriptor,
  380. serializer: serializer,
  381. deserializer: deserializer,
  382. options: options,
  383. handler: body
  384. )
  385. }
  386. internal func bidiStream<R>(
  387. request: ClientRequest.Stream<ControlInput>,
  388. serializer: some MessageSerializer<ControlInput>,
  389. deserializer: some MessageDeserializer<ControlOutput>,
  390. options: CallOptions = .defaults,
  391. _ body: @Sendable @escaping (ClientResponse.Stream<ControlOutput>) async throws -> R
  392. ) async throws -> R where R: Sendable {
  393. try await self.client.bidirectionalStreaming(
  394. request: request,
  395. descriptor: Control.Method.BidiStream.descriptor,
  396. serializer: serializer,
  397. deserializer: deserializer,
  398. options: options,
  399. handler: body
  400. )
  401. }
  402. }