// // Copyright 2024, gRPC Authors All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all // // Generated by the gRPC Swift generator plugin for the protocol buffer compiler. // Source: error-service.proto // // For information on using the generated types, please see the documentation: // https://github.com/grpc/grpc-swift internal import GRPCCore internal import GRPCProtobuf internal import SwiftProtobuf // MARK: - ErrorService /// Namespace containing generated types for the "ErrorService" service. internal enum ErrorService { /// Service descriptor for the "ErrorService" service. internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "ErrorService") /// Namespace for method metadata. internal enum Method { /// Namespace for "ThrowError" metadata. internal enum ThrowError { /// Request type for "ThrowError". internal typealias Input = ThrowInput /// Response type for "ThrowError". internal typealias Output = SwiftProtobuf.Google_Protobuf_Empty /// Descriptor for "ThrowError". internal static let descriptor = GRPCCore.MethodDescriptor( service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "ErrorService"), method: "ThrowError" ) } /// Descriptors for all methods in the "ErrorService" service. internal static let descriptors: [GRPCCore.MethodDescriptor] = [ ThrowError.descriptor ] } } extension GRPCCore.ServiceDescriptor { /// Service descriptor for the "ErrorService" service. internal static let ErrorService = GRPCCore.ServiceDescriptor(fullyQualifiedService: "ErrorService") } // MARK: ErrorService (server) extension ErrorService { /// Streaming variant of the service protocol for the "ErrorService" service. /// /// This protocol is the lowest-level of the service protocols generated for this service /// giving you the most flexibility over the implementation of your service. This comes at /// the cost of more verbose and less strict APIs. Each RPC requires you to implement it in /// terms of a request stream and response stream. Where only a single request or response /// message is expected, you are responsible for enforcing this invariant is maintained. /// /// Where possible, prefer using the stricter, less-verbose ``ServiceProtocol`` /// or ``SimpleServiceProtocol`` instead. internal protocol StreamingServiceProtocol: GRPCCore.RegistrableRPCService { /// Handle the "ThrowError" method. /// /// - Parameters: /// - request: A streaming request of `ThrowInput` messages. /// - context: Context providing information about the RPC. /// - Throws: Any error which occurred during the processing of the request. Thrown errors /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted /// to an internal error. /// - Returns: A streaming response of `SwiftProtobuf.Google_Protobuf_Empty` messages. func throwError( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse } /// Service protocol for the "ErrorService" service. /// /// This protocol is higher level than ``StreamingServiceProtocol`` but lower level than /// the ``SimpleServiceProtocol``, it provides access to request and response metadata and /// trailing response metadata. If you don't need these then consider using /// the ``SimpleServiceProtocol``. If you need fine grained control over your RPCs then /// use ``StreamingServiceProtocol``. internal protocol ServiceProtocol: ErrorService.StreamingServiceProtocol { /// Handle the "ThrowError" method. /// /// - Parameters: /// - request: A request containing a single `ThrowInput` message. /// - context: Context providing information about the RPC. /// - Throws: Any error which occurred during the processing of the request. Thrown errors /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted /// to an internal error. /// - Returns: A response containing a single `SwiftProtobuf.Google_Protobuf_Empty` message. func throwError( request: GRPCCore.ServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.ServerResponse } /// Simple service protocol for the "ErrorService" service. /// /// This is the highest level protocol for the service. The API is the easiest to use but /// doesn't provide access to request or response metadata. If you need access to these /// then use ``ServiceProtocol`` instead. internal protocol SimpleServiceProtocol: ErrorService.ServiceProtocol { /// Handle the "ThrowError" method. /// /// - Parameters: /// - request: A `ThrowInput` message. /// - context: Context providing information about the RPC. /// - Throws: Any error which occurred during the processing of the request. Thrown errors /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted /// to an internal error. /// - Returns: A `SwiftProtobuf.Google_Protobuf_Empty` to respond with. func throwError( request: ThrowInput, context: GRPCCore.ServerContext ) async throws -> SwiftProtobuf.Google_Protobuf_Empty } } // Default implementation of 'registerMethods(with:)'. extension ErrorService.StreamingServiceProtocol { internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { router.registerHandler( forMethod: ErrorService.Method.ThrowError.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), serializer: GRPCProtobuf.ProtobufSerializer(), handler: { request, context in try await self.throwError( request: request, context: context ) } ) } } // Default implementation of streaming methods from 'StreamingServiceProtocol'. extension ErrorService.ServiceProtocol { internal func throwError( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse { let response = try await self.throwError( request: GRPCCore.ServerRequest(stream: request), context: context ) return GRPCCore.StreamingServerResponse(single: response) } } // Default implementation of methods from 'ServiceProtocol'. extension ErrorService.SimpleServiceProtocol { internal func throwError( request: GRPCCore.ServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.ServerResponse { return GRPCCore.ServerResponse( message: try await self.throwError( request: request.message, context: context ), metadata: [:] ) } } // MARK: ErrorService (client) extension ErrorService { /// Generated client protocol for the "ErrorService" service. /// /// You don't need to implement this protocol directly, use the generated /// implementation, ``Client``. internal protocol ClientProtocol: Sendable { /// Call the "ThrowError" method. /// /// - Parameters: /// - request: A request containing a single `ThrowInput` message. /// - serializer: A serializer for `ThrowInput` messages. /// - deserializer: A deserializer for `SwiftProtobuf.Google_Protobuf_Empty` messages. /// - options: Options to apply to this RPC. /// - handleResponse: A closure which handles the response, the result of which is /// returned to the caller. Returning from the closure will cancel the RPC if it /// hasn't already finished. /// - Returns: The result of `handleResponse`. func throwError( request: GRPCCore.ClientRequest, serializer: some GRPCCore.MessageSerializer, deserializer: some GRPCCore.MessageDeserializer, options: GRPCCore.CallOptions, onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable } /// Generated client for the "ErrorService" service. /// /// The ``Client`` provides an implementation of ``ClientProtocol`` which wraps /// a `GRPCCore.GRPCCClient`. The underlying `GRPCClient` provides the long-lived /// means of communication with the remote peer. internal struct Client: ClientProtocol where Transport: GRPCCore.ClientTransport { private let client: GRPCCore.GRPCClient /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`. /// /// - Parameters: /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service. internal init(wrapping client: GRPCCore.GRPCClient) { self.client = client } /// Call the "ThrowError" method. /// /// - Parameters: /// - request: A request containing a single `ThrowInput` message. /// - serializer: A serializer for `ThrowInput` messages. /// - deserializer: A deserializer for `SwiftProtobuf.Google_Protobuf_Empty` messages. /// - options: Options to apply to this RPC. /// - handleResponse: A closure which handles the response, the result of which is /// returned to the caller. Returning from the closure will cancel the RPC if it /// hasn't already finished. /// - Returns: The result of `handleResponse`. internal func throwError( request: GRPCCore.ClientRequest, serializer: some GRPCCore.MessageSerializer, deserializer: some GRPCCore.MessageDeserializer, options: GRPCCore.CallOptions = .defaults, onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in try response.message } ) async throws -> Result where Result: Sendable { try await self.client.unary( request: request, descriptor: ErrorService.Method.ThrowError.descriptor, serializer: serializer, deserializer: deserializer, options: options, onResponse: handleResponse ) } } } // Helpers providing default arguments to 'ClientProtocol' methods. extension ErrorService.ClientProtocol { /// Call the "ThrowError" method. /// /// - Parameters: /// - request: A request containing a single `ThrowInput` message. /// - options: Options to apply to this RPC. /// - handleResponse: A closure which handles the response, the result of which is /// returned to the caller. Returning from the closure will cancel the RPC if it /// hasn't already finished. /// - Returns: The result of `handleResponse`. internal func throwError( request: GRPCCore.ClientRequest, options: GRPCCore.CallOptions = .defaults, onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in try response.message } ) async throws -> Result where Result: Sendable { try await self.throwError( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, onResponse: handleResponse ) } } // Helpers providing sugared APIs for 'ClientProtocol' methods. extension ErrorService.ClientProtocol { /// Call the "ThrowError" method. /// /// - Parameters: /// - message: request message to send. /// - metadata: Additional metadata to send, defaults to empty. /// - options: Options to apply to this RPC, defaults to `.defaults`. /// - handleResponse: A closure which handles the response, the result of which is /// returned to the caller. Returning from the closure will cancel the RPC if it /// hasn't already finished. /// - Returns: The result of `handleResponse`. internal func throwError( _ message: ThrowInput, metadata: GRPCCore.Metadata = [:], options: GRPCCore.CallOptions = .defaults, onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in try response.message } ) async throws -> Result where Result: Sendable { let request = GRPCCore.ClientRequest( message: message, metadata: metadata ) return try await self.throwError( request: request, options: options, onResponse: handleResponse ) } }