/* * 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. */ import GRPCCodeGen import GRPCProtobufCodeGen import SwiftProtobufPluginLibrary import Testing struct ProtobufCodeGeneratorTests: UsesDescriptorSet { static let descriptorSetName = "test-service" static let fileDescriptorName = "test-service" @Test("Generate", arguments: [SourceGenerator.Config.AccessLevel.internal, .public, .package]) func generate(accessLevel: SourceGenerator.Config.AccessLevel) throws { let generator = ProtobufCodeGenerator( config: SourceGenerator.Config( accessLevel: accessLevel, accessLevelOnImports: false, client: true, server: true, indentation: 2 ) ) let access: String switch accessLevel { case .public: access = "public" case .internal: access = "internal" case .package: access = "package" default: fatalError() } let generated = try generator.generateCode( fileDescriptor: Self.fileDescriptor, protoFileModuleMappings: ProtoFileToModuleMappings(), extraModuleImports: [] ) let expected = """ /// Leading trivia. // DO NOT EDIT. // swift-format-ignore-file // // Generated by the gRPC Swift generator plugin for the protocol buffer compiler. // Source: test-service.proto // // For information on using the generated types, please see the documentation: // https://github.com/grpc/grpc-swift import GRPCCore import GRPCProtobuf import SwiftProtobuf // MARK: - test.TestService /// Namespace containing generated types for the "test.TestService" service. \(access) enum Test_TestService { /// Service descriptor for the "test.TestService" service. \(access) static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "test.TestService") /// Namespace for method metadata. \(access) enum Method { /// Namespace for "Unary" metadata. \(access) enum Unary { /// Request type for "Unary". \(access) typealias Input = Test_TestInput /// Response type for "Unary". \(access) typealias Output = Test_TestOutput /// Descriptor for "Unary". \(access) static let descriptor = GRPCCore.MethodDescriptor( service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "test.TestService"), method: "Unary" ) } /// Namespace for "ClientStreaming" metadata. \(access) enum ClientStreaming { /// Request type for "ClientStreaming". \(access) typealias Input = Test_TestInput /// Response type for "ClientStreaming". \(access) typealias Output = Test_TestOutput /// Descriptor for "ClientStreaming". \(access) static let descriptor = GRPCCore.MethodDescriptor( service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "test.TestService"), method: "ClientStreaming" ) } /// Namespace for "ServerStreaming" metadata. \(access) enum ServerStreaming { /// Request type for "ServerStreaming". \(access) typealias Input = Test_TestInput /// Response type for "ServerStreaming". \(access) typealias Output = Test_TestOutput /// Descriptor for "ServerStreaming". \(access) static let descriptor = GRPCCore.MethodDescriptor( service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "test.TestService"), method: "ServerStreaming" ) } /// Namespace for "BidirectionalStreaming" metadata. \(access) enum BidirectionalStreaming { /// Request type for "BidirectionalStreaming". \(access) typealias Input = Test_TestInput /// Response type for "BidirectionalStreaming". \(access) typealias Output = Test_TestOutput /// Descriptor for "BidirectionalStreaming". \(access) static let descriptor = GRPCCore.MethodDescriptor( service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "test.TestService"), method: "BidirectionalStreaming" ) } /// Descriptors for all methods in the "test.TestService" service. \(access) static let descriptors: [GRPCCore.MethodDescriptor] = [ Unary.descriptor, ClientStreaming.descriptor, ServerStreaming.descriptor, BidirectionalStreaming.descriptor ] } } extension GRPCCore.ServiceDescriptor { /// Service descriptor for the "test.TestService" service. \(access) static let test_TestService = GRPCCore.ServiceDescriptor(fullyQualifiedService: "test.TestService") } // MARK: test.TestService (server) extension Test_TestService { /// Streaming variant of the service protocol for the "test.TestService" 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. /// /// > Source IDL Documentation: /// > /// > Service docs. \(access) protocol StreamingServiceProtocol: GRPCCore.RegistrableRPCService { /// Handle the "Unary" method. /// /// > Source IDL Documentation: /// > /// > Unary docs. /// /// - Parameters: /// - request: A streaming request of `Test_TestInput` 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 `Test_TestOutput` messages. func unary( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse /// Handle the "ClientStreaming" method. /// /// > Source IDL Documentation: /// > /// > Client streaming docs. /// /// - Parameters: /// - request: A streaming request of `Test_TestInput` 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 `Test_TestOutput` messages. func clientStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse /// Handle the "ServerStreaming" method. /// /// > Source IDL Documentation: /// > /// > Server streaming docs. /// /// - Parameters: /// - request: A streaming request of `Test_TestInput` 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 `Test_TestOutput` messages. func serverStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse /// Handle the "BidirectionalStreaming" method. /// /// > Source IDL Documentation: /// > /// > Bidirectional streaming docs. /// /// - Parameters: /// - request: A streaming request of `Test_TestInput` 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 `Test_TestOutput` messages. func bidirectionalStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse } /// Service protocol for the "test.TestService" 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``. /// /// > Source IDL Documentation: /// > /// > Service docs. \(access) protocol ServiceProtocol: Test_TestService.StreamingServiceProtocol { /// Handle the "Unary" method. /// /// > Source IDL Documentation: /// > /// > Unary docs. /// /// - Parameters: /// - request: A request containing a single `Test_TestInput` 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 `Test_TestOutput` message. func unary( request: GRPCCore.ServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.ServerResponse /// Handle the "ClientStreaming" method. /// /// > Source IDL Documentation: /// > /// > Client streaming docs. /// /// - Parameters: /// - request: A streaming request of `Test_TestInput` 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 response containing a single `Test_TestOutput` message. func clientStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.ServerResponse /// Handle the "ServerStreaming" method. /// /// > Source IDL Documentation: /// > /// > Server streaming docs. /// /// - Parameters: /// - request: A request containing a single `Test_TestInput` 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 streaming response of `Test_TestOutput` messages. func serverStreaming( request: GRPCCore.ServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse /// Handle the "BidirectionalStreaming" method. /// /// > Source IDL Documentation: /// > /// > Bidirectional streaming docs. /// /// - Parameters: /// - request: A streaming request of `Test_TestInput` 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 `Test_TestOutput` messages. func bidirectionalStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse } /// Simple service protocol for the "test.TestService" 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. /// /// > Source IDL Documentation: /// > /// > Service docs. \(access) protocol SimpleServiceProtocol: Test_TestService.ServiceProtocol { /// Handle the "Unary" method. /// /// > Source IDL Documentation: /// > /// > Unary docs. /// /// - Parameters: /// - request: A `Test_TestInput` 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 `Test_TestOutput` to respond with. func unary( request: Test_TestInput, context: GRPCCore.ServerContext ) async throws -> Test_TestOutput /// Handle the "ClientStreaming" method. /// /// > Source IDL Documentation: /// > /// > Client streaming docs. /// /// - Parameters: /// - request: A stream of `Test_TestInput` 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 `Test_TestOutput` to respond with. func clientStreaming( request: GRPCCore.RPCAsyncSequence, context: GRPCCore.ServerContext ) async throws -> Test_TestOutput /// Handle the "ServerStreaming" method. /// /// > Source IDL Documentation: /// > /// > Server streaming docs. /// /// - Parameters: /// - request: A `Test_TestInput` message. /// - response: A response stream of `Test_TestOutput` 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. func serverStreaming( request: Test_TestInput, response: GRPCCore.RPCWriter, context: GRPCCore.ServerContext ) async throws /// Handle the "BidirectionalStreaming" method. /// /// > Source IDL Documentation: /// > /// > Bidirectional streaming docs. /// /// - Parameters: /// - request: A stream of `Test_TestInput` messages. /// - response: A response stream of `Test_TestOutput` 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. func bidirectionalStreaming( request: GRPCCore.RPCAsyncSequence, response: GRPCCore.RPCWriter, context: GRPCCore.ServerContext ) async throws } } // Default implementation of 'registerMethods(with:)'. extension Test_TestService.StreamingServiceProtocol { \(access) func registerMethods(with router: inout GRPCCore.RPCRouter) { router.registerHandler( forMethod: Test_TestService.Method.Unary.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), serializer: GRPCProtobuf.ProtobufSerializer(), handler: { request, context in try await self.unary( request: request, context: context ) } ) router.registerHandler( forMethod: Test_TestService.Method.ClientStreaming.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), serializer: GRPCProtobuf.ProtobufSerializer(), handler: { request, context in try await self.clientStreaming( request: request, context: context ) } ) router.registerHandler( forMethod: Test_TestService.Method.ServerStreaming.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), serializer: GRPCProtobuf.ProtobufSerializer(), handler: { request, context in try await self.serverStreaming( request: request, context: context ) } ) router.registerHandler( forMethod: Test_TestService.Method.BidirectionalStreaming.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), serializer: GRPCProtobuf.ProtobufSerializer(), handler: { request, context in try await self.bidirectionalStreaming( request: request, context: context ) } ) } } // Default implementation of streaming methods from 'StreamingServiceProtocol'. extension Test_TestService.ServiceProtocol { \(access) func unary( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse { let response = try await self.unary( request: GRPCCore.ServerRequest(stream: request), context: context ) return GRPCCore.StreamingServerResponse(single: response) } \(access) func clientStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse { let response = try await self.clientStreaming( request: request, context: context ) return GRPCCore.StreamingServerResponse(single: response) } \(access) func serverStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse { let response = try await self.serverStreaming( request: GRPCCore.ServerRequest(stream: request), context: context ) return response } } // Default implementation of methods from 'ServiceProtocol'. extension Test_TestService.SimpleServiceProtocol { \(access) func unary( request: GRPCCore.ServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.ServerResponse { return GRPCCore.ServerResponse( message: try await self.unary( request: request.message, context: context ), metadata: [:] ) } \(access) func clientStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.ServerResponse { return GRPCCore.ServerResponse( message: try await self.clientStreaming( request: request.messages, context: context ), metadata: [:] ) } \(access) func serverStreaming( request: GRPCCore.ServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse { return GRPCCore.StreamingServerResponse( metadata: [:], producer: { writer in try await self.serverStreaming( request: request.message, response: writer, context: context ) return [:] } ) } \(access) func bidirectionalStreaming( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext ) async throws -> GRPCCore.StreamingServerResponse { return GRPCCore.StreamingServerResponse( metadata: [:], producer: { writer in try await self.bidirectionalStreaming( request: request.messages, response: writer, context: context ) return [:] } ) } } // MARK: test.TestService (client) extension Test_TestService { /// Generated client protocol for the "test.TestService" service. /// /// You don't need to implement this protocol directly, use the generated /// implementation, ``Client``. /// /// > Source IDL Documentation: /// > /// > Service docs. \(access) protocol ClientProtocol: Sendable { /// Call the "Unary" method. /// /// > Source IDL Documentation: /// > /// > Unary docs. /// /// - Parameters: /// - request: A request containing a single `Test_TestInput` message. /// - serializer: A serializer for `Test_TestInput` messages. /// - deserializer: A deserializer for `Test_TestOutput` 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 unary( 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 /// Call the "ClientStreaming" method. /// /// > Source IDL Documentation: /// > /// > Client streaming docs. /// /// - Parameters: /// - request: A streaming request producing `Test_TestInput` messages. /// - serializer: A serializer for `Test_TestInput` messages. /// - deserializer: A deserializer for `Test_TestOutput` 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 clientStreaming( request: GRPCCore.StreamingClientRequest, 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 /// Call the "ServerStreaming" method. /// /// > Source IDL Documentation: /// > /// > Server streaming docs. /// /// - Parameters: /// - request: A request containing a single `Test_TestInput` message. /// - serializer: A serializer for `Test_TestInput` messages. /// - deserializer: A deserializer for `Test_TestOutput` 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 serverStreaming( request: GRPCCore.ClientRequest, serializer: some GRPCCore.MessageSerializer, deserializer: some GRPCCore.MessageDeserializer, options: GRPCCore.CallOptions, onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable /// Call the "BidirectionalStreaming" method. /// /// > Source IDL Documentation: /// > /// > Bidirectional streaming docs. /// /// - Parameters: /// - request: A streaming request producing `Test_TestInput` messages. /// - serializer: A serializer for `Test_TestInput` messages. /// - deserializer: A deserializer for `Test_TestOutput` 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 bidirectionalStreaming( request: GRPCCore.StreamingClientRequest, serializer: some GRPCCore.MessageSerializer, deserializer: some GRPCCore.MessageDeserializer, options: GRPCCore.CallOptions, onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable } /// Generated client for the "test.TestService" 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. /// /// > Source IDL Documentation: /// > /// > Service docs. \(access) struct Client: ClientProtocol { 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. \(access) init(wrapping client: GRPCCore.GRPCClient) { self.client = client } /// Call the "Unary" method. /// /// > Source IDL Documentation: /// > /// > Unary docs. /// /// - Parameters: /// - request: A request containing a single `Test_TestInput` message. /// - serializer: A serializer for `Test_TestInput` messages. /// - deserializer: A deserializer for `Test_TestOutput` 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`. \(access) func unary( 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: Test_TestService.Method.Unary.descriptor, serializer: serializer, deserializer: deserializer, options: options, onResponse: handleResponse ) } /// Call the "ClientStreaming" method. /// /// > Source IDL Documentation: /// > /// > Client streaming docs. /// /// - Parameters: /// - request: A streaming request producing `Test_TestInput` messages. /// - serializer: A serializer for `Test_TestInput` messages. /// - deserializer: A deserializer for `Test_TestOutput` 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`. \(access) func clientStreaming( request: GRPCCore.StreamingClientRequest, 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.clientStreaming( request: request, descriptor: Test_TestService.Method.ClientStreaming.descriptor, serializer: serializer, deserializer: deserializer, options: options, onResponse: handleResponse ) } /// Call the "ServerStreaming" method. /// /// > Source IDL Documentation: /// > /// > Server streaming docs. /// /// - Parameters: /// - request: A request containing a single `Test_TestInput` message. /// - serializer: A serializer for `Test_TestInput` messages. /// - deserializer: A deserializer for `Test_TestOutput` 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`. \(access) func serverStreaming( request: GRPCCore.ClientRequest, serializer: some GRPCCore.MessageSerializer, deserializer: some GRPCCore.MessageDeserializer, options: GRPCCore.CallOptions = .defaults, onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable { try await self.client.serverStreaming( request: request, descriptor: Test_TestService.Method.ServerStreaming.descriptor, serializer: serializer, deserializer: deserializer, options: options, onResponse: handleResponse ) } /// Call the "BidirectionalStreaming" method. /// /// > Source IDL Documentation: /// > /// > Bidirectional streaming docs. /// /// - Parameters: /// - request: A streaming request producing `Test_TestInput` messages. /// - serializer: A serializer for `Test_TestInput` messages. /// - deserializer: A deserializer for `Test_TestOutput` 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`. \(access) func bidirectionalStreaming( request: GRPCCore.StreamingClientRequest, serializer: some GRPCCore.MessageSerializer, deserializer: some GRPCCore.MessageDeserializer, options: GRPCCore.CallOptions = .defaults, onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable { try await self.client.bidirectionalStreaming( request: request, descriptor: Test_TestService.Method.BidirectionalStreaming.descriptor, serializer: serializer, deserializer: deserializer, options: options, onResponse: handleResponse ) } } } // Helpers providing default arguments to 'ClientProtocol' methods. extension Test_TestService.ClientProtocol { /// Call the "Unary" method. /// /// > Source IDL Documentation: /// > /// > Unary docs. /// /// - Parameters: /// - request: A request containing a single `Test_TestInput` 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`. \(access) func unary( 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.unary( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, onResponse: handleResponse ) } /// Call the "ClientStreaming" method. /// /// > Source IDL Documentation: /// > /// > Client streaming docs. /// /// - Parameters: /// - request: A streaming request producing `Test_TestInput` 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`. \(access) func clientStreaming( request: GRPCCore.StreamingClientRequest, 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.clientStreaming( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, onResponse: handleResponse ) } /// Call the "ServerStreaming" method. /// /// > Source IDL Documentation: /// > /// > Server streaming docs. /// /// - Parameters: /// - request: A request containing a single `Test_TestInput` 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`. \(access) func serverStreaming( request: GRPCCore.ClientRequest, options: GRPCCore.CallOptions = .defaults, onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable { try await self.serverStreaming( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, onResponse: handleResponse ) } /// Call the "BidirectionalStreaming" method. /// /// > Source IDL Documentation: /// > /// > Bidirectional streaming docs. /// /// - Parameters: /// - request: A streaming request producing `Test_TestInput` 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`. \(access) func bidirectionalStreaming( request: GRPCCore.StreamingClientRequest, options: GRPCCore.CallOptions = .defaults, onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable { try await self.bidirectionalStreaming( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, onResponse: handleResponse ) } } // Helpers providing sugared APIs for 'ClientProtocol' methods. extension Test_TestService.ClientProtocol { /// Call the "Unary" method. /// /// > Source IDL Documentation: /// > /// > Unary docs. /// /// - 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`. \(access) func unary( _ message: Test_TestInput, 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.unary( request: request, options: options, onResponse: handleResponse ) } /// Call the "ClientStreaming" method. /// /// > Source IDL Documentation: /// > /// > Client streaming docs. /// /// - Parameters: /// - metadata: Additional metadata to send, defaults to empty. /// - options: Options to apply to this RPC, defaults to `.defaults`. /// - producer: A closure producing request messages to send to the server. The request /// stream is closed when the closure returns. /// - 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`. \(access) func clientStreaming( metadata: GRPCCore.Metadata = [:], options: GRPCCore.CallOptions = .defaults, requestProducer producer: @Sendable @escaping (GRPCCore.RPCWriter) async throws -> Void, onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in try response.message } ) async throws -> Result where Result: Sendable { let request = GRPCCore.StreamingClientRequest( metadata: metadata, producer: producer ) return try await self.clientStreaming( request: request, options: options, onResponse: handleResponse ) } /// Call the "ServerStreaming" method. /// /// > Source IDL Documentation: /// > /// > Server streaming docs. /// /// - 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`. \(access) func serverStreaming( _ message: Test_TestInput, metadata: GRPCCore.Metadata = [:], options: GRPCCore.CallOptions = .defaults, onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable { let request = GRPCCore.ClientRequest( message: message, metadata: metadata ) return try await self.serverStreaming( request: request, options: options, onResponse: handleResponse ) } /// Call the "BidirectionalStreaming" method. /// /// > Source IDL Documentation: /// > /// > Bidirectional streaming docs. /// /// - Parameters: /// - metadata: Additional metadata to send, defaults to empty. /// - options: Options to apply to this RPC, defaults to `.defaults`. /// - producer: A closure producing request messages to send to the server. The request /// stream is closed when the closure returns. /// - 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`. \(access) func bidirectionalStreaming( metadata: GRPCCore.Metadata = [:], options: GRPCCore.CallOptions = .defaults, requestProducer producer: @Sendable @escaping (GRPCCore.RPCWriter) async throws -> Void, onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> Result ) async throws -> Result where Result: Sendable { let request = GRPCCore.StreamingClientRequest( metadata: metadata, producer: producer ) return try await self.bidirectionalStreaming( request: request, options: options, onResponse: handleResponse ) } } """ #expect(generated == expected) } }