error-service.grpc.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. // swiftlint:disable all
  18. //
  19. // Generated by the gRPC Swift generator plugin for the protocol buffer compiler.
  20. // Source: error-service.proto
  21. //
  22. // For information on using the generated types, please see the documentation:
  23. // https://github.com/grpc/grpc-swift
  24. internal import GRPCCore
  25. internal import GRPCProtobuf
  26. internal import SwiftProtobuf
  27. // MARK: - ErrorService
  28. /// Namespace containing generated types for the "ErrorService" service.
  29. internal enum ErrorService {
  30. /// Service descriptor for the "ErrorService" service.
  31. internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "ErrorService")
  32. /// Namespace for method metadata.
  33. internal enum Method {
  34. /// Namespace for "ThrowError" metadata.
  35. internal enum ThrowError {
  36. /// Request type for "ThrowError".
  37. internal typealias Input = ThrowInput
  38. /// Response type for "ThrowError".
  39. internal typealias Output = SwiftProtobuf.Google_Protobuf_Empty
  40. /// Descriptor for "ThrowError".
  41. internal static let descriptor = GRPCCore.MethodDescriptor(
  42. service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "ErrorService"),
  43. method: "ThrowError"
  44. )
  45. }
  46. /// Descriptors for all methods in the "ErrorService" service.
  47. internal static let descriptors: [GRPCCore.MethodDescriptor] = [
  48. ThrowError.descriptor
  49. ]
  50. }
  51. }
  52. extension GRPCCore.ServiceDescriptor {
  53. /// Service descriptor for the "ErrorService" service.
  54. internal static let ErrorService = GRPCCore.ServiceDescriptor(fullyQualifiedService: "ErrorService")
  55. }
  56. // MARK: ErrorService (server)
  57. extension ErrorService {
  58. /// Streaming variant of the service protocol for the "ErrorService" service.
  59. ///
  60. /// This protocol is the lowest-level of the service protocols generated for this service
  61. /// giving you the most flexibility over the implementation of your service. This comes at
  62. /// the cost of more verbose and less strict APIs. Each RPC requires you to implement it in
  63. /// terms of a request stream and response stream. Where only a single request or response
  64. /// message is expected, you are responsible for enforcing this invariant is maintained.
  65. ///
  66. /// Where possible, prefer using the stricter, less-verbose ``ServiceProtocol``
  67. /// or ``SimpleServiceProtocol`` instead.
  68. internal protocol StreamingServiceProtocol: GRPCCore.RegistrableRPCService {
  69. /// Handle the "ThrowError" method.
  70. ///
  71. /// - Parameters:
  72. /// - request: A streaming request of `ThrowInput` messages.
  73. /// - context: Context providing information about the RPC.
  74. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  75. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  76. /// to an internal error.
  77. /// - Returns: A streaming response of `SwiftProtobuf.Google_Protobuf_Empty` messages.
  78. func throwError(
  79. request: GRPCCore.StreamingServerRequest<ThrowInput>,
  80. context: GRPCCore.ServerContext
  81. ) async throws -> GRPCCore.StreamingServerResponse<SwiftProtobuf.Google_Protobuf_Empty>
  82. }
  83. /// Service protocol for the "ErrorService" service.
  84. ///
  85. /// This protocol is higher level than ``StreamingServiceProtocol`` but lower level than
  86. /// the ``SimpleServiceProtocol``, it provides access to request and response metadata and
  87. /// trailing response metadata. If you don't need these then consider using
  88. /// the ``SimpleServiceProtocol``. If you need fine grained control over your RPCs then
  89. /// use ``StreamingServiceProtocol``.
  90. internal protocol ServiceProtocol: ErrorService.StreamingServiceProtocol {
  91. /// Handle the "ThrowError" method.
  92. ///
  93. /// - Parameters:
  94. /// - request: A request containing a single `ThrowInput` message.
  95. /// - context: Context providing information about the RPC.
  96. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  97. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  98. /// to an internal error.
  99. /// - Returns: A response containing a single `SwiftProtobuf.Google_Protobuf_Empty` message.
  100. func throwError(
  101. request: GRPCCore.ServerRequest<ThrowInput>,
  102. context: GRPCCore.ServerContext
  103. ) async throws -> GRPCCore.ServerResponse<SwiftProtobuf.Google_Protobuf_Empty>
  104. }
  105. /// Simple service protocol for the "ErrorService" service.
  106. ///
  107. /// This is the highest level protocol for the service. The API is the easiest to use but
  108. /// doesn't provide access to request or response metadata. If you need access to these
  109. /// then use ``ServiceProtocol`` instead.
  110. internal protocol SimpleServiceProtocol: ErrorService.ServiceProtocol {
  111. /// Handle the "ThrowError" method.
  112. ///
  113. /// - Parameters:
  114. /// - request: A `ThrowInput` message.
  115. /// - context: Context providing information about the RPC.
  116. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  117. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  118. /// to an internal error.
  119. /// - Returns: A `SwiftProtobuf.Google_Protobuf_Empty` to respond with.
  120. func throwError(
  121. request: ThrowInput,
  122. context: GRPCCore.ServerContext
  123. ) async throws -> SwiftProtobuf.Google_Protobuf_Empty
  124. }
  125. }
  126. // Default implementation of 'registerMethods(with:)'.
  127. extension ErrorService.StreamingServiceProtocol {
  128. internal func registerMethods<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
  129. router.registerHandler(
  130. forMethod: ErrorService.Method.ThrowError.descriptor,
  131. deserializer: GRPCProtobuf.ProtobufDeserializer<ThrowInput>(),
  132. serializer: GRPCProtobuf.ProtobufSerializer<SwiftProtobuf.Google_Protobuf_Empty>(),
  133. handler: { request, context in
  134. try await self.throwError(
  135. request: request,
  136. context: context
  137. )
  138. }
  139. )
  140. }
  141. }
  142. // Default implementation of streaming methods from 'StreamingServiceProtocol'.
  143. extension ErrorService.ServiceProtocol {
  144. internal func throwError(
  145. request: GRPCCore.StreamingServerRequest<ThrowInput>,
  146. context: GRPCCore.ServerContext
  147. ) async throws -> GRPCCore.StreamingServerResponse<SwiftProtobuf.Google_Protobuf_Empty> {
  148. let response = try await self.throwError(
  149. request: GRPCCore.ServerRequest(stream: request),
  150. context: context
  151. )
  152. return GRPCCore.StreamingServerResponse(single: response)
  153. }
  154. }
  155. // Default implementation of methods from 'ServiceProtocol'.
  156. extension ErrorService.SimpleServiceProtocol {
  157. internal func throwError(
  158. request: GRPCCore.ServerRequest<ThrowInput>,
  159. context: GRPCCore.ServerContext
  160. ) async throws -> GRPCCore.ServerResponse<SwiftProtobuf.Google_Protobuf_Empty> {
  161. return GRPCCore.ServerResponse<SwiftProtobuf.Google_Protobuf_Empty>(
  162. message: try await self.throwError(
  163. request: request.message,
  164. context: context
  165. ),
  166. metadata: [:]
  167. )
  168. }
  169. }
  170. // MARK: ErrorService (client)
  171. extension ErrorService {
  172. /// Generated client protocol for the "ErrorService" service.
  173. ///
  174. /// You don't need to implement this protocol directly, use the generated
  175. /// implementation, ``Client``.
  176. internal protocol ClientProtocol: Sendable {
  177. /// Call the "ThrowError" method.
  178. ///
  179. /// - Parameters:
  180. /// - request: A request containing a single `ThrowInput` message.
  181. /// - serializer: A serializer for `ThrowInput` messages.
  182. /// - deserializer: A deserializer for `SwiftProtobuf.Google_Protobuf_Empty` messages.
  183. /// - options: Options to apply to this RPC.
  184. /// - handleResponse: A closure which handles the response, the result of which is
  185. /// returned to the caller. Returning from the closure will cancel the RPC if it
  186. /// hasn't already finished.
  187. /// - Returns: The result of `handleResponse`.
  188. func throwError<Result>(
  189. request: GRPCCore.ClientRequest<ThrowInput>,
  190. serializer: some GRPCCore.MessageSerializer<ThrowInput>,
  191. deserializer: some GRPCCore.MessageDeserializer<SwiftProtobuf.Google_Protobuf_Empty>,
  192. options: GRPCCore.CallOptions,
  193. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<SwiftProtobuf.Google_Protobuf_Empty>) async throws -> Result
  194. ) async throws -> Result where Result: Sendable
  195. }
  196. /// Generated client for the "ErrorService" service.
  197. ///
  198. /// The ``Client`` provides an implementation of ``ClientProtocol`` which wraps
  199. /// a `GRPCCore.GRPCCClient`. The underlying `GRPCClient` provides the long-lived
  200. /// means of communication with the remote peer.
  201. internal struct Client<Transport>: ClientProtocol where Transport: GRPCCore.ClientTransport {
  202. private let client: GRPCCore.GRPCClient<Transport>
  203. /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`.
  204. ///
  205. /// - Parameters:
  206. /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service.
  207. internal init(wrapping client: GRPCCore.GRPCClient<Transport>) {
  208. self.client = client
  209. }
  210. /// Call the "ThrowError" method.
  211. ///
  212. /// - Parameters:
  213. /// - request: A request containing a single `ThrowInput` message.
  214. /// - serializer: A serializer for `ThrowInput` messages.
  215. /// - deserializer: A deserializer for `SwiftProtobuf.Google_Protobuf_Empty` messages.
  216. /// - options: Options to apply to this RPC.
  217. /// - handleResponse: A closure which handles the response, the result of which is
  218. /// returned to the caller. Returning from the closure will cancel the RPC if it
  219. /// hasn't already finished.
  220. /// - Returns: The result of `handleResponse`.
  221. internal func throwError<Result>(
  222. request: GRPCCore.ClientRequest<ThrowInput>,
  223. serializer: some GRPCCore.MessageSerializer<ThrowInput>,
  224. deserializer: some GRPCCore.MessageDeserializer<SwiftProtobuf.Google_Protobuf_Empty>,
  225. options: GRPCCore.CallOptions = .defaults,
  226. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<SwiftProtobuf.Google_Protobuf_Empty>) async throws -> Result = { response in
  227. try response.message
  228. }
  229. ) async throws -> Result where Result: Sendable {
  230. try await self.client.unary(
  231. request: request,
  232. descriptor: ErrorService.Method.ThrowError.descriptor,
  233. serializer: serializer,
  234. deserializer: deserializer,
  235. options: options,
  236. onResponse: handleResponse
  237. )
  238. }
  239. }
  240. }
  241. // Helpers providing default arguments to 'ClientProtocol' methods.
  242. extension ErrorService.ClientProtocol {
  243. /// Call the "ThrowError" method.
  244. ///
  245. /// - Parameters:
  246. /// - request: A request containing a single `ThrowInput` message.
  247. /// - options: Options to apply to this RPC.
  248. /// - handleResponse: A closure which handles the response, the result of which is
  249. /// returned to the caller. Returning from the closure will cancel the RPC if it
  250. /// hasn't already finished.
  251. /// - Returns: The result of `handleResponse`.
  252. internal func throwError<Result>(
  253. request: GRPCCore.ClientRequest<ThrowInput>,
  254. options: GRPCCore.CallOptions = .defaults,
  255. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<SwiftProtobuf.Google_Protobuf_Empty>) async throws -> Result = { response in
  256. try response.message
  257. }
  258. ) async throws -> Result where Result: Sendable {
  259. try await self.throwError(
  260. request: request,
  261. serializer: GRPCProtobuf.ProtobufSerializer<ThrowInput>(),
  262. deserializer: GRPCProtobuf.ProtobufDeserializer<SwiftProtobuf.Google_Protobuf_Empty>(),
  263. options: options,
  264. onResponse: handleResponse
  265. )
  266. }
  267. }
  268. // Helpers providing sugared APIs for 'ClientProtocol' methods.
  269. extension ErrorService.ClientProtocol {
  270. /// Call the "ThrowError" method.
  271. ///
  272. /// - Parameters:
  273. /// - message: request message to send.
  274. /// - metadata: Additional metadata to send, defaults to empty.
  275. /// - options: Options to apply to this RPC, defaults to `.defaults`.
  276. /// - handleResponse: A closure which handles the response, the result of which is
  277. /// returned to the caller. Returning from the closure will cancel the RPC if it
  278. /// hasn't already finished.
  279. /// - Returns: The result of `handleResponse`.
  280. internal func throwError<Result>(
  281. _ message: ThrowInput,
  282. metadata: GRPCCore.Metadata = [:],
  283. options: GRPCCore.CallOptions = .defaults,
  284. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<SwiftProtobuf.Google_Protobuf_Empty>) async throws -> Result = { response in
  285. try response.message
  286. }
  287. ) async throws -> Result where Result: Sendable {
  288. let request = GRPCCore.ClientRequest<ThrowInput>(
  289. message: message,
  290. metadata: metadata
  291. )
  292. return try await self.throwError(
  293. request: request,
  294. options: options,
  295. onResponse: handleResponse
  296. )
  297. }
  298. }