error-service.grpc.swift 14 KB

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