From 5216d5f4fcd6504bf5a60a5d271213df3d9df527 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Wed, 4 Dec 2024 09:40:32 +0000 Subject: [PATCH 1/7] Update examples and tutorials Motivation: We're going to tag beta.1 soon, so the examples and tutorials need to be updated to reflect this. Modifications: - Regenerate example code - Update example code to use new APIs - Update example manifests to use the as-yet-unreleased beta.1 tag of each dependency Result: Examples are up-to-date --- Examples/echo/Package.swift | 8 ++++---- Examples/hello-world/Package.swift | 8 ++++---- Examples/route-guide/Package.swift | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Examples/echo/Package.swift b/Examples/echo/Package.swift index 3792fcb04..8029be33f 100644 --- a/Examples/echo/Package.swift +++ b/Examples/echo/Package.swift @@ -21,10 +21,10 @@ let package = Package( name: "echo", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift", exact: "2.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf", exact: "1.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "1.0.0-alpha.1"), - .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), + .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "1.0.0-beta.1"), + .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ .executableTarget( diff --git a/Examples/hello-world/Package.swift b/Examples/hello-world/Package.swift index 5437aa7dc..2dd86b73e 100644 --- a/Examples/hello-world/Package.swift +++ b/Examples/hello-world/Package.swift @@ -21,10 +21,10 @@ let package = Package( name: "hello-world", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift", exact: "2.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf", exact: "1.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport", exact: "1.0.0-alpha.1"), - .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), + .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.1"), + .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ .executableTarget( diff --git a/Examples/route-guide/Package.swift b/Examples/route-guide/Package.swift index 7aba9a836..fa2554ed7 100644 --- a/Examples/route-guide/Package.swift +++ b/Examples/route-guide/Package.swift @@ -21,10 +21,10 @@ let package = Package( name: "route-guide", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift", exact: "2.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf", exact: "1.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport", exact: "1.0.0-alpha.1"), - .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), + .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.1"), + .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ .executableTarget( From 49b948896fbd4119a09ae9d74e46c6241daef088 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 25 Nov 2024 16:28:40 +0000 Subject: [PATCH 2/7] Regenerate examples --- .../echo/Sources/Generated/echo.grpc.swift | 982 ++++++++++---- .../Sources/Generated/helloworld.grpc.swift | 345 +++-- .../Sources/Generated/route_guide.grpc.swift | 1170 ++++++++++++----- 3 files changed, 1858 insertions(+), 639 deletions(-) diff --git a/Examples/echo/Sources/Generated/echo.grpc.swift b/Examples/echo/Sources/Generated/echo.grpc.swift index 88b929b9a..7ad44d1ce 100644 --- a/Examples/echo/Sources/Generated/echo.grpc.swift +++ b/Examples/echo/Sources/Generated/echo.grpc.swift @@ -23,42 +23,65 @@ import GRPCCore import GRPCProtobuf +import SwiftProtobuf +// MARK: - echo.Echo + +/// Namespace containing generated types for the "echo.Echo" service. internal enum Echo_Echo { - internal static let descriptor = GRPCCore.ServiceDescriptor.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: Echo_Echo.descriptor.fullyQualifiedService, + 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: Echo_Echo.descriptor.fullyQualifiedService, + 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: Echo_Echo.descriptor.fullyQualifiedService, + 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: Echo_Echo.descriptor.fullyQualifiedService, + 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, @@ -66,54 +89,265 @@ internal enum Echo_Echo { Update.descriptor ] } - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias StreamingServiceProtocol = Echo_Echo_StreamingServiceProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias ServiceProtocol = Echo_Echo_ServiceProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias ClientProtocol = Echo_Echo_ClientProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias Client = Echo_Echo_Client } extension GRPCCore.ServiceDescriptor { - internal static let echo_Echo = Self( - package: "echo", - service: "Echo" - ) + /// Service descriptor for the "echo.Echo" service. + internal static let echo_Echo = GRPCCore.ServiceDescriptor(fullyQualifiedService: "echo.Echo") } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Echo_Echo_StreamingServiceProtocol: GRPCCore.RegistrableRPCService { - /// Immediately returns an echo of a request. - func get( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Splits a request into words and returns each word in a stream of messages. - func expand( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Collects a stream of messages and returns them concatenated when the caller closes. - func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Streams back messages as they are received in an input stream. - func update( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse +// 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 + } } -/// Conformance to `GRPCCore.RegistrableRPCService`. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Default implementation of 'registerMethods(with:)'. extension Echo_Echo.StreamingServiceProtocol { - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) internal func registerMethods(with router: inout GRPCCore.RPCRouter) { router.registerHandler( forMethod: Echo_Echo.Method.Get.descriptor, @@ -162,35 +396,7 @@ extension Echo_Echo.StreamingServiceProtocol { } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Echo_Echo_ServiceProtocol: Echo_Echo.StreamingServiceProtocol { - /// Immediately returns an echo of a request. - func get( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// Splits a request into words and returns each word in a stream of messages. - func expand( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// Collects a stream of messages and returns them concatenated when the caller closes. - func collect( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// Streams back messages as they are received in an input stream. - func update( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse -} - -/// Partial conformance to `Echo_Echo_StreamingServiceProtocol`. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Default implementation of streaming methods from 'StreamingServiceProtocol'. extension Echo_Echo.ServiceProtocol { internal func get( request: GRPCCore.StreamingServerRequest, @@ -202,7 +408,7 @@ extension Echo_Echo.ServiceProtocol { ) return GRPCCore.StreamingServerResponse(single: response) } - + internal func expand( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext @@ -213,7 +419,7 @@ extension Echo_Echo.ServiceProtocol { ) return response } - + internal func collect( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext @@ -226,117 +432,457 @@ extension Echo_Echo.ServiceProtocol { } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Echo_Echo_ClientProtocol: Sendable { - /// Immediately returns an echo of a request. - func get( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R - ) async throws -> R where R: Sendable - - /// Splits a request into words and returns each word in a stream of messages. - func expand( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable - - /// Collects a stream of messages and returns them concatenated when the caller closes. - func collect( - request: GRPCCore.StreamingClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R - ) async throws -> R where R: Sendable - - /// Streams back messages as they are received in an input stream. - func update( - request: GRPCCore.StreamingClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable +// 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 { + 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 + ) + } + } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Helpers providing default arguments to 'ClientProtocol' methods. extension Echo_Echo.ClientProtocol { - internal func get( + /// 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, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message + onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in + try response.message } - ) async throws -> R where R: Sendable { + ) async throws -> Result where Result: Sendable { try await self.get( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, - body + onResponse: handleResponse ) } - - internal func expand( + + /// 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, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable { + 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, - body + onResponse: handleResponse ) } - - internal func collect( + + /// 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, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message + onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in + try response.message } - ) async throws -> R where R: Sendable { + ) async throws -> Result where Result: Sendable { try await self.collect( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, - body + onResponse: handleResponse ) } - - internal func update( + + /// 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, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable { + 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, - body + onResponse: handleResponse ) } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Helpers providing sugared APIs for 'ClientProtocol' methods. extension Echo_Echo.ClientProtocol { - /// Immediately returns an echo of a request. + /// 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 = { - try $0.message + onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in + try response.message } ) async throws -> Result where Result: Sendable { let request = GRPCCore.ClientRequest( @@ -346,11 +892,24 @@ extension Echo_Echo.ClientProtocol { return try await self.get( request: request, options: options, - handleResponse + onResponse: handleResponse ) } - - /// Splits a request into words and returns each word in a stream of messages. + + /// 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 = [:], @@ -364,130 +923,73 @@ extension Echo_Echo.ClientProtocol { return try await self.expand( request: request, options: options, - handleResponse + onResponse: handleResponse ) } - - /// Collects a stream of messages and returns them concatenated when the caller closes. + + /// 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: @Sendable @escaping (GRPCCore.RPCWriter) async throws -> Void, - onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { - try $0.message + 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: requestProducer + producer: producer ) return try await self.collect( request: request, options: options, - handleResponse + onResponse: handleResponse ) } - - /// Streams back messages as they are received in an input stream. + + /// 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: @Sendable @escaping (GRPCCore.RPCWriter) async throws -> Void, + 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: requestProducer + producer: producer ) return try await self.update( request: request, options: options, - handleResponse - ) - } -} - -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal struct Echo_Echo_Client: Echo_Echo.ClientProtocol { - private let client: GRPCCore.GRPCClient - - internal init(wrapping client: GRPCCore.GRPCClient) { - self.client = client - } - - /// Immediately returns an echo of a request. - internal func get( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message - } - ) async throws -> R where R: Sendable { - try await self.client.unary( - request: request, - descriptor: Echo_Echo.Method.Get.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body - ) - } - - /// Splits a request into words and returns each word in a stream of messages. - internal func expand( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable { - try await self.client.serverStreaming( - request: request, - descriptor: Echo_Echo.Method.Expand.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body - ) - } - - /// Collects a stream of messages and returns them concatenated when the caller closes. - internal func collect( - request: GRPCCore.StreamingClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message - } - ) async throws -> R where R: Sendable { - try await self.client.clientStreaming( - request: request, - descriptor: Echo_Echo.Method.Collect.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body - ) - } - - /// Streams back messages as they are received in an input stream. - internal func update( - request: GRPCCore.StreamingClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable { - try await self.client.bidirectionalStreaming( - request: request, - descriptor: Echo_Echo.Method.Update.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body + onResponse: handleResponse ) } } \ 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 index bc729483a..e64bc3e95 100644 --- a/Examples/hello-world/Sources/Generated/helloworld.grpc.swift +++ b/Examples/hello-world/Sources/Generated/helloworld.grpc.swift @@ -23,53 +23,140 @@ import GRPCCore import GRPCProtobuf +import SwiftProtobuf +// MARK: - helloworld.Greeter + +/// Namespace containing generated types for the "helloworld.Greeter" service. internal enum Helloworld_Greeter { - internal static let descriptor = GRPCCore.ServiceDescriptor.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: Helloworld_Greeter.descriptor.fullyQualifiedService, + 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 ] } - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias StreamingServiceProtocol = Helloworld_Greeter_StreamingServiceProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias ServiceProtocol = Helloworld_Greeter_ServiceProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias ClientProtocol = Helloworld_Greeter_ClientProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias Client = Helloworld_Greeter_Client } extension GRPCCore.ServiceDescriptor { - internal static let helloworld_Greeter = Self( - package: "helloworld", - service: "Greeter" - ) + /// Service descriptor for the "helloworld.Greeter" service. + internal static let helloworld_Greeter = GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter") } -/// The greeting service definition. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Helloworld_Greeter_StreamingServiceProtocol: GRPCCore.RegistrableRPCService { - /// Sends a greeting - func sayHello( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse +// 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 + } } -/// Conformance to `GRPCCore.RegistrableRPCService`. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Default implementation of 'registerMethods(with:)'. extension Helloworld_Greeter.StreamingServiceProtocol { - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) internal func registerMethods(with router: inout GRPCCore.RPCRouter) { router.registerHandler( forMethod: Helloworld_Greeter.Method.SayHello.descriptor, @@ -85,18 +172,7 @@ extension Helloworld_Greeter.StreamingServiceProtocol { } } -/// The greeting service definition. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Helloworld_Greeter_ServiceProtocol: Helloworld_Greeter.StreamingServiceProtocol { - /// Sends a greeting - func sayHello( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse -} - -/// Partial conformance to `Helloworld_Greeter_StreamingServiceProtocol`. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Default implementation of streaming methods from 'StreamingServiceProtocol'. extension Helloworld_Greeter.ServiceProtocol { internal func sayHello( request: GRPCCore.StreamingServerRequest, @@ -110,47 +186,168 @@ extension Helloworld_Greeter.ServiceProtocol { } } -/// The greeting service definition. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Helloworld_Greeter_ClientProtocol: Sendable { - /// Sends a greeting - func sayHello( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R - ) async throws -> R where R: Sendable +// 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: [:] + ) + } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// 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 { + 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 { - internal func sayHello( + /// 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, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message + onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in + try response.message } - ) async throws -> R where R: Sendable { + ) async throws -> Result where Result: Sendable { try await self.sayHello( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, - body + onResponse: handleResponse ) } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Helpers providing sugared APIs for 'ClientProtocol' methods. extension Helloworld_Greeter.ClientProtocol { - /// Sends a greeting + /// 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 = { - try $0.message + onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in + try response.message } ) async throws -> Result where Result: Sendable { let request = GRPCCore.ClientRequest( @@ -160,37 +357,7 @@ extension Helloworld_Greeter.ClientProtocol { return try await self.sayHello( request: request, options: options, - handleResponse - ) - } -} - -/// The greeting service definition. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal struct Helloworld_Greeter_Client: Helloworld_Greeter.ClientProtocol { - private let client: GRPCCore.GRPCClient - - internal init(wrapping client: GRPCCore.GRPCClient) { - self.client = client - } - - /// Sends a greeting - internal func sayHello( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message - } - ) async throws -> R where R: Sendable { - try await self.client.unary( - request: request, - descriptor: Helloworld_Greeter.Method.SayHello.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body + onResponse: handleResponse ) } } \ No newline at end of file diff --git a/Examples/route-guide/Sources/Generated/route_guide.grpc.swift b/Examples/route-guide/Sources/Generated/route_guide.grpc.swift index 2468fd7d7..7971c54e1 100644 --- a/Examples/route-guide/Sources/Generated/route_guide.grpc.swift +++ b/Examples/route-guide/Sources/Generated/route_guide.grpc.swift @@ -23,42 +23,65 @@ import GRPCCore import GRPCProtobuf +import SwiftProtobuf +// MARK: - routeguide.RouteGuide + +/// Namespace containing generated types for the "routeguide.RouteGuide" service. internal enum Routeguide_RouteGuide { - internal static let descriptor = GRPCCore.ServiceDescriptor.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: Routeguide_RouteGuide.descriptor.fullyQualifiedService, + 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: Routeguide_RouteGuide.descriptor.fullyQualifiedService, + 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: Routeguide_RouteGuide.descriptor.fullyQualifiedService, + 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: Routeguide_RouteGuide.descriptor.fullyQualifiedService, + 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, @@ -66,71 +89,325 @@ internal enum Routeguide_RouteGuide { RouteChat.descriptor ] } - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias StreamingServiceProtocol = Routeguide_RouteGuide_StreamingServiceProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias ServiceProtocol = Routeguide_RouteGuide_ServiceProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias ClientProtocol = Routeguide_RouteGuide_ClientProtocol - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) - internal typealias Client = Routeguide_RouteGuide_Client } extension GRPCCore.ServiceDescriptor { - internal static let routeguide_RouteGuide = Self( - package: "routeguide", - service: "RouteGuide" - ) + /// Service descriptor for the "routeguide.RouteGuide" service. + internal static let routeguide_RouteGuide = GRPCCore.ServiceDescriptor(fullyQualifiedService: "routeguide.RouteGuide") } -/// Interface exported by the server. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Routeguide_RouteGuide_StreamingServiceProtocol: GRPCCore.RegistrableRPCService { - /// A simple RPC. +// MARK: routeguide.RouteGuide (server) + +extension Routeguide_RouteGuide { + /// Streaming variant of the service protocol for the "routeguide.RouteGuide" service. /// - /// Obtains the feature at a given position. + /// 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. /// - /// A feature with an empty name is returned if there's no feature at the given - /// position. - func getFeature( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// A server-to-client streaming RPC. + /// Where possible, prefer using the stricter, less-verbose ``ServiceProtocol`` + /// or ``SimpleServiceProtocol`` instead. /// - /// 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. - func listFeatures( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// A client-to-server streaming RPC. + /// > 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. /// - /// Accepts a stream of Points on a route being traversed, returning a - /// RouteSummary when traversal is completed. - func recordRoute( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// A Bidirectional streaming RPC. + /// 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``. /// - /// Accepts a stream of RouteNotes sent while a route is being traversed, - /// while receiving other RouteNotes (e.g. from other users). - func routeChat( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse + /// > 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 + } } -/// Conformance to `GRPCCore.RegistrableRPCService`. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Default implementation of 'registerMethods(with:)'. extension Routeguide_RouteGuide.StreamingServiceProtocol { - @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) internal func registerMethods(with router: inout GRPCCore.RPCRouter) { router.registerHandler( forMethod: Routeguide_RouteGuide.Method.GetFeature.descriptor, @@ -179,52 +456,7 @@ extension Routeguide_RouteGuide.StreamingServiceProtocol { } } -/// Interface exported by the server. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Routeguide_RouteGuide_ServiceProtocol: Routeguide_RouteGuide.StreamingServiceProtocol { - /// 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. - func getFeature( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// 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. - func listFeatures( - request: GRPCCore.ServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse - - /// A client-to-server streaming RPC. - /// - /// Accepts a stream of Points on a route being traversed, returning a - /// RouteSummary when traversal is completed. - func recordRoute( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.ServerResponse - - /// 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). - func routeChat( - request: GRPCCore.StreamingServerRequest, - context: GRPCCore.ServerContext - ) async throws -> GRPCCore.StreamingServerResponse -} - -/// Partial conformance to `Routeguide_RouteGuide_StreamingServiceProtocol`. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Default implementation of streaming methods from 'StreamingServiceProtocol'. extension Routeguide_RouteGuide.ServiceProtocol { internal func getFeature( request: GRPCCore.StreamingServerRequest, @@ -236,7 +468,7 @@ extension Routeguide_RouteGuide.ServiceProtocol { ) return GRPCCore.StreamingServerResponse(single: response) } - + internal func listFeatures( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext @@ -247,7 +479,7 @@ extension Routeguide_RouteGuide.ServiceProtocol { ) return response } - + internal func recordRoute( request: GRPCCore.StreamingServerRequest, context: GRPCCore.ServerContext @@ -260,139 +492,518 @@ extension Routeguide_RouteGuide.ServiceProtocol { } } -/// Interface exported by the server. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal protocol Routeguide_RouteGuide_ClientProtocol: Sendable { - /// A simple RPC. - /// - /// Obtains the feature at a given position. +// 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. /// - /// A feature with an empty name is returned if there's no feature at the given - /// position. - func getFeature( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R - ) async throws -> R where R: Sendable - - /// A server-to-client streaming RPC. + /// You don't need to implement this protocol directly, use the generated + /// implementation, ``Client``. /// - /// 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. - func listFeatures( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable - - /// A client-to-server streaming RPC. + /// > 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. /// - /// Accepts a stream of Points on a route being traversed, returning a - /// RouteSummary when traversal is completed. - func recordRoute( - request: GRPCCore.StreamingClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R - ) async throws -> R where R: Sendable - - /// A Bidirectional streaming RPC. + /// 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. /// - /// Accepts a stream of RouteNotes sent while a route is being traversed, - /// while receiving other RouteNotes (e.g. from other users). - func routeChat( - request: GRPCCore.StreamingClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable + /// > Source IDL Documentation: + /// > + /// > Interface exported by the server. + internal struct Client: ClientProtocol { + private let client: GRPCCore.GRPCClient + + /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`. + /// + /// - Parameters: + /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service. + 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 + ) + } + } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Helpers providing default arguments to 'ClientProtocol' methods. extension Routeguide_RouteGuide.ClientProtocol { - internal func getFeature( + /// 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, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message + onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in + try response.message } - ) async throws -> R where R: Sendable { + ) async throws -> Result where Result: Sendable { try await self.getFeature( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, - body + onResponse: handleResponse ) } - - internal func listFeatures( + + /// 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, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable { + 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, - body + onResponse: handleResponse ) } - - internal func recordRoute( + + /// 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, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message + onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in + try response.message } - ) async throws -> R where R: Sendable { + ) async throws -> Result where Result: Sendable { try await self.recordRoute( request: request, serializer: GRPCProtobuf.ProtobufSerializer(), deserializer: GRPCProtobuf.ProtobufDeserializer(), options: options, - body + onResponse: handleResponse ) } - - internal func routeChat( + + /// 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, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable { + 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, - body + onResponse: handleResponse ) } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) +// Helpers providing sugared APIs for 'ClientProtocol' methods. extension Routeguide_RouteGuide.ClientProtocol { - /// A simple RPC. + /// Call the "GetFeature" method. /// - /// Obtains the feature at a given position. + /// > 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. /// - /// 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 = { - try $0.message + onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { response in + try response.message } ) async throws -> Result where Result: Sendable { let request = GRPCCore.ClientRequest( @@ -402,16 +1013,29 @@ extension Routeguide_RouteGuide.ClientProtocol { return try await self.getFeature( request: request, options: options, - handleResponse + onResponse: handleResponse ) } - - /// A server-to-client streaming RPC. + + /// 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. /// - /// 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 = [:], @@ -425,153 +1049,79 @@ extension Routeguide_RouteGuide.ClientProtocol { return try await self.listFeatures( request: request, options: options, - handleResponse + onResponse: handleResponse ) } - - /// A client-to-server streaming RPC. + + /// 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. /// - /// 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: @Sendable @escaping (GRPCCore.RPCWriter) async throws -> Void, - onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> Result = { - try $0.message + 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: requestProducer + producer: producer ) return try await self.recordRoute( request: request, options: options, - handleResponse + onResponse: handleResponse ) } - - /// A Bidirectional streaming RPC. + + /// Call the "RouteChat" method. /// - /// Accepts a stream of RouteNotes sent while a route is being traversed, - /// while receiving other RouteNotes (e.g. from other users). + /// > 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: @Sendable @escaping (GRPCCore.RPCWriter) async throws -> Void, + 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: requestProducer + producer: producer ) return try await self.routeChat( request: request, options: options, - handleResponse - ) - } -} - -/// Interface exported by the server. -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) -internal struct Routeguide_RouteGuide_Client: Routeguide_RouteGuide.ClientProtocol { - private let client: GRPCCore.GRPCClient - - internal init(wrapping client: GRPCCore.GRPCClient) { - self.client = client - } - - /// 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. - internal func getFeature( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message - } - ) async throws -> R where R: Sendable { - try await self.client.unary( - request: request, - descriptor: Routeguide_RouteGuide.Method.GetFeature.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body - ) - } - - /// 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. - internal func listFeatures( - request: GRPCCore.ClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable { - try await self.client.serverStreaming( - request: request, - descriptor: Routeguide_RouteGuide.Method.ListFeatures.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body - ) - } - - /// A client-to-server streaming RPC. - /// - /// Accepts a stream of Points on a route being traversed, returning a - /// RouteSummary when traversal is completed. - internal func recordRoute( - request: GRPCCore.StreamingClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.ClientResponse) async throws -> R = { - try $0.message - } - ) async throws -> R where R: Sendable { - try await self.client.clientStreaming( - request: request, - descriptor: Routeguide_RouteGuide.Method.RecordRoute.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body - ) - } - - /// 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). - internal func routeChat( - request: GRPCCore.StreamingClientRequest, - serializer: some GRPCCore.MessageSerializer, - deserializer: some GRPCCore.MessageDeserializer, - options: GRPCCore.CallOptions = .defaults, - _ body: @Sendable @escaping (GRPCCore.StreamingClientResponse) async throws -> R - ) async throws -> R where R: Sendable { - try await self.client.bidirectionalStreaming( - request: request, - descriptor: Routeguide_RouteGuide.Method.RouteChat.descriptor, - serializer: serializer, - deserializer: deserializer, - options: options, - handler: body + onResponse: handleResponse ) } } \ No newline at end of file From ac7afbcfb80099d21350287f2b6aa064fa2be9eb Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 25 Nov 2024 16:33:15 +0000 Subject: [PATCH 3/7] Update hello-world --- Examples/hello-world/Sources/Subcommands/Greet.swift | 4 ++-- Examples/hello-world/Sources/Subcommands/Serve.swift | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Examples/hello-world/Sources/Subcommands/Greet.swift b/Examples/hello-world/Sources/Subcommands/Greet.swift index cd005534a..cf5d73a8d 100644 --- a/Examples/hello-world/Sources/Subcommands/Greet.swift +++ b/Examples/hello-world/Sources/Subcommands/Greet.swift @@ -33,7 +33,7 @@ struct Greet: AsyncParsableCommand { let client = GRPCClient( transport: try .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: self.port), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) @@ -45,7 +45,7 @@ struct Greet: AsyncParsableCommand { client.beginGracefulShutdown() } - let greeter = Helloworld_Greeter_Client(wrapping: client) + let greeter = Helloworld_Greeter.Client(wrapping: client) let reply = try await greeter.sayHello(.with { $0.name = self.name }) print(reply.message) } diff --git a/Examples/hello-world/Sources/Subcommands/Serve.swift b/Examples/hello-world/Sources/Subcommands/Serve.swift index d65483865..caf801ae4 100644 --- a/Examples/hello-world/Sources/Subcommands/Serve.swift +++ b/Examples/hello-world/Sources/Subcommands/Serve.swift @@ -29,7 +29,7 @@ struct Serve: AsyncParsableCommand { let server = GRPCServer( transport: .http2NIOPosix( address: .ipv4(host: "127.0.0.1", port: self.port), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ), services: [Greeter()] ) @@ -43,14 +43,14 @@ struct Serve: AsyncParsableCommand { } } -struct Greeter: Helloworld_Greeter_ServiceProtocol { +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { func sayHello( - request: ServerRequest, + request: Helloworld_HelloRequest, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Helloworld_HelloReply { var reply = Helloworld_HelloReply() - let recipient = request.message.name.isEmpty ? "stranger" : request.message.name + let recipient = request.name.isEmpty ? "stranger" : request.name reply.message = "Hello, \(recipient)" - return ServerResponse(message: reply) + return reply } } From a34a63f8442cce66338e11bfec82d6d8e72ceb45 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 25 Nov 2024 16:37:36 +0000 Subject: [PATCH 4/7] Update echo --- .../echo/Sources/Subcommands/Collect.swift | 4 +- .../echo/Sources/Subcommands/Expand.swift | 4 +- Examples/echo/Sources/Subcommands/Get.swift | 4 +- Examples/echo/Sources/Subcommands/Serve.swift | 44 +++++++++---------- .../echo/Sources/Subcommands/Update.swift | 4 +- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/Examples/echo/Sources/Subcommands/Collect.swift b/Examples/echo/Sources/Subcommands/Collect.swift index d105237c3..281ae9d35 100644 --- a/Examples/echo/Sources/Subcommands/Collect.swift +++ b/Examples/echo/Sources/Subcommands/Collect.swift @@ -30,7 +30,7 @@ struct Collect: AsyncParsableCommand { let client = GRPCClient( transport: try .http2NIOPosix( target: self.arguments.target, - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) @@ -39,7 +39,7 @@ struct Collect: AsyncParsableCommand { try await client.run() } - let echo = Echo_Echo_Client(wrapping: client) + let echo = Echo_Echo.Client(wrapping: client) for _ in 0 ..< self.arguments.repetitions { let message = try await echo.collect { writer in diff --git a/Examples/echo/Sources/Subcommands/Expand.swift b/Examples/echo/Sources/Subcommands/Expand.swift index 72285dc08..c30b481ef 100644 --- a/Examples/echo/Sources/Subcommands/Expand.swift +++ b/Examples/echo/Sources/Subcommands/Expand.swift @@ -30,7 +30,7 @@ struct Expand: AsyncParsableCommand { let client = GRPCClient( transport: try .http2NIOPosix( target: self.arguments.target, - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) @@ -39,7 +39,7 @@ struct Expand: AsyncParsableCommand { try await client.run() } - let echo = Echo_Echo_Client(wrapping: client) + let echo = Echo_Echo.Client(wrapping: client) for _ in 0 ..< self.arguments.repetitions { let message = Echo_EchoRequest.with { $0.text = self.arguments.message } diff --git a/Examples/echo/Sources/Subcommands/Get.swift b/Examples/echo/Sources/Subcommands/Get.swift index 242e4b0a1..9a1953628 100644 --- a/Examples/echo/Sources/Subcommands/Get.swift +++ b/Examples/echo/Sources/Subcommands/Get.swift @@ -28,7 +28,7 @@ struct Get: AsyncParsableCommand { let client = GRPCClient( transport: try .http2NIOPosix( target: self.arguments.target, - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) @@ -37,7 +37,7 @@ struct Get: AsyncParsableCommand { try await client.run() } - let echo = Echo_Echo_Client(wrapping: client) + let echo = Echo_Echo.Client(wrapping: client) for _ in 0 ..< self.arguments.repetitions { let message = Echo_EchoRequest.with { $0.text = self.arguments.message } diff --git a/Examples/echo/Sources/Subcommands/Serve.swift b/Examples/echo/Sources/Subcommands/Serve.swift index 4e12baa5d..6bbb9ea82 100644 --- a/Examples/echo/Sources/Subcommands/Serve.swift +++ b/Examples/echo/Sources/Subcommands/Serve.swift @@ -28,7 +28,7 @@ struct Serve: AsyncParsableCommand { let server = GRPCServer( transport: .http2NIOPosix( address: .ipv4(host: "127.0.0.1", port: self.port), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ), services: [EchoService()] ) @@ -42,44 +42,40 @@ struct Serve: AsyncParsableCommand { } } -struct EchoService: Echo_Echo_ServiceProtocol { +struct EchoService: Echo_Echo.SimpleServiceProtocol { func get( - request: ServerRequest, + request: Echo_EchoRequest, context: ServerContext - ) async throws -> ServerResponse { - return ServerResponse(message: .with { $0.text = request.message.text }) + ) async throws -> Echo_EchoResponse { + return .with { $0.text = request.text } } func collect( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { - let messages = try await request.messages.reduce(into: []) { $0.append($1.text) } + ) async throws -> Echo_EchoResponse { + let messages = try await request.reduce(into: []) { $0.append($1.text) } let joined = messages.joined(separator: " ") - return ServerResponse(message: .with { $0.text = joined }) + return .with { $0.text = joined } } func expand( - request: ServerRequest, + request: Echo_EchoRequest, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - let parts = request.message.text.split(separator: " ") - let messages = parts.map { part in Echo_EchoResponse.with { $0.text = String(part) } } - try await writer.write(contentsOf: messages) - return [:] - } + ) async throws { + let parts = request.text.split(separator: " ") + let messages = parts.map { part in Echo_EchoResponse.with { $0.text = String(part) } } + try await response.write(contentsOf: messages) } func update( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - for try await message in request.messages { - try await writer.write(.with { $0.text = message.text }) - } - return [:] + ) async throws { + for try await message in request { + try await response.write(.with { $0.text = message.text }) } } } diff --git a/Examples/echo/Sources/Subcommands/Update.swift b/Examples/echo/Sources/Subcommands/Update.swift index 2166a6aa1..8e8cb664f 100644 --- a/Examples/echo/Sources/Subcommands/Update.swift +++ b/Examples/echo/Sources/Subcommands/Update.swift @@ -30,7 +30,7 @@ struct Update: AsyncParsableCommand { let client = GRPCClient( transport: try .http2NIOPosix( target: self.arguments.target, - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) @@ -39,7 +39,7 @@ struct Update: AsyncParsableCommand { try await client.run() } - let echo = Echo_Echo_Client(wrapping: client) + let echo = Echo_Echo.Client(wrapping: client) for _ in 0 ..< self.arguments.repetitions { try await echo.update { writer in From 9c76fa71475c1cbd4b731aa8f731e03d91ac9e87 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 25 Nov 2024 16:42:33 +0000 Subject: [PATCH 5/7] Update route-guide --- .../Sources/Subcommands/GetFeature.swift | 4 +- .../Sources/Subcommands/ListFeatures.swift | 4 +- .../Sources/Subcommands/RecordRoute.swift | 4 +- .../Sources/Subcommands/RouteChat.swift | 4 +- .../Sources/Subcommands/Serve.swift | 58 +++++++++---------- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/Examples/route-guide/Sources/Subcommands/GetFeature.swift b/Examples/route-guide/Sources/Subcommands/GetFeature.swift index 890d432cd..eb58eeff3 100644 --- a/Examples/route-guide/Sources/Subcommands/GetFeature.swift +++ b/Examples/route-guide/Sources/Subcommands/GetFeature.swift @@ -39,7 +39,7 @@ struct GetFeature: AsyncParsableCommand { func run() async throws { let transport = try HTTP2ClientTransport.Posix( target: .ipv4(host: "127.0.0.1", port: self.port), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) let client = GRPCClient(transport: transport) @@ -48,7 +48,7 @@ struct GetFeature: AsyncParsableCommand { try await client.run() } - let routeGuide = Routeguide_RouteGuide_Client(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) let point = Routeguide_Point.with { $0.latitude = self.latitude diff --git a/Examples/route-guide/Sources/Subcommands/ListFeatures.swift b/Examples/route-guide/Sources/Subcommands/ListFeatures.swift index e2d1a5f5c..32db2d0c1 100644 --- a/Examples/route-guide/Sources/Subcommands/ListFeatures.swift +++ b/Examples/route-guide/Sources/Subcommands/ListFeatures.swift @@ -53,7 +53,7 @@ struct ListFeatures: AsyncParsableCommand { func run() async throws { let transport = try HTTP2ClientTransport.Posix( target: .ipv4(host: "127.0.0.1", port: self.port), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) let client = GRPCClient(transport: transport) @@ -62,7 +62,7 @@ struct ListFeatures: AsyncParsableCommand { try await client.run() } - let routeGuide = Routeguide_RouteGuide_Client(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) let boundingRectangle = Routeguide_Rectangle.with { $0.lo.latitude = self.minLatitude $0.hi.latitude = self.maxLatitude diff --git a/Examples/route-guide/Sources/Subcommands/RecordRoute.swift b/Examples/route-guide/Sources/Subcommands/RecordRoute.swift index e6d1611f1..bc3f4f9dc 100644 --- a/Examples/route-guide/Sources/Subcommands/RecordRoute.swift +++ b/Examples/route-guide/Sources/Subcommands/RecordRoute.swift @@ -32,7 +32,7 @@ struct RecordRoute: AsyncParsableCommand { func run() async throws { let transport = try HTTP2ClientTransport.Posix( target: .ipv4(host: "127.0.0.1", port: self.port), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) let client = GRPCClient(transport: transport) @@ -41,7 +41,7 @@ struct RecordRoute: AsyncParsableCommand { try await client.run() } - let routeGuide = Routeguide_RouteGuide_Client(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) // Get all features. let rectangle = Routeguide_Rectangle.with { diff --git a/Examples/route-guide/Sources/Subcommands/RouteChat.swift b/Examples/route-guide/Sources/Subcommands/RouteChat.swift index d25352662..2a4c23b16 100644 --- a/Examples/route-guide/Sources/Subcommands/RouteChat.swift +++ b/Examples/route-guide/Sources/Subcommands/RouteChat.swift @@ -32,7 +32,7 @@ struct RouteChat: AsyncParsableCommand { func run() async throws { let transport = try HTTP2ClientTransport.Posix( target: .ipv4(host: "127.0.0.1", port: self.port), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) let client = GRPCClient(transport: transport) @@ -41,7 +41,7 @@ struct RouteChat: AsyncParsableCommand { try await client.run() } - let routeGuide = Routeguide_RouteGuide_Client(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) try await routeGuide.routeChat { writer in let notes: [(String, (Int32, Int32))] = [ diff --git a/Examples/route-guide/Sources/Subcommands/Serve.swift b/Examples/route-guide/Sources/Subcommands/Serve.swift index 8651346d4..066d8e396 100644 --- a/Examples/route-guide/Sources/Subcommands/Serve.swift +++ b/Examples/route-guide/Sources/Subcommands/Serve.swift @@ -40,7 +40,7 @@ struct Serve: AsyncParsableCommand { let features = try self.loadFeatures() let transport = HTTP2ServerTransport.Posix( address: .ipv4(host: "127.0.0.1", port: self.port), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) let server = GRPCServer(transport: transport, services: [RouteGuideService(features: features)]) @@ -99,56 +99,54 @@ struct RouteGuideService { } } -extension RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +extension RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { let feature = self.findFeature( - latitude: request.message.latitude, - longitude: request.message.longitude + latitude: request.latitude, + longitude: request.longitude ) if let feature { - return ServerResponse(message: feature) + return feature } else { // No feature: return a feature with an empty name. let unknownFeature = Routeguide_Feature.with { $0.name = "" $0.location = .with { - $0.latitude = request.message.latitude - $0.longitude = request.message.longitude + $0.latitude = request.latitude + $0.longitude = request.longitude } } - return ServerResponse(message: unknownFeature) + return unknownFeature } } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - let featuresWithinBounds = self.features.filter { feature in - !feature.name.isEmpty && feature.isContained(by: request.message) - } - - try await writer.write(contentsOf: featuresWithinBounds) - return [:] + ) async throws { + let featuresWithinBounds = self.features.filter { feature in + !feature.name.isEmpty && feature.isContained(by: request) } + + try await response.write(contentsOf: featuresWithinBounds) } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { let startTime = ContinuousClock.now var pointsVisited = 0 var featuresVisited = 0 var distanceTravelled = 0.0 var previousPoint: Routeguide_Point? = nil - for try await point in request.messages { + for try await point in request { pointsVisited += 1 if self.findFeature(latitude: point.latitude, longitude: point.longitude) != nil { @@ -170,19 +168,17 @@ extension RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.distance = Int32(distanceTravelled) } - return ServerResponse(message: summary) + return summary } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - for try await note in request.messages { - let notes = self.receivedNotes.recordNote(note) - try await writer.write(contentsOf: notes) - } - return [:] + ) async throws { + for try await note in request { + let notes = self.receivedNotes.recordNote(note) + try await response.write(contentsOf: notes) } } } From bd779a3dbde43593507e50d32b0aa4d29dc7f97f Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 25 Nov 2024 16:45:01 +0000 Subject: [PATCH 6/7] Update hello-world tutorial --- .../Tutorials/Hello-World/Hello-World.tutorial | 2 +- .../Resources/hello-world-sec04-step01.swift | 8 ++++---- .../Resources/hello-world-sec04-step02.swift | 14 +++++++------- .../Resources/hello-world-sec04-step03.swift | 2 +- .../Resources/hello-world-sec04-step04.swift | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial index e3e4241a4..6a056d47f 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial @@ -18,7 +18,7 @@ repository by running the following command in a terminal: ```console - git clone https://github.com/grpc/grpc-swift + git clone --branch 2.0.0-beta.1 https://github.com/grpc/grpc-swift ``` You then need to change directory to the `Examples/hello-world` directory of the cloned diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step01.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step01.swift index b4b20841a..c7ab21adc 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step01.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step01.swift @@ -1,11 +1,11 @@ -struct Greeter: Helloworld_GreeterServiceProtocol { +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { func sayHello( - request: ServerRequest, + request: Helloworld_HelloRequest, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Helloworld_HelloReply { var reply = Helloworld_HelloReply() let recipient = request.message.name.isEmpty ? "stranger" : request.message.name reply.message = "Hello, \(recipient)" - return ServerResponse(message: reply) + return reply } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step02.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step02.swift index 9ecccd975..a2e4fba28 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step02.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step02.swift @@ -1,21 +1,21 @@ -struct Greeter: Helloworld_GreeterServiceProtocol { +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { func sayHello( - request: ServerRequest, + request: Helloworld_HelloRequest, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Helloworld_HelloReply { var reply = Helloworld_HelloReply() let recipient = request.message.name.isEmpty ? "stranger" : request.message.name reply.message = "Hello, \(recipient)" - return ServerResponse(message: reply) + return reply } func sayHelloAgain( - request: ServerRequest, + request: Helloworld_HelloRequest, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Helloworld_HelloReply { var reply = Helloworld_HelloReply() let recipient = request.message.name.isEmpty ? "stranger" : request.message.name reply.message = "Hello again, \(recipient)" - return ServerResponse(message: reply) + return reply } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step03.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step03.swift index 4e10d4adc..23b644f0c 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step03.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step03.swift @@ -1,3 +1,3 @@ -let greeter = Helloworld_GreeterClient(wrapping: client) +let greeter = Helloworld_Greeter.Client(wrapping: client) let reply = try await greeter.sayHello(.with { $0.name = self.name }) print(reply.message) diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step04.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step04.swift index 534a4fb8a..34fb040f1 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step04.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Resources/hello-world-sec04-step04.swift @@ -1,4 +1,4 @@ -let greeter = Helloworld_GreeterClient(wrapping: client) +let greeter = Helloworld_Greeter.Client(wrapping: client) let reply = try await greeter.sayHello(.with { $0.name = self.name }) print(reply.message) From 752ca351017b8261136edecec324c78fee09c7c7 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 25 Nov 2024 17:02:35 +0000 Subject: [PATCH 7/7] Update route-guide tutorial --- ...route-guide-sec01-step07-description.swift | 5 +- ...route-guide-sec01-step08-description.swift | 5 +- .../route-guide-sec04-step01-struct.swift | 2 +- ...ute-guide-sec04-step02-unimplemented.swift | 20 ++--- .../route-guide-sec04-step03-features.swift | 20 ++--- .../route-guide-sec04-step04-unary.swift | 20 ++--- .../route-guide-sec04-step05-unary.swift | 24 +++--- ...-guide-sec04-step06-server-streaming.swift | 32 ++++---- ...-guide-sec04-step07-server-streaming.swift | 79 ------------------- ...-guide-sec04-step08-client-streaming.swift | 38 +++++---- ...te-guide-sec04-step09-bidi-streaming.swift | 68 +++++----------- ...te-guide-sec04-step10-bidi-streaming.swift | 77 +++++------------- .../route-guide-sec05-step00-package.swift | 4 +- .../route-guide-sec05-step01-package.swift | 5 +- .../route-guide-sec05-step02-package.swift | 5 +- .../route-guide-sec05-step07-server.swift | 2 +- .../route-guide-sec05-step08-run.swift | 2 +- ...ute-guide-sec06-step03-create-client.swift | 2 +- .../route-guide-sec06-step04-run-client.swift | 2 +- .../route-guide-sec06-step05-stub.swift | 4 +- ...route-guide-sec06-step06-get-feature.swift | 6 +- ...ute-guide-sec06-step07-list-features.swift | 8 +- ...oute-guide-sec06-step08-record-route.swift | 10 +-- .../route-guide-sec06-step09-route-chat.swift | 12 +-- .../Route-Guide/Route-Guide.tutorial | 46 ++++------- 25 files changed, 174 insertions(+), 324 deletions(-) delete mode 100644 Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step07-server-streaming.swift diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift index f475a700c..d7116586e 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift @@ -5,8 +5,9 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-alpha.1"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.1"), ], targets: [] ) diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift index 65a51d4b9..462edb8d6 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift @@ -5,8 +5,9 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-alpha.1"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.1"), ], targets: [ .executableTarget( diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step01-struct.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step01-struct.swift index 65aa33cb2..141e47735 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step01-struct.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step01-struct.swift @@ -1,4 +1,4 @@ import GRPCCore -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step02-unimplemented.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step02-unimplemented.swift index 283c9a8fb..bd5d7724c 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step02-unimplemented.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step02-unimplemented.swift @@ -1,27 +1,29 @@ import GRPCCore -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step03-features.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step03-features.swift index 84ce31e89..f66682fb0 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step03-features.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step03-features.swift @@ -1,6 +1,6 @@ import GRPCCore -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { /// Known features. private let features: [Routeguide_Feature] @@ -11,26 +11,28 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { } func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step04-unary.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step04-unary.swift index cf1b88e21..75a19a7ec 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step04-unary.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step04-unary.swift @@ -1,6 +1,6 @@ import GRPCCore -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { /// Known features. private let features: [Routeguide_Feature] @@ -18,9 +18,9 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { } func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { let feature = self.findFeature( latitude: request.message.latitude, longitude: request.message.longitude @@ -28,20 +28,22 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step05-unary.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step05-unary.swift index dcbde29fa..d23cc14e2 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step05-unary.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step05-unary.swift @@ -1,6 +1,6 @@ import GRPCCore -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { /// Known features. private let features: [Routeguide_Feature] @@ -18,16 +18,16 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { } func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { let feature = self.findFeature( latitude: request.message.latitude, longitude: request.message.longitude ) if let feature { - return ServerResponse(message: feature) + return feature } else { // No feature: return a feature with an empty name. let unknownFeature = Routeguide_Feature.with { @@ -37,25 +37,27 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.longitude = request.message.longitude } } - return ServerResponse(message: unknownFeature) + return unknownFeature } } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step06-server-streaming.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step06-server-streaming.swift index 779857268..c912c5f58 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step06-server-streaming.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step06-server-streaming.swift @@ -1,6 +1,6 @@ import GRPCCore -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { /// Known features. private let features: [Routeguide_Feature] @@ -18,16 +18,16 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { } func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { let feature = self.findFeature( latitude: request.message.latitude, longitude: request.message.longitude ) if let feature { - return ServerResponse(message: feature) + return feature } else { // No feature: return a feature with an empty name. let unknownFeature = Routeguide_Feature.with { @@ -37,33 +37,33 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.longitude = request.message.longitude } } - return ServerResponse(message: unknownFeature) + return unknownFeature } } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - for feature in self.features { - if !feature.name.isEmpty, feature.isContained(by: request.message) { - try await writer.write(feature) - } + ) async throws { + for feature in self.features { + if !feature.name.isEmpty, feature.isContained(by: request) { + try await response.write(feature) } } } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step07-server-streaming.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step07-server-streaming.swift deleted file mode 100644 index 8fe80e2dd..000000000 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step07-server-streaming.swift +++ /dev/null @@ -1,79 +0,0 @@ -import GRPCCore - -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { - /// Known features. - private let features: [Routeguide_Feature] - - /// Creates a new route guide service. - /// - Parameter features: Known features. - init(features: [Routeguide_Feature]) { - self.features = features - } - - /// Returns the first feature found at the given location, if one exists. - private func findFeature(latitude: Int32, longitude: Int32) -> Routeguide_Feature? { - self.features.first { - $0.location.latitude == latitude && $0.location.longitude == longitude - } - } - - func getFeature( - request: ServerRequest, - context: ServerContext - ) async throws -> ServerResponse { - let feature = self.findFeature( - latitude: request.message.latitude, - longitude: request.message.longitude - ) - - if let feature { - return ServerResponse(message: feature) - } else { - // No feature: return a feature with an empty name. - let unknownFeature = Routeguide_Feature.with { - $0.name = "" - $0.location = .with { - $0.latitude = request.message.latitude - $0.longitude = request.message.longitude - } - } - return ServerResponse(message: unknownFeature) - } - } - - func listFeatures( - request: ServerRequest, - context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - for feature in self.features { - if !feature.name.isEmpty, feature.isContained(by: request.message) { - try await writer.write(feature) - } - } - - return [:] - } - } - - func recordRoute( - request: StreamingServerRequest, - context: ServerContext - ) async throws -> ServerResponse { - } - - func routeChat( - request: StreamingServerRequest, - context: ServerContext - ) async throws -> StreamingServerResponse { - } -} - -extension Routeguide_Feature { - func isContained(by rectangle: Routeguide_Rectangle) -> Bool { - return rectangle.lo.latitude <= self.location.latitude - && self.location.latitude <= rectangle.hi.latitude - && rectangle.lo.longitude <= self.location.longitude - && self.location.longitude <= rectangle.hi.longitude - } -} diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step08-client-streaming.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step08-client-streaming.swift index 2004a8ddc..72032cfbb 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step08-client-streaming.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step08-client-streaming.swift @@ -1,7 +1,7 @@ import Foundation import GRPCCore -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { /// Known features. private let features: [Routeguide_Feature] @@ -19,16 +19,16 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { } func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { let feature = self.findFeature( latitude: request.message.latitude, longitude: request.message.longitude ) if let feature { - return ServerResponse(message: feature) + return feature } else { // No feature: return a feature with an empty name. let unknownFeature = Routeguide_Feature.with { @@ -38,36 +38,33 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.longitude = request.message.longitude } } - return ServerResponse(message: unknownFeature) + return unknownFeature } } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - for feature in self.features { - if !feature.name.isEmpty, feature.isContained(by: request.message) { - try await writer.write(feature) - } + ) async throws { + for feature in self.features { + if !feature.name.isEmpty, feature.isContained(by: request) { + try await response.write(feature) } - - return [:] } } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { let startTime = ContinuousClock.now var pointsVisited = 0 var featuresVisited = 0 var distanceTravelled = 0.0 var previousPoint: Routeguide_Point? = nil - for try await point in request.messages { + for try await point in request { pointsVisited += 1 if self.findFeature(latitude: point.latitude, longitude: point.longitude) != nil { @@ -89,13 +86,14 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.distance = Int32(distanceTravelled) } - return ServerResponse(message: summary) + return summary } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step09-bidi-streaming.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step09-bidi-streaming.swift index d48385753..96ecea323 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step09-bidi-streaming.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step09-bidi-streaming.swift @@ -2,44 +2,14 @@ import Foundation import GRPCCore import Synchronization -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { /// Known features. private let features: [Routeguide_Feature] - /// Notes recorded by clients. - private let receivedNotes: Notes - - /// A thread-safe store for notes sent by clients. - private final class Notes: Sendable { - private let notes: Mutex<[Routeguide_RouteNote]> - - init() { - self.notes = Mutex([]) - } - - /// Records a note and returns all other notes recorded at the same location. - /// - /// - Parameter receivedNote: A note to record. - /// - Returns: Other notes recorded at the same location. - func recordNote(_ receivedNote: Routeguide_RouteNote) -> [Routeguide_RouteNote] { - return self.notes.withLock { notes in - var notesFromSameLocation: [Routeguide_RouteNote] = [] - for note in notes { - if note.location == receivedNote.location { - notesFromSameLocation.append(note) - } - } - notes.append(receivedNote) - return notesFromSameLocation - } - } - } - /// Creates a new route guide service. /// - Parameter features: Known features. init(features: [Routeguide_Feature]) { self.features = features - self.receivedNotes = Notes() } /// Returns the first feature found at the given location, if one exists. @@ -50,16 +20,16 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { } func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { let feature = self.findFeature( latitude: request.message.latitude, longitude: request.message.longitude ) if let feature { - return ServerResponse(message: feature) + return feature } else { // No feature: return a feature with an empty name. let unknownFeature = Routeguide_Feature.with { @@ -69,36 +39,33 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.longitude = request.message.longitude } } - return ServerResponse(message: unknownFeature) + return unknownFeature } } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - for feature in self.features { - if !feature.name.isEmpty, feature.isContained(by: request.message) { - try await writer.write(feature) - } + ) async throws { + for feature in self.features { + if !feature.name.isEmpty, feature.isContained(by: request) { + try await response.write(feature) } - - return [:] } } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { let startTime = ContinuousClock.now var pointsVisited = 0 var featuresVisited = 0 var distanceTravelled = 0.0 var previousPoint: Routeguide_Point? = nil - for try await point in request.messages { + for try await point in request { pointsVisited += 1 if self.findFeature(latitude: point.latitude, longitude: point.longitude) != nil { @@ -120,13 +87,14 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.distance = Int32(distanceTravelled) } - return ServerResponse(message: summary) + return summary } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { + ) async throws { } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step10-bidi-streaming.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step10-bidi-streaming.swift index eb2b88a78..452e1ad7f 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step10-bidi-streaming.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec04-step10-bidi-streaming.swift @@ -2,44 +2,14 @@ import Foundation import GRPCCore import Synchronization -struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { +struct RouteGuideService: Routeguide_RouteGuide.SimpleServiceProtocol { /// Known features. private let features: [Routeguide_Feature] - /// Notes recorded by clients. - private let receivedNotes: Notes - - /// A thread-safe store for notes sent by clients. - private final class Notes: Sendable { - private let notes: Mutex<[Routeguide_RouteNote]> - - init() { - self.notes = Mutex([]) - } - - /// Records a note and returns all other notes recorded at the same location. - /// - /// - Parameter receivedNote: A note to record. - /// - Returns: Other notes recorded at the same location. - func recordNote(_ receivedNote: Routeguide_RouteNote) -> [Routeguide_RouteNote] { - return self.notes.withLock { notes in - var notesFromSameLocation: [Routeguide_RouteNote] = [] - for note in notes { - if note.location == receivedNote.location { - notesFromSameLocation.append(note) - } - } - notes.append(receivedNote) - return notesFromSameLocation - } - } - } - /// Creates a new route guide service. /// - Parameter features: Known features. init(features: [Routeguide_Feature]) { self.features = features - self.receivedNotes = Notes() } /// Returns the first feature found at the given location, if one exists. @@ -50,16 +20,16 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { } func getFeature( - request: ServerRequest, + request: Routeguide_Point, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_Feature { let feature = self.findFeature( latitude: request.message.latitude, longitude: request.message.longitude ) if let feature { - return ServerResponse(message: feature) + return feature } else { // No feature: return a feature with an empty name. let unknownFeature = Routeguide_Feature.with { @@ -69,36 +39,33 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.longitude = request.message.longitude } } - return ServerResponse(message: unknownFeature) + return unknownFeature } } func listFeatures( - request: ServerRequest, + request: Routeguide_Rectangle, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - for feature in self.features { - if !feature.name.isEmpty, feature.isContained(by: request.message) { - try await writer.write(feature) - } + ) async throws { + for feature in self.features { + if !feature.name.isEmpty, feature.isContained(by: request) { + try await response.write(feature) } - - return [:] } } func recordRoute( - request: StreamingServerRequest, + request: RPCAsyncSequence, context: ServerContext - ) async throws -> ServerResponse { + ) async throws -> Routeguide_RouteSummary { let startTime = ContinuousClock.now var pointsVisited = 0 var featuresVisited = 0 var distanceTravelled = 0.0 var previousPoint: Routeguide_Point? = nil - for try await point in request.messages { + for try await point in request { pointsVisited += 1 if self.findFeature(latitude: point.latitude, longitude: point.longitude) != nil { @@ -120,19 +87,17 @@ struct RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { $0.distance = Int32(distanceTravelled) } - return ServerResponse(message: summary) + return summary } func routeChat( - request: StreamingServerRequest, + request: RPCAsyncSequence, + response: RPCWriter, context: ServerContext - ) async throws -> StreamingServerResponse { - return StreamingServerResponse { writer in - for try await note in request.messages { - let notes = self.receivedNotes.recordNote(note) - try await writer.write(contentsOf: notes) - } - return [:] + ) async throws { + for try await note in request { + let notes = self.receivedNotes.recordNote(note) + try await response.write(contentsOf: notes) } } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift index 65a51d4b9..d5526b86f 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift @@ -5,8 +5,8 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-alpha.1"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.1"), ], targets: [ .executableTarget( diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift index e5f9b1088..8b4629476 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift @@ -5,8 +5,9 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-alpha.1"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.1"), ], targets: [ .executableTarget( diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift index 1e8ef47e1..bb1937d02 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift @@ -5,8 +5,9 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-alpha.1"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-alpha.1"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.1"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.1"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), ], targets: [ diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step07-server.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step07-server.swift index a0ba287f4..c6b0359fc 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step07-server.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step07-server.swift @@ -8,7 +8,7 @@ extension RouteGuide { let server = GRPCServer( transport: .http2NIOPosix( address: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ), services: [routeGuide] ) diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step08-run.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step08-run.swift index 6502dee78..c5401b149 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step08-run.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step08-run.swift @@ -8,7 +8,7 @@ extension RouteGuide { let server = GRPCServer( transport: .http2NIOPosix( address: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ), services: [routeGuide] ) diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift index ef8bc14ae..bf1dbaebc 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift @@ -6,7 +6,7 @@ extension RouteGuide { let client = try GRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift index f87f8cc80..52c4c79e5 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift @@ -6,7 +6,7 @@ extension RouteGuide { let client = try GRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift index 15322b30f..9b8b5ee3b 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift @@ -6,12 +6,12 @@ extension RouteGuide { let client = try GRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) async let _ = client.run() - let routeGuide = Routeguide_RouteGuideClient(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift index 04f75c699..b2b103b20 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift @@ -6,17 +6,17 @@ extension RouteGuide { let client = try GRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) async let _ = client.run() - let routeGuide = Routeguide_RouteGuideClient(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) try await self.getFeature(using: routeGuide) } - private func getFeature(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func getFeature(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'GetFeature'") let point = Routeguide_Point.with { diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift index adc6a25f4..609ce0ead 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift @@ -6,18 +6,18 @@ extension RouteGuide { let client = try GRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) async let _ = client.run() - let routeGuide = Routeguide_RouteGuideClient(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) try await self.getFeature(using: routeGuide) try await self.listFeatures(using: routeGuide) } - private func getFeature(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func getFeature(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'GetFeature'") let point = Routeguide_Point.with { @@ -29,7 +29,7 @@ extension RouteGuide { print("Got feature '\(feature.name)'") } - private func listFeatures(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func listFeatures(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'ListFeatures'") let boundingRectangle = Routeguide_Rectangle.with { diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift index 448eaa0ac..9fb6490c8 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift @@ -6,19 +6,19 @@ extension RouteGuide { let client = try GRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) async let _ = client.run() - let routeGuide = Routeguide_RouteGuideClient(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) try await self.getFeature(using: routeGuide) try await self.listFeatures(using: routeGuide) try await self.recordRoute(using: routeGuide) } - private func getFeature(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func getFeature(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'GetFeature'") let point = Routeguide_Point.with { @@ -30,7 +30,7 @@ extension RouteGuide { print("Got feature '\(feature.name)'") } - private func listFeatures(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func listFeatures(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'ListFeatures'") let boundingRectangle = Routeguide_Rectangle.with { @@ -53,7 +53,7 @@ extension RouteGuide { } } - private func recordRoute(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func recordRoute(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'RecordRoute'") let features = try self.loadFeatures() diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift index 12f75d83d..9f1afac60 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift @@ -6,20 +6,20 @@ extension RouteGuide { let client = try GRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), - config: .defaults(transportSecurity: .plaintext) + transportSecurity: .plaintext ) ) async let _ = client.run() - let routeGuide = Routeguide_RouteGuideClient(wrapping: client) + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) try await self.getFeature(using: routeGuide) try await self.listFeatures(using: routeGuide) try await self.recordRoute(using: routeGuide) try await self.routeChat(using: routeGuide) } - private func getFeature(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func getFeature(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'GetFeature'") let point = Routeguide_Point.with { @@ -31,7 +31,7 @@ extension RouteGuide { print("Got feature '\(feature.name)'") } - private func listFeatures(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func listFeatures(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'ListFeatures'") let boundingRectangle = Routeguide_Rectangle.with { @@ -54,7 +54,7 @@ extension RouteGuide { } } - private func recordRoute(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func recordRoute(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'RecordRoute'") let features = try self.loadFeatures() @@ -76,7 +76,7 @@ extension RouteGuide { ) } - private func routeChat(using routeGuide: Routeguide_RouteGuideClient) async throws { + private func routeChat(using routeGuide: Routeguide_RouteGuide.Client) async throws { print("→ Calling 'RouteChat'") try await routeGuide.routeChat { writer in diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial index 2d9192efc..3491b521a 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial @@ -65,7 +65,7 @@ @Step { We need to add a dependency on the gRPC Swift and Swift Protobuf packages. As gRPC Swift v2 - hasn't yet been released the dependencies must use the `-alpha` tags. + hasn't yet been released the dependencies must use the `-beta` tags. Note that we also add `.macOS(.v15)` to platforms, this is the earliest macOS version supported by gRPC Swift v2. @@ -192,9 +192,6 @@ Run `protoc` again to generate the service code. This will create `Sources/Generated/route_guide.grpc.swift`. - > `protoc-gen-grpc-swift` is currently shared with v1 so the `_V2=true` option is required. - > This will be removed when v2 is released. - @Code(name: "Console", file: "route-guide-sec03-step04-gen-grpc.txt") } } @@ -216,11 +213,11 @@ @Step { Create a new empty file in `Sources` called `RouteGuideService.swift`. To implement the service we need to conform a type to the generated service protocol. The name - of the protocol will be `_.ServiceProtocol` where `` and + of the protocol will be `_.SimpleServiceProtocol` where `` and `` are both taken from the `.proto` file. Create a `struct` called `RouteGuideService` which conforms to - the `Routeguide_RouteGuide.ServiceProtocol`. + the `Routeguide_RouteGuide.SimpleServiceProtocol`. @Code(name: "Sources/RouteGuideService.swift", file: "route-guide-sec04-step01-struct.swift") } @@ -243,47 +240,38 @@ @Step { `GetFeature` is a unary RPC which takes a single point as input and returns a single feature back to the client. Its generated method, `getFeature`, has one parameter: - `ServerRequest` describing the request. To return our response to + `Routeguide_Point`, the request message. To return our response to the client and complete the call we must first lookup a feature at the given point. @Code(name: "Sources/RouteGuideService.swift", file: "route-guide-sec04-step04-unary.swift") } @Step { - Then create and return an appropriate `ServerResponse` to the - client. + Then create and return an appropriate `Routeguide_Feature` to the client. @Code(name: "Sources/RouteGuideService.swift", file: "route-guide-sec04-step05-unary.swift") } @Step { Next, let's look at one of our streaming RPCs. Like the unary RPC, this method gets a - request object, `ServerRequest`, which has a message describing - the area in which the client wants to list features. As this is a server-side streaming RPC - we can send back multiple `Routeguide_Feature` messages to our client. + request message, `Routeguide_Rectangle`, describing the area in which the client wants to + list features. As this is a server-side streaming RPC we can send back + multiple `Routeguide_Feature` messages to our client. - To implement the method we must return a `StreamingServerResponse` which is initialized with - a closure to produce messages. The closure is passed a writer allowing you to write back - messages. We can write back a message for each feature we find in the rectangle. + To implement the method we must write messages back to the client using `response`, + an `RPCWriter` for `Routeguide_Feature` messages. @Code(name: "Sources/RouteGuideService.swift", file: "route-guide-sec04-step06-server-streaming.swift") } - @Step { - You can also send metadata to the client once the RPC has finished, in this case we don't - have any to send back so return the empty `Metadata` collection. - - @Code(name: "Sources/RouteGuideService.swift", file: "route-guide-sec04-step07-server-streaming.swift") - } - @Step { Now let's look at something a little more complicated: the client-side streaming method `RecordRoute`, where we get a stream of `Routeguide_Point`s from the client and return a single `Routeguide_RouteSummary` with information about their trip. - As you can see our method gets a `StreamingServerRequest` parameter and - returns a `ServerResponse`. In the method we iterate over - the asynchronous stream of points sent by the client. For each point we check if there's + As you can see our method gets a `RPCAsyncSequence` parameter + and returns a `Routeguide_RouteSummary`. In the method we iterate over the asynchronous + stream of points sent by the client. For each point we check if there's a feature at that point and calculate the distance between that and the last point we saw. After the *client* has finished sending points we populate a `Routeguide_RouteSummary` which we return in the response. @@ -301,11 +289,9 @@ } @Step { - To implement the RPC we return a `StreamingServerResponse`. Like in the - server-side streaming RPC it's initialized with a closure for writing back messages. In - the body of the closure we iterate the request messages and for each one call our helper - class to record the note and get all other notes recorded in the same location. We then - write each of those notes back to the client. + To implement the RPC we iterate the request notes, call our helper class to record each + note and get all other notes recorded in the same location. We then write each of those + notes back to the client. @Code(name: "Sources/RouteGuideService.swift", file: "route-guide-sec04-step10-bidi-streaming.swift") }