diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6bbf64854..8a60ba1f8 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -42,7 +42,7 @@ jobs: MATRIX_LINUX_5_9_ENABLED: false MATRIX_LINUX_5_10_ENABLED: false MATRIX_LINUX_COMMAND: "./dev/build-examples.sh" - MATRIX_LINUX_SETUP_COMMAND: "" + MATRIX_LINUX_SETUP_COMMAND: "apt update && apt install -y protobuf-compiler && ./dev/build-examples.sh" examples-matrix: name: Examples diff --git a/Examples/echo/Package.swift b/Examples/echo/Package.swift index ca473e981..01608d9a5 100644 --- a/Examples/echo/Package.swift +++ b/Examples/echo/Package.swift @@ -21,9 +21,9 @@ let package = Package( name: "echo", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ @@ -34,6 +34,9 @@ let package = Package( .product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"), .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), .product(name: "ArgumentParser", package: "swift-argument-parser"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") ] ) ] diff --git a/Examples/echo/Sources/Generated/echo.grpc.swift b/Examples/echo/Sources/Generated/echo.grpc.swift deleted file mode 100644 index 3a0e70694..000000000 --- a/Examples/echo/Sources/Generated/echo.grpc.swift +++ /dev/null @@ -1,994 +0,0 @@ -// Copyright (c) 2015, Google Inc. -// -// 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 -// -// Generated by the gRPC Swift generator plugin for the protocol buffer compiler. -// Source: echo.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/grpc/grpc-swift - -import GRPCCore -import GRPCProtobuf - -// MARK: - echo.Echo - -/// Namespace containing generated types for the "echo.Echo" service. -internal enum Echo_Echo { - /// Service descriptor for the "echo.Echo" service. - internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo") - /// Namespace for method metadata. - internal enum Method { - /// Namespace for "Get" metadata. - internal enum Get { - /// Request type for "Get". - internal typealias Input = Echo_EchoRequest - /// Response type for "Get". - internal typealias Output = Echo_EchoResponse - /// Descriptor for "Get". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"), - method: "Get" - ) - } - /// Namespace for "Expand" metadata. - internal enum Expand { - /// Request type for "Expand". - internal typealias Input = Echo_EchoRequest - /// Response type for "Expand". - internal typealias Output = Echo_EchoResponse - /// Descriptor for "Expand". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"), - method: "Expand" - ) - } - /// Namespace for "Collect" metadata. - internal enum Collect { - /// Request type for "Collect". - internal typealias Input = Echo_EchoRequest - /// Response type for "Collect". - internal typealias Output = Echo_EchoResponse - /// Descriptor for "Collect". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"), - method: "Collect" - ) - } - /// Namespace for "Update" metadata. - internal enum Update { - /// Request type for "Update". - internal typealias Input = Echo_EchoRequest - /// Response type for "Update". - internal typealias Output = Echo_EchoResponse - /// Descriptor for "Update". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"), - method: "Update" - ) - } - /// Descriptors for all methods in the "echo.Echo" service. - internal static let descriptors: [GRPCCore.MethodDescriptor] = [ - Get.descriptor, - Expand.descriptor, - Collect.descriptor, - Update.descriptor - ] - } -} - -extension GRPCCore.ServiceDescriptor { - /// Service descriptor for the "echo.Echo" service. - internal static let echo_Echo = GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo") -} - -// MARK: echo.Echo (server) - -extension Echo_Echo { - /// Streaming variant of the service protocol for the "echo.Echo" 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 "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func get( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func expand( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func update( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - } - - /// Service protocol for the "echo.Echo" 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: Echo_Echo.StreamingServiceProtocol { - /// Handle the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` 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 `Echo_EchoResponse` message. - func get( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// Handle the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func expand( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` message. - func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// Handle the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func update( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - } - - /// Simple service protocol for the "echo.Echo" 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: Echo_Echo.ServiceProtocol { - /// Handle the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A `Echo_EchoRequest` 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 `Echo_EchoResponse` to respond with. - func get( - request: Echo_EchoRequest, - context: GRPCCore.ServerContext - ) async throws -> Echo_EchoResponse - - /// Handle the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A `Echo_EchoRequest` message. - /// - response: A response stream of `Echo_EchoResponse` 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 expand( - request: Echo_EchoRequest, - response: GRPCCore.RPCWriter, - context: GRPCCore.ServerContext - ) async throws - - /// Handle the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A stream of `Echo_EchoRequest` 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 `Echo_EchoResponse` to respond with. - func collect( - request: GRPCCore.RPCAsyncSequence, - context: GRPCCore.ServerContext - ) async throws -> Echo_EchoResponse - - /// Handle the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A stream of `Echo_EchoRequest` messages. - /// - response: A response stream of `Echo_EchoResponse` 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 update( - request: GRPCCore.RPCAsyncSequence, - response: GRPCCore.RPCWriter, - context: GRPCCore.ServerContext - ) async throws - } -} - -// Default implementation of 'registerMethods(with:)'. -extension Echo_Echo.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { - router.registerHandler( - forMethod: Echo_Echo.Method.Get.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.get( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Echo_Echo.Method.Expand.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.expand( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Echo_Echo.Method.Collect.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.collect( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Echo_Echo.Method.Update.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.update( - request: request, - context: context - ) - } - ) - } -} - -// Default implementation of streaming methods from 'StreamingServiceProtocol'. -extension Echo_Echo.ServiceProtocol { - internal func get( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.get( - request: GRPCCore.ServerRequest(stream: request), - context: context - ) - return GRPCCore.StreamingServerResponse(single: response) - } - - internal func expand( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.expand( - request: GRPCCore.ServerRequest(stream: request), - context: context - ) - return response - } - - internal func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.collect( - request: request, - context: context - ) - return GRPCCore.StreamingServerResponse(single: response) - } -} - -// Default implementation of methods from 'ServiceProtocol'. -extension Echo_Echo.SimpleServiceProtocol { - internal func get( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse { - return GRPCCore.ServerResponse( - message: try await self.get( - request: request.message, - context: context - ), - metadata: [:] - ) - } - - internal func expand( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - return GRPCCore.StreamingServerResponse( - metadata: [:], - producer: { writer in - try await self.expand( - request: request.message, - response: writer, - context: context - ) - return [:] - } - ) - } - - internal func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse { - return GRPCCore.ServerResponse( - message: try await self.collect( - request: request.messages, - context: context - ), - metadata: [:] - ) - } - - internal func update( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - return GRPCCore.StreamingServerResponse( - metadata: [:], - producer: { writer in - try await self.update( - request: request.messages, - response: writer, - context: context - ) - return [:] - } - ) - } -} - -// MARK: echo.Echo (client) - -extension Echo_Echo { - /// Generated client protocol for the "echo.Echo" service. - /// - /// You don't need to implement this protocol directly, use the generated - /// implementation, ``Client``. - internal protocol ClientProtocol: Sendable { - /// Call the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` message. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 get( - 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 "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` message. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 expand( - 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 "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` messages. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 collect( - 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 "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` messages. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 update( - 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 "echo.Echo" 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 "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` message. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 get( - 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: Echo_Echo.Method.Get.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` message. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 expand( - 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: Echo_Echo.Method.Expand.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` messages. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 collect( - 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: Echo_Echo.Method.Collect.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` messages. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 update( - 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: Echo_Echo.Method.Update.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - } -} - -// Helpers providing default arguments to 'ClientProtocol' methods. -extension Echo_Echo.ClientProtocol { - /// Call the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` 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 get( - 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.get( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` 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 expand( - 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.expand( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` 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 collect( - 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.collect( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` 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 update( - 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.update( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } -} - -// Helpers providing sugared APIs for 'ClientProtocol' methods. -extension Echo_Echo.ClientProtocol { - /// Call the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - 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 get( - _ message: Echo_EchoRequest, - 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.get( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - 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 expand( - _ message: Echo_EchoRequest, - 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.expand( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - 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`. - internal func collect( - 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.collect( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - 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`. - internal func update( - 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.update( - request: request, - options: options, - onResponse: handleResponse - ) - } -} \ No newline at end of file diff --git a/Examples/echo/Sources/Generated/echo.pb.swift b/Examples/echo/Sources/Generated/echo.pb.swift deleted file mode 100644 index 88ef21ca9..000000000 --- a/Examples/echo/Sources/Generated/echo.pb.swift +++ /dev/null @@ -1,129 +0,0 @@ -// DO NOT EDIT. -// swift-format-ignore-file -// swiftlint:disable all -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: echo.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/apple/swift-protobuf/ - -// Copyright (c) 2015, Google Inc. -// -// 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 SwiftProtobuf - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that you are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -struct Echo_EchoRequest: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The text of a message to be echoed. - var text: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -struct Echo_EchoResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The text of an echo response. - var text: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "echo" - -extension Echo_EchoRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".EchoRequest" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "text"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.text) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if !self.text.isEmpty { - try visitor.visitSingularStringField(value: self.text, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Echo_EchoRequest, rhs: Echo_EchoRequest) -> Bool { - if lhs.text != rhs.text {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Echo_EchoResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".EchoResponse" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "text"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.text) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if !self.text.isEmpty { - try visitor.visitSingularStringField(value: self.text, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Echo_EchoResponse, rhs: Echo_EchoResponse) -> Bool { - if lhs.text != rhs.text {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Examples/echo/Sources/Protos/echo b/Examples/echo/Sources/Protos/echo new file mode 120000 index 000000000..66fa3f5f5 --- /dev/null +++ b/Examples/echo/Sources/Protos/echo @@ -0,0 +1 @@ +../../../../dev/protos/examples/echo/ \ No newline at end of file diff --git a/Examples/echo/Sources/Protos/grpc-swift-proto-generator-config.json b/Examples/echo/Sources/Protos/grpc-swift-proto-generator-config.json new file mode 100644 index 000000000..e6dda31fb --- /dev/null +++ b/Examples/echo/Sources/Protos/grpc-swift-proto-generator-config.json @@ -0,0 +1,7 @@ +{ + "generate": { + "clients": true, + "servers": true, + "messages": true + } +} diff --git a/Examples/error-details/Package.swift b/Examples/error-details/Package.swift index c7faca691..e9c868719 100644 --- a/Examples/error-details/Package.swift +++ b/Examples/error-details/Package.swift @@ -21,8 +21,8 @@ let package = Package( name: "error-details", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), ], targets: [ .executableTarget( @@ -31,6 +31,9 @@ let package = Package( .product(name: "GRPCCore", package: "grpc-swift"), .product(name: "GRPCInProcessTransport", package: "grpc-swift"), .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") ] ) ] diff --git a/Examples/error-details/Sources/Generated/helloworld.grpc.swift b/Examples/error-details/Sources/Generated/helloworld.grpc.swift deleted file mode 100644 index 329c0e816..000000000 --- a/Examples/error-details/Sources/Generated/helloworld.grpc.swift +++ /dev/null @@ -1,362 +0,0 @@ -/// Copyright 2015 gRPC authors. -/// -/// 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 -// -// Generated by the gRPC Swift generator plugin for the protocol buffer compiler. -// Source: helloworld.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/grpc/grpc-swift - -import GRPCCore -import GRPCProtobuf - -// MARK: - helloworld.Greeter - -/// Namespace containing generated types for the "helloworld.Greeter" service. -internal enum Helloworld_Greeter { - /// Service descriptor for the "helloworld.Greeter" service. - internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter") - /// Namespace for method metadata. - internal enum Method { - /// Namespace for "SayHello" metadata. - internal enum SayHello { - /// Request type for "SayHello". - internal typealias Input = Helloworld_HelloRequest - /// Response type for "SayHello". - internal typealias Output = Helloworld_HelloReply - /// Descriptor for "SayHello". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter"), - method: "SayHello" - ) - } - /// Descriptors for all methods in the "helloworld.Greeter" service. - internal static let descriptors: [GRPCCore.MethodDescriptor] = [ - SayHello.descriptor - ] - } -} - -extension GRPCCore.ServiceDescriptor { - /// Service descriptor for the "helloworld.Greeter" service. - internal static let helloworld_Greeter = GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter") -} - -// MARK: helloworld.Greeter (server) - -extension Helloworld_Greeter { - /// Streaming variant of the service protocol for the "helloworld.Greeter" 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: - /// > - /// > The greeting service definition. - internal protocol StreamingServiceProtocol: GRPCCore.RegistrableRPCService { - /// Handle the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A streaming request of `Helloworld_HelloRequest` 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 `Helloworld_HelloReply` messages. - func sayHello( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - } - - /// Service protocol for the "helloworld.Greeter" 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: - /// > - /// > The greeting service definition. - internal protocol ServiceProtocol: Helloworld_Greeter.StreamingServiceProtocol { - /// Handle the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A request containing a single `Helloworld_HelloRequest` 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 `Helloworld_HelloReply` message. - func sayHello( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - } - - /// Simple service protocol for the "helloworld.Greeter" 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: - /// > - /// > The greeting service definition. - internal protocol SimpleServiceProtocol: Helloworld_Greeter.ServiceProtocol { - /// Handle the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A `Helloworld_HelloRequest` 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 `Helloworld_HelloReply` to respond with. - func sayHello( - request: Helloworld_HelloRequest, - context: GRPCCore.ServerContext - ) async throws -> Helloworld_HelloReply - } -} - -// Default implementation of 'registerMethods(with:)'. -extension Helloworld_Greeter.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { - router.registerHandler( - forMethod: Helloworld_Greeter.Method.SayHello.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.sayHello( - request: request, - context: context - ) - } - ) - } -} - -// Default implementation of streaming methods from 'StreamingServiceProtocol'. -extension Helloworld_Greeter.ServiceProtocol { - internal func sayHello( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.sayHello( - request: GRPCCore.ServerRequest(stream: request), - context: context - ) - return GRPCCore.StreamingServerResponse(single: response) - } -} - -// Default implementation of methods from 'ServiceProtocol'. -extension Helloworld_Greeter.SimpleServiceProtocol { - internal func sayHello( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse { - return GRPCCore.ServerResponse( - message: try await self.sayHello( - request: request.message, - context: context - ), - metadata: [:] - ) - } -} - -// MARK: helloworld.Greeter (client) - -extension Helloworld_Greeter { - /// Generated client protocol for the "helloworld.Greeter" service. - /// - /// You don't need to implement this protocol directly, use the generated - /// implementation, ``Client``. - /// - /// > Source IDL Documentation: - /// > - /// > The greeting service definition. - internal protocol ClientProtocol: Sendable { - /// Call the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A request containing a single `Helloworld_HelloRequest` message. - /// - serializer: A serializer for `Helloworld_HelloRequest` messages. - /// - deserializer: A deserializer for `Helloworld_HelloReply` 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 sayHello( - 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 "helloworld.Greeter" 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: - /// > - /// > The greeting service definition. - 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 "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A request containing a single `Helloworld_HelloRequest` message. - /// - serializer: A serializer for `Helloworld_HelloRequest` messages. - /// - deserializer: A deserializer for `Helloworld_HelloReply` 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 sayHello( - 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: Helloworld_Greeter.Method.SayHello.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - } -} - -// Helpers providing default arguments to 'ClientProtocol' methods. -extension Helloworld_Greeter.ClientProtocol { - /// Call the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A request containing a single `Helloworld_HelloRequest` 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 sayHello( - 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.sayHello( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } -} - -// Helpers providing sugared APIs for 'ClientProtocol' methods. -extension Helloworld_Greeter.ClientProtocol { - /// Call the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - 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 sayHello( - _ message: Helloworld_HelloRequest, - 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.sayHello( - request: request, - options: options, - onResponse: handleResponse - ) - } -} \ No newline at end of file diff --git a/Examples/error-details/Sources/Generated/helloworld.pb.swift b/Examples/error-details/Sources/Generated/helloworld.pb.swift deleted file mode 100644 index 20b4f36df..000000000 --- a/Examples/error-details/Sources/Generated/helloworld.pb.swift +++ /dev/null @@ -1,129 +0,0 @@ -// DO NOT EDIT. -// swift-format-ignore-file -// swiftlint:disable all -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: helloworld.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/apple/swift-protobuf/ - -/// Copyright 2015 gRPC authors. -/// -/// 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 SwiftProtobuf - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that you are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// The request message containing the user's name. -struct Helloworld_HelloRequest: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - var name: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -/// The response message containing the greetings -struct Helloworld_HelloReply: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - var message: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "helloworld" - -extension Helloworld_HelloRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".HelloRequest" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Helloworld_HelloRequest, rhs: Helloworld_HelloRequest) -> Bool { - if lhs.name != rhs.name {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Helloworld_HelloReply: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".HelloReply" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "message"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.message) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if !self.message.isEmpty { - try visitor.visitSingularStringField(value: self.message, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Helloworld_HelloReply, rhs: Helloworld_HelloReply) -> Bool { - if lhs.message != rhs.message {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Examples/error-details/Sources/Protos/grpc-swift-proto-generator-config.json b/Examples/error-details/Sources/Protos/grpc-swift-proto-generator-config.json new file mode 100644 index 000000000..e6dda31fb --- /dev/null +++ b/Examples/error-details/Sources/Protos/grpc-swift-proto-generator-config.json @@ -0,0 +1,7 @@ +{ + "generate": { + "clients": true, + "servers": true, + "messages": true + } +} diff --git a/Examples/error-details/Sources/Protos/helloworld.proto b/Examples/error-details/Sources/Protos/helloworld.proto new file mode 120000 index 000000000..f4684af4f --- /dev/null +++ b/Examples/error-details/Sources/Protos/helloworld.proto @@ -0,0 +1 @@ +../../../../dev/protos/upstream/grpc/examples/helloworld.proto \ No newline at end of file diff --git a/Examples/hello-world/Package.swift b/Examples/hello-world/Package.swift index 18eb5c1f6..696daffc2 100644 --- a/Examples/hello-world/Package.swift +++ b/Examples/hello-world/Package.swift @@ -21,9 +21,9 @@ let package = Package( name: "hello-world", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ @@ -34,6 +34,9 @@ let package = Package( .product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"), .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), .product(name: "ArgumentParser", package: "swift-argument-parser"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") ] ) ] diff --git a/Examples/hello-world/Protos/HelloWorld.proto b/Examples/hello-world/Protos/HelloWorld.proto deleted file mode 120000 index b5e1142c1..000000000 --- a/Examples/hello-world/Protos/HelloWorld.proto +++ /dev/null @@ -1 +0,0 @@ -../../..//dev/protos/upstream/grpc/examples/helloworld.proto \ No newline at end of file diff --git a/Examples/hello-world/Sources/Generated/helloworld.grpc.swift b/Examples/hello-world/Sources/Generated/helloworld.grpc.swift deleted file mode 100644 index 329c0e816..000000000 --- a/Examples/hello-world/Sources/Generated/helloworld.grpc.swift +++ /dev/null @@ -1,362 +0,0 @@ -/// Copyright 2015 gRPC authors. -/// -/// 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 -// -// Generated by the gRPC Swift generator plugin for the protocol buffer compiler. -// Source: helloworld.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/grpc/grpc-swift - -import GRPCCore -import GRPCProtobuf - -// MARK: - helloworld.Greeter - -/// Namespace containing generated types for the "helloworld.Greeter" service. -internal enum Helloworld_Greeter { - /// Service descriptor for the "helloworld.Greeter" service. - internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter") - /// Namespace for method metadata. - internal enum Method { - /// Namespace for "SayHello" metadata. - internal enum SayHello { - /// Request type for "SayHello". - internal typealias Input = Helloworld_HelloRequest - /// Response type for "SayHello". - internal typealias Output = Helloworld_HelloReply - /// Descriptor for "SayHello". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter"), - method: "SayHello" - ) - } - /// Descriptors for all methods in the "helloworld.Greeter" service. - internal static let descriptors: [GRPCCore.MethodDescriptor] = [ - SayHello.descriptor - ] - } -} - -extension GRPCCore.ServiceDescriptor { - /// Service descriptor for the "helloworld.Greeter" service. - internal static let helloworld_Greeter = GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter") -} - -// MARK: helloworld.Greeter (server) - -extension Helloworld_Greeter { - /// Streaming variant of the service protocol for the "helloworld.Greeter" 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: - /// > - /// > The greeting service definition. - internal protocol StreamingServiceProtocol: GRPCCore.RegistrableRPCService { - /// Handle the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A streaming request of `Helloworld_HelloRequest` 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 `Helloworld_HelloReply` messages. - func sayHello( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - } - - /// Service protocol for the "helloworld.Greeter" 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: - /// > - /// > The greeting service definition. - internal protocol ServiceProtocol: Helloworld_Greeter.StreamingServiceProtocol { - /// Handle the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A request containing a single `Helloworld_HelloRequest` 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 `Helloworld_HelloReply` message. - func sayHello( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - } - - /// Simple service protocol for the "helloworld.Greeter" 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: - /// > - /// > The greeting service definition. - internal protocol SimpleServiceProtocol: Helloworld_Greeter.ServiceProtocol { - /// Handle the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A `Helloworld_HelloRequest` 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 `Helloworld_HelloReply` to respond with. - func sayHello( - request: Helloworld_HelloRequest, - context: GRPCCore.ServerContext - ) async throws -> Helloworld_HelloReply - } -} - -// Default implementation of 'registerMethods(with:)'. -extension Helloworld_Greeter.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { - router.registerHandler( - forMethod: Helloworld_Greeter.Method.SayHello.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.sayHello( - request: request, - context: context - ) - } - ) - } -} - -// Default implementation of streaming methods from 'StreamingServiceProtocol'. -extension Helloworld_Greeter.ServiceProtocol { - internal func sayHello( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.sayHello( - request: GRPCCore.ServerRequest(stream: request), - context: context - ) - return GRPCCore.StreamingServerResponse(single: response) - } -} - -// Default implementation of methods from 'ServiceProtocol'. -extension Helloworld_Greeter.SimpleServiceProtocol { - internal func sayHello( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse { - return GRPCCore.ServerResponse( - message: try await self.sayHello( - request: request.message, - context: context - ), - metadata: [:] - ) - } -} - -// MARK: helloworld.Greeter (client) - -extension Helloworld_Greeter { - /// Generated client protocol for the "helloworld.Greeter" service. - /// - /// You don't need to implement this protocol directly, use the generated - /// implementation, ``Client``. - /// - /// > Source IDL Documentation: - /// > - /// > The greeting service definition. - internal protocol ClientProtocol: Sendable { - /// Call the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A request containing a single `Helloworld_HelloRequest` message. - /// - serializer: A serializer for `Helloworld_HelloRequest` messages. - /// - deserializer: A deserializer for `Helloworld_HelloReply` 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 sayHello( - 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 "helloworld.Greeter" 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: - /// > - /// > The greeting service definition. - 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 "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A request containing a single `Helloworld_HelloRequest` message. - /// - serializer: A serializer for `Helloworld_HelloRequest` messages. - /// - deserializer: A deserializer for `Helloworld_HelloReply` 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 sayHello( - 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: Helloworld_Greeter.Method.SayHello.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - } -} - -// Helpers providing default arguments to 'ClientProtocol' methods. -extension Helloworld_Greeter.ClientProtocol { - /// Call the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - Parameters: - /// - request: A request containing a single `Helloworld_HelloRequest` 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 sayHello( - 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.sayHello( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } -} - -// Helpers providing sugared APIs for 'ClientProtocol' methods. -extension Helloworld_Greeter.ClientProtocol { - /// Call the "SayHello" method. - /// - /// > Source IDL Documentation: - /// > - /// > Sends a greeting - /// - /// - 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 sayHello( - _ message: Helloworld_HelloRequest, - 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.sayHello( - request: request, - options: options, - onResponse: handleResponse - ) - } -} \ No newline at end of file diff --git a/Examples/hello-world/Sources/Generated/helloworld.pb.swift b/Examples/hello-world/Sources/Generated/helloworld.pb.swift deleted file mode 100644 index 20b4f36df..000000000 --- a/Examples/hello-world/Sources/Generated/helloworld.pb.swift +++ /dev/null @@ -1,129 +0,0 @@ -// DO NOT EDIT. -// swift-format-ignore-file -// swiftlint:disable all -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: helloworld.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/apple/swift-protobuf/ - -/// Copyright 2015 gRPC authors. -/// -/// 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 SwiftProtobuf - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that you are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// The request message containing the user's name. -struct Helloworld_HelloRequest: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - var name: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -/// The response message containing the greetings -struct Helloworld_HelloReply: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - var message: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "helloworld" - -extension Helloworld_HelloRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".HelloRequest" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Helloworld_HelloRequest, rhs: Helloworld_HelloRequest) -> Bool { - if lhs.name != rhs.name {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Helloworld_HelloReply: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".HelloReply" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "message"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.message) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if !self.message.isEmpty { - try visitor.visitSingularStringField(value: self.message, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Helloworld_HelloReply, rhs: Helloworld_HelloReply) -> Bool { - if lhs.message != rhs.message {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Examples/hello-world/Sources/Protos/grpc-swift-proto-generator-config.json b/Examples/hello-world/Sources/Protos/grpc-swift-proto-generator-config.json new file mode 100644 index 000000000..e6dda31fb --- /dev/null +++ b/Examples/hello-world/Sources/Protos/grpc-swift-proto-generator-config.json @@ -0,0 +1,7 @@ +{ + "generate": { + "clients": true, + "servers": true, + "messages": true + } +} diff --git a/Examples/hello-world/Sources/Protos/helloworld.proto b/Examples/hello-world/Sources/Protos/helloworld.proto new file mode 120000 index 000000000..f4684af4f --- /dev/null +++ b/Examples/hello-world/Sources/Protos/helloworld.proto @@ -0,0 +1 @@ +../../../../dev/protos/upstream/grpc/examples/helloworld.proto \ No newline at end of file diff --git a/Examples/reflection-server/Package.swift b/Examples/reflection-server/Package.swift index 03aed7629..684b10c1c 100644 --- a/Examples/reflection-server/Package.swift +++ b/Examples/reflection-server/Package.swift @@ -21,9 +21,9 @@ let package = Package( name: "reflection-server", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"), .package(url: "https://github.com/grpc/grpc-swift-extras.git", exact: "1.0.0-beta.3"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], @@ -39,6 +39,9 @@ let package = Package( ], resources: [ .copy("DescriptorSets") + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") ] ) ] diff --git a/Examples/reflection-server/Sources/Generated/echo.grpc.swift b/Examples/reflection-server/Sources/Generated/echo.grpc.swift deleted file mode 100644 index 3a0e70694..000000000 --- a/Examples/reflection-server/Sources/Generated/echo.grpc.swift +++ /dev/null @@ -1,994 +0,0 @@ -// Copyright (c) 2015, Google Inc. -// -// 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 -// -// Generated by the gRPC Swift generator plugin for the protocol buffer compiler. -// Source: echo.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/grpc/grpc-swift - -import GRPCCore -import GRPCProtobuf - -// MARK: - echo.Echo - -/// Namespace containing generated types for the "echo.Echo" service. -internal enum Echo_Echo { - /// Service descriptor for the "echo.Echo" service. - internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo") - /// Namespace for method metadata. - internal enum Method { - /// Namespace for "Get" metadata. - internal enum Get { - /// Request type for "Get". - internal typealias Input = Echo_EchoRequest - /// Response type for "Get". - internal typealias Output = Echo_EchoResponse - /// Descriptor for "Get". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"), - method: "Get" - ) - } - /// Namespace for "Expand" metadata. - internal enum Expand { - /// Request type for "Expand". - internal typealias Input = Echo_EchoRequest - /// Response type for "Expand". - internal typealias Output = Echo_EchoResponse - /// Descriptor for "Expand". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"), - method: "Expand" - ) - } - /// Namespace for "Collect" metadata. - internal enum Collect { - /// Request type for "Collect". - internal typealias Input = Echo_EchoRequest - /// Response type for "Collect". - internal typealias Output = Echo_EchoResponse - /// Descriptor for "Collect". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"), - method: "Collect" - ) - } - /// Namespace for "Update" metadata. - internal enum Update { - /// Request type for "Update". - internal typealias Input = Echo_EchoRequest - /// Response type for "Update". - internal typealias Output = Echo_EchoResponse - /// Descriptor for "Update". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo"), - method: "Update" - ) - } - /// Descriptors for all methods in the "echo.Echo" service. - internal static let descriptors: [GRPCCore.MethodDescriptor] = [ - Get.descriptor, - Expand.descriptor, - Collect.descriptor, - Update.descriptor - ] - } -} - -extension GRPCCore.ServiceDescriptor { - /// Service descriptor for the "echo.Echo" service. - internal static let echo_Echo = GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo") -} - -// MARK: echo.Echo (server) - -extension Echo_Echo { - /// Streaming variant of the service protocol for the "echo.Echo" 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 "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func get( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func expand( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func update( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - } - - /// Service protocol for the "echo.Echo" 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: Echo_Echo.StreamingServiceProtocol { - /// Handle the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` 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 `Echo_EchoResponse` message. - func get( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// Handle the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func expand( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` message. - func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// Handle the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request of `Echo_EchoRequest` 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 `Echo_EchoResponse` messages. - func update( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - } - - /// Simple service protocol for the "echo.Echo" 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: Echo_Echo.ServiceProtocol { - /// Handle the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A `Echo_EchoRequest` 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 `Echo_EchoResponse` to respond with. - func get( - request: Echo_EchoRequest, - context: GRPCCore.ServerContext - ) async throws -> Echo_EchoResponse - - /// Handle the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A `Echo_EchoRequest` message. - /// - response: A response stream of `Echo_EchoResponse` 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 expand( - request: Echo_EchoRequest, - response: GRPCCore.RPCWriter, - context: GRPCCore.ServerContext - ) async throws - - /// Handle the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A stream of `Echo_EchoRequest` 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 `Echo_EchoResponse` to respond with. - func collect( - request: GRPCCore.RPCAsyncSequence, - context: GRPCCore.ServerContext - ) async throws -> Echo_EchoResponse - - /// Handle the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A stream of `Echo_EchoRequest` messages. - /// - response: A response stream of `Echo_EchoResponse` 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 update( - request: GRPCCore.RPCAsyncSequence, - response: GRPCCore.RPCWriter, - context: GRPCCore.ServerContext - ) async throws - } -} - -// Default implementation of 'registerMethods(with:)'. -extension Echo_Echo.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { - router.registerHandler( - forMethod: Echo_Echo.Method.Get.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.get( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Echo_Echo.Method.Expand.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.expand( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Echo_Echo.Method.Collect.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.collect( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Echo_Echo.Method.Update.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.update( - request: request, - context: context - ) - } - ) - } -} - -// Default implementation of streaming methods from 'StreamingServiceProtocol'. -extension Echo_Echo.ServiceProtocol { - internal func get( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.get( - request: GRPCCore.ServerRequest(stream: request), - context: context - ) - return GRPCCore.StreamingServerResponse(single: response) - } - - internal func expand( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.expand( - request: GRPCCore.ServerRequest(stream: request), - context: context - ) - return response - } - - internal func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.collect( - request: request, - context: context - ) - return GRPCCore.StreamingServerResponse(single: response) - } -} - -// Default implementation of methods from 'ServiceProtocol'. -extension Echo_Echo.SimpleServiceProtocol { - internal func get( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse { - return GRPCCore.ServerResponse( - message: try await self.get( - request: request.message, - context: context - ), - metadata: [:] - ) - } - - internal func expand( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - return GRPCCore.StreamingServerResponse( - metadata: [:], - producer: { writer in - try await self.expand( - request: request.message, - response: writer, - context: context - ) - return [:] - } - ) - } - - internal func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse { - return GRPCCore.ServerResponse( - message: try await self.collect( - request: request.messages, - context: context - ), - metadata: [:] - ) - } - - internal func update( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - return GRPCCore.StreamingServerResponse( - metadata: [:], - producer: { writer in - try await self.update( - request: request.messages, - response: writer, - context: context - ) - return [:] - } - ) - } -} - -// MARK: echo.Echo (client) - -extension Echo_Echo { - /// Generated client protocol for the "echo.Echo" service. - /// - /// You don't need to implement this protocol directly, use the generated - /// implementation, ``Client``. - internal protocol ClientProtocol: Sendable { - /// Call the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` message. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 get( - 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 "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` message. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 expand( - 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 "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` messages. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 collect( - 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 "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` messages. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 update( - 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 "echo.Echo" 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 "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` message. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 get( - 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: Echo_Echo.Method.Get.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` message. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 expand( - 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: Echo_Echo.Method.Expand.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` messages. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 collect( - 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: Echo_Echo.Method.Collect.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` messages. - /// - serializer: A serializer for `Echo_EchoRequest` messages. - /// - deserializer: A deserializer for `Echo_EchoResponse` 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 update( - 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: Echo_Echo.Method.Update.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - } -} - -// Helpers providing default arguments to 'ClientProtocol' methods. -extension Echo_Echo.ClientProtocol { - /// Call the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` 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 get( - 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.get( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - Parameters: - /// - request: A request containing a single `Echo_EchoRequest` 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 expand( - 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.expand( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` 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 collect( - 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.collect( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - Parameters: - /// - request: A streaming request producing `Echo_EchoRequest` 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 update( - 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.update( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } -} - -// Helpers providing sugared APIs for 'ClientProtocol' methods. -extension Echo_Echo.ClientProtocol { - /// Call the "Get" method. - /// - /// > Source IDL Documentation: - /// > - /// > Immediately returns an echo of a request. - /// - /// - 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 get( - _ message: Echo_EchoRequest, - 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.get( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Expand" method. - /// - /// > Source IDL Documentation: - /// > - /// > Splits a request into words and returns each word in a stream of messages. - /// - /// - 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 expand( - _ message: Echo_EchoRequest, - 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.expand( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Collect" method. - /// - /// > Source IDL Documentation: - /// > - /// > Collects a stream of messages and returns them concatenated when the caller closes. - /// - /// - 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`. - internal func collect( - 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.collect( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "Update" method. - /// - /// > Source IDL Documentation: - /// > - /// > Streams back messages as they are received in an input stream. - /// - /// - 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`. - internal func update( - 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.update( - request: request, - options: options, - onResponse: handleResponse - ) - } -} \ No newline at end of file diff --git a/Examples/reflection-server/Sources/Generated/echo.pb.swift b/Examples/reflection-server/Sources/Generated/echo.pb.swift deleted file mode 100644 index 88ef21ca9..000000000 --- a/Examples/reflection-server/Sources/Generated/echo.pb.swift +++ /dev/null @@ -1,129 +0,0 @@ -// DO NOT EDIT. -// swift-format-ignore-file -// swiftlint:disable all -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: echo.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/apple/swift-protobuf/ - -// Copyright (c) 2015, Google Inc. -// -// 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 SwiftProtobuf - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that you are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -struct Echo_EchoRequest: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The text of a message to be echoed. - var text: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -struct Echo_EchoResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The text of an echo response. - var text: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "echo" - -extension Echo_EchoRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".EchoRequest" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "text"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.text) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if !self.text.isEmpty { - try visitor.visitSingularStringField(value: self.text, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Echo_EchoRequest, rhs: Echo_EchoRequest) -> Bool { - if lhs.text != rhs.text {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Echo_EchoResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".EchoResponse" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "text"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.text) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if !self.text.isEmpty { - try visitor.visitSingularStringField(value: self.text, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Echo_EchoResponse, rhs: Echo_EchoResponse) -> Bool { - if lhs.text != rhs.text {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Examples/reflection-server/Sources/Protos/echo b/Examples/reflection-server/Sources/Protos/echo new file mode 120000 index 000000000..d28b5425a --- /dev/null +++ b/Examples/reflection-server/Sources/Protos/echo @@ -0,0 +1 @@ +../../../../dev/protos/examples/echo \ No newline at end of file diff --git a/Examples/reflection-server/Sources/Protos/grpc-swift-proto-generator-config.json b/Examples/reflection-server/Sources/Protos/grpc-swift-proto-generator-config.json new file mode 100644 index 000000000..e6dda31fb --- /dev/null +++ b/Examples/reflection-server/Sources/Protos/grpc-swift-proto-generator-config.json @@ -0,0 +1,7 @@ +{ + "generate": { + "clients": true, + "servers": true, + "messages": true + } +} diff --git a/Examples/route-guide/Package.swift b/Examples/route-guide/Package.swift index 86df4fa62..b2d38d69f 100644 --- a/Examples/route-guide/Package.swift +++ b/Examples/route-guide/Package.swift @@ -21,9 +21,9 @@ let package = Package( name: "route-guide", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.3"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ @@ -37,6 +37,9 @@ let package = Package( ], resources: [ .copy("route_guide_db.json") + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") ] ) ] diff --git a/Examples/route-guide/Sources/Generated/route_guide.grpc.swift b/Examples/route-guide/Sources/Generated/route_guide.grpc.swift deleted file mode 100644 index 87ef9ba8b..000000000 --- a/Examples/route-guide/Sources/Generated/route_guide.grpc.swift +++ /dev/null @@ -1,1126 +0,0 @@ -// Copyright 2015 gRPC authors. -// -// 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 -// -// Generated by the gRPC Swift generator plugin for the protocol buffer compiler. -// Source: route_guide.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/grpc/grpc-swift - -import GRPCCore -import GRPCProtobuf - -// MARK: - routeguide.RouteGuide - -/// Namespace containing generated types for the "routeguide.RouteGuide" service. -internal enum Routeguide_RouteGuide { - /// Service descriptor for the "routeguide.RouteGuide" service. - internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "routeguide.RouteGuide") - /// Namespace for method metadata. - internal enum Method { - /// Namespace for "GetFeature" metadata. - internal enum GetFeature { - /// Request type for "GetFeature". - internal typealias Input = Routeguide_Point - /// Response type for "GetFeature". - internal typealias Output = Routeguide_Feature - /// Descriptor for "GetFeature". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "routeguide.RouteGuide"), - method: "GetFeature" - ) - } - /// Namespace for "ListFeatures" metadata. - internal enum ListFeatures { - /// Request type for "ListFeatures". - internal typealias Input = Routeguide_Rectangle - /// Response type for "ListFeatures". - internal typealias Output = Routeguide_Feature - /// Descriptor for "ListFeatures". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "routeguide.RouteGuide"), - method: "ListFeatures" - ) - } - /// Namespace for "RecordRoute" metadata. - internal enum RecordRoute { - /// Request type for "RecordRoute". - internal typealias Input = Routeguide_Point - /// Response type for "RecordRoute". - internal typealias Output = Routeguide_RouteSummary - /// Descriptor for "RecordRoute". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "routeguide.RouteGuide"), - method: "RecordRoute" - ) - } - /// Namespace for "RouteChat" metadata. - internal enum RouteChat { - /// Request type for "RouteChat". - internal typealias Input = Routeguide_RouteNote - /// Response type for "RouteChat". - internal typealias Output = Routeguide_RouteNote - /// Descriptor for "RouteChat". - internal static let descriptor = GRPCCore.MethodDescriptor( - service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "routeguide.RouteGuide"), - method: "RouteChat" - ) - } - /// Descriptors for all methods in the "routeguide.RouteGuide" service. - internal static let descriptors: [GRPCCore.MethodDescriptor] = [ - GetFeature.descriptor, - ListFeatures.descriptor, - RecordRoute.descriptor, - RouteChat.descriptor - ] - } -} - -extension GRPCCore.ServiceDescriptor { - /// Service descriptor for the "routeguide.RouteGuide" service. - internal static let routeguide_RouteGuide = GRPCCore.ServiceDescriptor(fullyQualifiedService: "routeguide.RouteGuide") -} - -// MARK: routeguide.RouteGuide (server) - -extension Routeguide_RouteGuide { - /// Streaming variant of the service protocol for the "routeguide.RouteGuide" 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: - /// > - /// > Interface exported by the server. - internal protocol StreamingServiceProtocol: GRPCCore.RegistrableRPCService { - /// Handle the "GetFeature" method. - /// - /// > Source IDL Documentation: - /// > - /// > A simple RPC. - /// > - /// > Obtains the feature at a given position. - /// > - /// > A feature with an empty name is returned if there's no feature at the given - /// > position. - /// - /// - Parameters: - /// - request: A streaming request of `Routeguide_Point` 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 `Routeguide_Feature` messages. - func getFeature( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "ListFeatures" method. - /// - /// > Source IDL Documentation: - /// > - /// > A server-to-client streaming RPC. - /// > - /// > Obtains the Features available within the given Rectangle. Results are - /// > streamed rather than returned at once (e.g. in a response message with a - /// > repeated field), as the rectangle may cover a large area and contain a - /// > huge number of features. - /// - /// - Parameters: - /// - request: A streaming request of `Routeguide_Rectangle` 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 `Routeguide_Feature` messages. - func listFeatures( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "RecordRoute" method. - /// - /// > Source IDL Documentation: - /// > - /// > A client-to-server streaming RPC. - /// > - /// > Accepts a stream of Points on a route being traversed, returning a - /// > RouteSummary when traversal is completed. - /// - /// - Parameters: - /// - request: A streaming request of `Routeguide_Point` 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 `Routeguide_RouteSummary` messages. - func recordRoute( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "RouteChat" method. - /// - /// > Source IDL Documentation: - /// > - /// > A Bidirectional streaming RPC. - /// > - /// > Accepts a stream of RouteNotes sent while a route is being traversed, - /// > while receiving other RouteNotes (e.g. from other users). - /// - /// - Parameters: - /// - request: A streaming request of `Routeguide_RouteNote` 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 `Routeguide_RouteNote` messages. - func routeChat( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - } - - /// Service protocol for the "routeguide.RouteGuide" 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: - /// > - /// > Interface exported by the server. - internal protocol ServiceProtocol: Routeguide_RouteGuide.StreamingServiceProtocol { - /// Handle the "GetFeature" method. - /// - /// > Source IDL Documentation: - /// > - /// > A simple RPC. - /// > - /// > Obtains the feature at a given position. - /// > - /// > A feature with an empty name is returned if there's no feature at the given - /// > position. - /// - /// - Parameters: - /// - request: A request containing a single `Routeguide_Point` 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 `Routeguide_Feature` message. - func getFeature( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// Handle the "ListFeatures" method. - /// - /// > Source IDL Documentation: - /// > - /// > A server-to-client streaming RPC. - /// > - /// > Obtains the Features available within the given Rectangle. Results are - /// > streamed rather than returned at once (e.g. in a response message with a - /// > repeated field), as the rectangle may cover a large area and contain a - /// > huge number of features. - /// - /// - Parameters: - /// - request: A request containing a single `Routeguide_Rectangle` 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 `Routeguide_Feature` messages. - func listFeatures( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Handle the "RecordRoute" method. - /// - /// > Source IDL Documentation: - /// > - /// > A client-to-server streaming RPC. - /// > - /// > Accepts a stream of Points on a route being traversed, returning a - /// > RouteSummary when traversal is completed. - /// - /// - Parameters: - /// - request: A streaming request of `Routeguide_Point` 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 `Routeguide_RouteSummary` message. - func recordRoute( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// Handle the "RouteChat" method. - /// - /// > Source IDL Documentation: - /// > - /// > A Bidirectional streaming RPC. - /// > - /// > Accepts a stream of RouteNotes sent while a route is being traversed, - /// > while receiving other RouteNotes (e.g. from other users). - /// - /// - Parameters: - /// - request: A streaming request of `Routeguide_RouteNote` 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 `Routeguide_RouteNote` messages. - func routeChat( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - } - - /// Simple service protocol for the "routeguide.RouteGuide" 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: - /// > - /// > Interface exported by the server. - internal protocol SimpleServiceProtocol: Routeguide_RouteGuide.ServiceProtocol { - /// Handle the "GetFeature" method. - /// - /// > Source IDL Documentation: - /// > - /// > A simple RPC. - /// > - /// > Obtains the feature at a given position. - /// > - /// > A feature with an empty name is returned if there's no feature at the given - /// > position. - /// - /// - Parameters: - /// - request: A `Routeguide_Point` 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 `Routeguide_Feature` to respond with. - func getFeature( - request: Routeguide_Point, - context: GRPCCore.ServerContext - ) async throws -> Routeguide_Feature - - /// Handle the "ListFeatures" method. - /// - /// > Source IDL Documentation: - /// > - /// > A server-to-client streaming RPC. - /// > - /// > Obtains the Features available within the given Rectangle. Results are - /// > streamed rather than returned at once (e.g. in a response message with a - /// > repeated field), as the rectangle may cover a large area and contain a - /// > huge number of features. - /// - /// - Parameters: - /// - request: A `Routeguide_Rectangle` message. - /// - response: A response stream of `Routeguide_Feature` 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 listFeatures( - request: Routeguide_Rectangle, - response: GRPCCore.RPCWriter, - context: GRPCCore.ServerContext - ) async throws - - /// Handle the "RecordRoute" method. - /// - /// > Source IDL Documentation: - /// > - /// > A client-to-server streaming RPC. - /// > - /// > Accepts a stream of Points on a route being traversed, returning a - /// > RouteSummary when traversal is completed. - /// - /// - Parameters: - /// - request: A stream of `Routeguide_Point` 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 `Routeguide_RouteSummary` to respond with. - func recordRoute( - request: GRPCCore.RPCAsyncSequence, - context: GRPCCore.ServerContext - ) async throws -> Routeguide_RouteSummary - - /// Handle the "RouteChat" method. - /// - /// > Source IDL Documentation: - /// > - /// > A Bidirectional streaming RPC. - /// > - /// > Accepts a stream of RouteNotes sent while a route is being traversed, - /// > while receiving other RouteNotes (e.g. from other users). - /// - /// - Parameters: - /// - request: A stream of `Routeguide_RouteNote` messages. - /// - response: A response stream of `Routeguide_RouteNote` 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 routeChat( - request: GRPCCore.RPCAsyncSequence, - response: GRPCCore.RPCWriter, - context: GRPCCore.ServerContext - ) async throws - } -} - -// Default implementation of 'registerMethods(with:)'. -extension Routeguide_RouteGuide.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { - router.registerHandler( - forMethod: Routeguide_RouteGuide.Method.GetFeature.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.getFeature( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Routeguide_RouteGuide.Method.ListFeatures.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.listFeatures( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Routeguide_RouteGuide.Method.RecordRoute.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.recordRoute( - request: request, - context: context - ) - } - ) - router.registerHandler( - forMethod: Routeguide_RouteGuide.Method.RouteChat.descriptor, - deserializer: GRPCProtobuf.ProtobufDeserializer(), - serializer: GRPCProtobuf.ProtobufSerializer(), - handler: { request, context in - try await self.routeChat( - request: request, - context: context - ) - } - ) - } -} - -// Default implementation of streaming methods from 'StreamingServiceProtocol'. -extension Routeguide_RouteGuide.ServiceProtocol { - internal func getFeature( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.getFeature( - request: GRPCCore.ServerRequest(stream: request), - context: context - ) - return GRPCCore.StreamingServerResponse(single: response) - } - - internal func listFeatures( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.listFeatures( - request: GRPCCore.ServerRequest(stream: request), - context: context - ) - return response - } - - internal func recordRoute( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - let response = try await self.recordRoute( - request: request, - context: context - ) - return GRPCCore.StreamingServerResponse(single: response) - } -} - -// Default implementation of methods from 'ServiceProtocol'. -extension Routeguide_RouteGuide.SimpleServiceProtocol { - internal func getFeature( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse { - return GRPCCore.ServerResponse( - message: try await self.getFeature( - request: request.message, - context: context - ), - metadata: [:] - ) - } - - internal func listFeatures( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - return GRPCCore.StreamingServerResponse( - metadata: [:], - producer: { writer in - try await self.listFeatures( - request: request.message, - response: writer, - context: context - ) - return [:] - } - ) - } - - internal func recordRoute( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse { - return GRPCCore.ServerResponse( - message: try await self.recordRoute( - request: request.messages, - context: context - ), - metadata: [:] - ) - } - - internal func routeChat( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse { - return GRPCCore.StreamingServerResponse( - metadata: [:], - producer: { writer in - try await self.routeChat( - request: request.messages, - response: writer, - context: context - ) - return [:] - } - ) - } -} - -// MARK: routeguide.RouteGuide (client) - -extension Routeguide_RouteGuide { - /// Generated client protocol for the "routeguide.RouteGuide" service. - /// - /// You don't need to implement this protocol directly, use the generated - /// implementation, ``Client``. - /// - /// > Source IDL Documentation: - /// > - /// > Interface exported by the server. - internal protocol ClientProtocol: Sendable { - /// Call the "GetFeature" method. - /// - /// > Source IDL Documentation: - /// > - /// > A simple RPC. - /// > - /// > Obtains the feature at a given position. - /// > - /// > A feature with an empty name is returned if there's no feature at the given - /// > position. - /// - /// - Parameters: - /// - request: A request containing a single `Routeguide_Point` message. - /// - serializer: A serializer for `Routeguide_Point` messages. - /// - deserializer: A deserializer for `Routeguide_Feature` 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 getFeature( - 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 "ListFeatures" method. - /// - /// > Source IDL Documentation: - /// > - /// > A server-to-client streaming RPC. - /// > - /// > Obtains the Features available within the given Rectangle. Results are - /// > streamed rather than returned at once (e.g. in a response message with a - /// > repeated field), as the rectangle may cover a large area and contain a - /// > huge number of features. - /// - /// - Parameters: - /// - request: A request containing a single `Routeguide_Rectangle` message. - /// - serializer: A serializer for `Routeguide_Rectangle` messages. - /// - deserializer: A deserializer for `Routeguide_Feature` 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 listFeatures( - 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 "RecordRoute" method. - /// - /// > Source IDL Documentation: - /// > - /// > A client-to-server streaming RPC. - /// > - /// > Accepts a stream of Points on a route being traversed, returning a - /// > RouteSummary when traversal is completed. - /// - /// - Parameters: - /// - request: A streaming request producing `Routeguide_Point` messages. - /// - serializer: A serializer for `Routeguide_Point` messages. - /// - deserializer: A deserializer for `Routeguide_RouteSummary` 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 recordRoute( - 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 "RouteChat" method. - /// - /// > Source IDL Documentation: - /// > - /// > A Bidirectional streaming RPC. - /// > - /// > Accepts a stream of RouteNotes sent while a route is being traversed, - /// > while receiving other RouteNotes (e.g. from other users). - /// - /// - Parameters: - /// - request: A streaming request producing `Routeguide_RouteNote` messages. - /// - serializer: A serializer for `Routeguide_RouteNote` messages. - /// - deserializer: A deserializer for `Routeguide_RouteNote` 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 routeChat( - 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 "routeguide.RouteGuide" 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: - /// > - /// > Interface exported by the server. - 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 "GetFeature" method. - /// - /// > Source IDL Documentation: - /// > - /// > A simple RPC. - /// > - /// > Obtains the feature at a given position. - /// > - /// > A feature with an empty name is returned if there's no feature at the given - /// > position. - /// - /// - Parameters: - /// - request: A request containing a single `Routeguide_Point` message. - /// - serializer: A serializer for `Routeguide_Point` messages. - /// - deserializer: A deserializer for `Routeguide_Feature` 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 getFeature( - 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: Routeguide_RouteGuide.Method.GetFeature.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "ListFeatures" method. - /// - /// > Source IDL Documentation: - /// > - /// > A server-to-client streaming RPC. - /// > - /// > Obtains the Features available within the given Rectangle. Results are - /// > streamed rather than returned at once (e.g. in a response message with a - /// > repeated field), as the rectangle may cover a large area and contain a - /// > huge number of features. - /// - /// - Parameters: - /// - request: A request containing a single `Routeguide_Rectangle` message. - /// - serializer: A serializer for `Routeguide_Rectangle` messages. - /// - deserializer: A deserializer for `Routeguide_Feature` 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 listFeatures( - 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: Routeguide_RouteGuide.Method.ListFeatures.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "RecordRoute" method. - /// - /// > Source IDL Documentation: - /// > - /// > A client-to-server streaming RPC. - /// > - /// > Accepts a stream of Points on a route being traversed, returning a - /// > RouteSummary when traversal is completed. - /// - /// - Parameters: - /// - request: A streaming request producing `Routeguide_Point` messages. - /// - serializer: A serializer for `Routeguide_Point` messages. - /// - deserializer: A deserializer for `Routeguide_RouteSummary` 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 recordRoute( - 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: Routeguide_RouteGuide.Method.RecordRoute.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "RouteChat" method. - /// - /// > Source IDL Documentation: - /// > - /// > A Bidirectional streaming RPC. - /// > - /// > Accepts a stream of RouteNotes sent while a route is being traversed, - /// > while receiving other RouteNotes (e.g. from other users). - /// - /// - Parameters: - /// - request: A streaming request producing `Routeguide_RouteNote` messages. - /// - serializer: A serializer for `Routeguide_RouteNote` messages. - /// - deserializer: A deserializer for `Routeguide_RouteNote` 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 routeChat( - 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: Routeguide_RouteGuide.Method.RouteChat.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - onResponse: handleResponse - ) - } - } -} - -// Helpers providing default arguments to 'ClientProtocol' methods. -extension Routeguide_RouteGuide.ClientProtocol { - /// Call the "GetFeature" method. - /// - /// > Source IDL Documentation: - /// > - /// > A simple RPC. - /// > - /// > Obtains the feature at a given position. - /// > - /// > A feature with an empty name is returned if there's no feature at the given - /// > position. - /// - /// - Parameters: - /// - request: A request containing a single `Routeguide_Point` 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 getFeature( - 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.getFeature( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "ListFeatures" method. - /// - /// > Source IDL Documentation: - /// > - /// > A server-to-client streaming RPC. - /// > - /// > Obtains the Features available within the given Rectangle. Results are - /// > streamed rather than returned at once (e.g. in a response message with a - /// > repeated field), as the rectangle may cover a large area and contain a - /// > huge number of features. - /// - /// - Parameters: - /// - request: A request containing a single `Routeguide_Rectangle` 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 listFeatures( - 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.listFeatures( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "RecordRoute" method. - /// - /// > Source IDL Documentation: - /// > - /// > A client-to-server streaming RPC. - /// > - /// > Accepts a stream of Points on a route being traversed, returning a - /// > RouteSummary when traversal is completed. - /// - /// - Parameters: - /// - request: A streaming request producing `Routeguide_Point` 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 recordRoute( - 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.recordRoute( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } - - /// Call the "RouteChat" method. - /// - /// > Source IDL Documentation: - /// > - /// > A Bidirectional streaming RPC. - /// > - /// > Accepts a stream of RouteNotes sent while a route is being traversed, - /// > while receiving other RouteNotes (e.g. from other users). - /// - /// - Parameters: - /// - request: A streaming request producing `Routeguide_RouteNote` 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 routeChat( - 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.routeChat( - request: request, - serializer: GRPCProtobuf.ProtobufSerializer(), - deserializer: GRPCProtobuf.ProtobufDeserializer(), - options: options, - onResponse: handleResponse - ) - } -} - -// Helpers providing sugared APIs for 'ClientProtocol' methods. -extension Routeguide_RouteGuide.ClientProtocol { - /// Call the "GetFeature" method. - /// - /// > Source IDL Documentation: - /// > - /// > A simple RPC. - /// > - /// > Obtains the feature at a given position. - /// > - /// > A feature with an empty name is returned if there's no feature at the given - /// > position. - /// - /// - 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 getFeature( - _ message: Routeguide_Point, - 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.getFeature( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "ListFeatures" method. - /// - /// > Source IDL Documentation: - /// > - /// > A server-to-client streaming RPC. - /// > - /// > Obtains the Features available within the given Rectangle. Results are - /// > streamed rather than returned at once (e.g. in a response message with a - /// > repeated field), as the rectangle may cover a large area and contain a - /// > huge number of features. - /// - /// - 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 listFeatures( - _ message: Routeguide_Rectangle, - 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.listFeatures( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "RecordRoute" method. - /// - /// > Source IDL Documentation: - /// > - /// > A client-to-server streaming RPC. - /// > - /// > Accepts a stream of Points on a route being traversed, returning a - /// > RouteSummary when traversal is completed. - /// - /// - 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`. - internal func recordRoute( - 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.recordRoute( - request: request, - options: options, - onResponse: handleResponse - ) - } - - /// Call the "RouteChat" method. - /// - /// > Source IDL Documentation: - /// > - /// > A Bidirectional streaming RPC. - /// > - /// > Accepts a stream of RouteNotes sent while a route is being traversed, - /// > while receiving other RouteNotes (e.g. from other users). - /// - /// - 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`. - internal func routeChat( - 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.routeChat( - request: request, - options: options, - onResponse: handleResponse - ) - } -} \ No newline at end of file diff --git a/Examples/route-guide/Sources/Generated/route_guide.pb.swift b/Examples/route-guide/Sources/Generated/route_guide.pb.swift deleted file mode 100644 index 09892ef83..000000000 --- a/Examples/route-guide/Sources/Generated/route_guide.pb.swift +++ /dev/null @@ -1,387 +0,0 @@ -// DO NOT EDIT. -// swift-format-ignore-file -// swiftlint:disable all -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: route_guide.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/apple/swift-protobuf/ - -// Copyright 2015 gRPC authors. -// -// 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 SwiftProtobuf - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that you are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// Points are represented as latitude-longitude pairs in the E7 representation -/// (degrees multiplied by 10**7 and rounded to the nearest integer). -/// Latitudes should be in the range +/- 90 degrees and longitude should be in -/// the range +/- 180 degrees (inclusive). -struct Routeguide_Point: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - var latitude: Int32 = 0 - - var longitude: Int32 = 0 - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -/// A latitude-longitude rectangle, represented as two diagonally opposite -/// points "lo" and "hi". -struct Routeguide_Rectangle: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// One corner of the rectangle. - var lo: Routeguide_Point { - get {return _lo ?? Routeguide_Point()} - set {_lo = newValue} - } - /// Returns true if `lo` has been explicitly set. - var hasLo: Bool {return self._lo != nil} - /// Clears the value of `lo`. Subsequent reads from it will return its default value. - mutating func clearLo() {self._lo = nil} - - /// The other corner of the rectangle. - var hi: Routeguide_Point { - get {return _hi ?? Routeguide_Point()} - set {_hi = newValue} - } - /// Returns true if `hi` has been explicitly set. - var hasHi: Bool {return self._hi != nil} - /// Clears the value of `hi`. Subsequent reads from it will return its default value. - mutating func clearHi() {self._hi = nil} - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - - fileprivate var _lo: Routeguide_Point? = nil - fileprivate var _hi: Routeguide_Point? = nil -} - -/// A feature names something at a given point. -/// -/// If a feature could not be named, the name is empty. -struct Routeguide_Feature: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The name of the feature. - var name: String = String() - - /// The point where the feature is detected. - var location: Routeguide_Point { - get {return _location ?? Routeguide_Point()} - set {_location = newValue} - } - /// Returns true if `location` has been explicitly set. - var hasLocation: Bool {return self._location != nil} - /// Clears the value of `location`. Subsequent reads from it will return its default value. - mutating func clearLocation() {self._location = nil} - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - - fileprivate var _location: Routeguide_Point? = nil -} - -/// A RouteNote is a message sent while at a given point. -struct Routeguide_RouteNote: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The location from which the message is sent. - var location: Routeguide_Point { - get {return _location ?? Routeguide_Point()} - set {_location = newValue} - } - /// Returns true if `location` has been explicitly set. - var hasLocation: Bool {return self._location != nil} - /// Clears the value of `location`. Subsequent reads from it will return its default value. - mutating func clearLocation() {self._location = nil} - - /// The message to be sent. - var message: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - - fileprivate var _location: Routeguide_Point? = nil -} - -/// A RouteSummary is received in response to a RecordRoute rpc. -/// -/// It contains the number of individual points received, the number of -/// detected features, and the total distance covered as the cumulative sum of -/// the distance between each point. -struct Routeguide_RouteSummary: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The number of points received. - var pointCount: Int32 = 0 - - /// The number of known features passed while traversing the route. - var featureCount: Int32 = 0 - - /// The distance covered in metres. - var distance: Int32 = 0 - - /// The duration of the traversal in seconds. - var elapsedTime: Int32 = 0 - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "routeguide" - -extension Routeguide_Point: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".Point" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "latitude"), - 2: .same(proto: "longitude"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularInt32Field(value: &self.latitude) }() - case 2: try { try decoder.decodeSingularInt32Field(value: &self.longitude) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if self.latitude != 0 { - try visitor.visitSingularInt32Field(value: self.latitude, fieldNumber: 1) - } - if self.longitude != 0 { - try visitor.visitSingularInt32Field(value: self.longitude, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Routeguide_Point, rhs: Routeguide_Point) -> Bool { - if lhs.latitude != rhs.latitude {return false} - if lhs.longitude != rhs.longitude {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Routeguide_Rectangle: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".Rectangle" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "lo"), - 2: .same(proto: "hi"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularMessageField(value: &self._lo) }() - case 2: try { try decoder.decodeSingularMessageField(value: &self._hi) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - try { if let v = self._lo { - try visitor.visitSingularMessageField(value: v, fieldNumber: 1) - } }() - try { if let v = self._hi { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } }() - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Routeguide_Rectangle, rhs: Routeguide_Rectangle) -> Bool { - if lhs._lo != rhs._lo {return false} - if lhs._hi != rhs._hi {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Routeguide_Feature: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".Feature" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - 2: .same(proto: "location"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() - case 2: try { try decoder.decodeSingularMessageField(value: &self._location) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) - } - try { if let v = self._location { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } }() - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Routeguide_Feature, rhs: Routeguide_Feature) -> Bool { - if lhs.name != rhs.name {return false} - if lhs._location != rhs._location {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Routeguide_RouteNote: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".RouteNote" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "location"), - 2: .same(proto: "message"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularMessageField(value: &self._location) }() - case 2: try { try decoder.decodeSingularStringField(value: &self.message) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - try { if let v = self._location { - try visitor.visitSingularMessageField(value: v, fieldNumber: 1) - } }() - if !self.message.isEmpty { - try visitor.visitSingularStringField(value: self.message, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Routeguide_RouteNote, rhs: Routeguide_RouteNote) -> Bool { - if lhs._location != rhs._location {return false} - if lhs.message != rhs.message {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Routeguide_RouteSummary: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".RouteSummary" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "point_count"), - 2: .standard(proto: "feature_count"), - 3: .same(proto: "distance"), - 4: .standard(proto: "elapsed_time"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularInt32Field(value: &self.pointCount) }() - case 2: try { try decoder.decodeSingularInt32Field(value: &self.featureCount) }() - case 3: try { try decoder.decodeSingularInt32Field(value: &self.distance) }() - case 4: try { try decoder.decodeSingularInt32Field(value: &self.elapsedTime) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if self.pointCount != 0 { - try visitor.visitSingularInt32Field(value: self.pointCount, fieldNumber: 1) - } - if self.featureCount != 0 { - try visitor.visitSingularInt32Field(value: self.featureCount, fieldNumber: 2) - } - if self.distance != 0 { - try visitor.visitSingularInt32Field(value: self.distance, fieldNumber: 3) - } - if self.elapsedTime != 0 { - try visitor.visitSingularInt32Field(value: self.elapsedTime, fieldNumber: 4) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Routeguide_RouteSummary, rhs: Routeguide_RouteSummary) -> Bool { - if lhs.pointCount != rhs.pointCount {return false} - if lhs.featureCount != rhs.featureCount {return false} - if lhs.distance != rhs.distance {return false} - if lhs.elapsedTime != rhs.elapsedTime {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Examples/route-guide/Sources/Protos/grpc-swift-proto-generator-config.json b/Examples/route-guide/Sources/Protos/grpc-swift-proto-generator-config.json new file mode 100644 index 000000000..e6dda31fb --- /dev/null +++ b/Examples/route-guide/Sources/Protos/grpc-swift-proto-generator-config.json @@ -0,0 +1,7 @@ +{ + "generate": { + "clients": true, + "servers": true, + "messages": true + } +} diff --git a/Examples/route-guide/Sources/Protos/route_guide b/Examples/route-guide/Sources/Protos/route_guide new file mode 120000 index 000000000..fb9dc04e8 --- /dev/null +++ b/Examples/route-guide/Sources/Protos/route_guide @@ -0,0 +1 @@ +../../../../dev/protos/examples/route_guide \ No newline at end of file diff --git a/dev/protos/generate.sh b/dev/protos/generate.sh index 0dc5cabb4..a4409f1d2 100755 --- a/dev/protos/generate.sh +++ b/dev/protos/generate.sh @@ -71,52 +71,6 @@ function invoke_protoc { "$protoc" "$@" } -#- EXAMPLES ------------------------------------------------------------------- - -function generate_echo_example { - local proto="$here/examples/echo/echo.proto" - local output="$root/Examples/echo/Sources/Generated" - - generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" - generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" -} - -function generate_helloworld_example { - local proto="$here/upstream/grpc/examples/helloworld.proto" - local output="$root/Examples/hello-world/Sources/Generated" - - generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" - generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" -} - -function generate_routeguide_example { - local proto="$here/examples/route_guide/route_guide.proto" - local output="$root/Examples/route-guide/Sources/Generated" - - generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" - generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" -} - -function generate_error_details_example { - local proto="$here/upstream/grpc/examples/helloworld.proto" - local output="$root/Examples/error-details/Sources/Generated" - - generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" - generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" -} - -function generate_reflection_server_example { - local proto="$here/examples/echo/echo.proto" - local output="$root/Examples/reflection-server/Sources/Generated" - local pb_output="$root/Examples/reflection-server/Sources/DescriptorSets/echo.pb" - - generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" - generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" - invoke_protoc --descriptor_set_out="$pb_output" "$proto" -I "$(dirname "$proto")" \ - --include_source_info \ - --include_imports -} - #- TESTS ---------------------------------------------------------------------- function generate_service_config_for_tests { @@ -135,12 +89,5 @@ function generate_service_config_for_tests { #------------------------------------------------------------------------------ -# Generate examples -generate_echo_example -generate_helloworld_example -generate_routeguide_example -generate_error_details_example -generate_reflection_server_example - # Tests generate_service_config_for_tests