From 1c499000649ec637237cea4de7e22b944e79216e Mon Sep 17 00:00:00 2001 From: George Barnett Date: Fri, 20 Dec 2024 10:56:53 +0000 Subject: [PATCH] Remove unused grpc-swift v1 reflection code Motivation: The reflection code is for v1 and not reference by any target yet. It needs to be brought up-to-date for v2. Given we need to make a few changes along the way the diff will be clearer if done from scratch rather than as a large diff on v1. Modifications: - Remove v1 reflection code Result: Nothing --- .../ReflectionServiceTutorial.md | 227 ----- .../Server/ReflectionService.swift | 379 --------- .../Server/ReflectionServiceV1.swift | 206 ----- .../Server/ReflectionServiceV1Alpha.swift | 225 ----- .../v1/reflection-v1.grpc.swift | 120 --- .../v1/reflection-v1.pb.swift | 775 ----------------- .../v1Alpha/reflection-v1alpha.grpc.swift | 120 --- .../v1Alpha/reflection-v1alpha.pb.swift | 788 ------------------ 8 files changed, 2840 deletions(-) delete mode 100644 Sources/GRPCReflectionService/Documentation.docc/ReflectionServiceTutorial.md delete mode 100644 Sources/GRPCReflectionService/Server/ReflectionService.swift delete mode 100644 Sources/GRPCReflectionService/Server/ReflectionServiceV1.swift delete mode 100644 Sources/GRPCReflectionService/Server/ReflectionServiceV1Alpha.swift delete mode 100644 Sources/GRPCReflectionService/v1/reflection-v1.grpc.swift delete mode 100644 Sources/GRPCReflectionService/v1/reflection-v1.pb.swift delete mode 100644 Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.grpc.swift delete mode 100644 Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.pb.swift diff --git a/Sources/GRPCReflectionService/Documentation.docc/ReflectionServiceTutorial.md b/Sources/GRPCReflectionService/Documentation.docc/ReflectionServiceTutorial.md deleted file mode 100644 index 8cf1310..0000000 --- a/Sources/GRPCReflectionService/Documentation.docc/ReflectionServiceTutorial.md +++ /dev/null @@ -1,227 +0,0 @@ -# Reflection service - -This tutorial goes through the steps of adding Reflection service to a -server, running it and testing it using gRPCurl. - - The server used in this example is implemented at - [Examples/v1/ReflectionService/ReflectionServer.swift][reflection-server] - and it supports the "Greeter", "Echo", and "Reflection" services. - - -## Overview - -The Reflection service provides information about the public RPCs served by a server. -It is specific to services defined using the Protocol Buffers IDL. -By calling the Reflection service, clients can construct and send requests to services -without needing to generate code and types for them. - -You can also use CLI clients such as [gRPCurl][grpcurl-setup] and the [gRPC command line tool][grpc-cli] to: -- list services, -- describe services and their methods, -- describe symbols, -- describe extensions, -- construct and invoke RPCs. - -gRPC Swift supports both [v1][v1] and [v1alpha][v1alpha] of the reflection service. - -## Adding the Reflection service to a server - -You can use the Reflection service by adding it as a provider when constructing your server. - -To initialise the Reflection service we will use -``GRPCReflectionService/ReflectionService/init(reflectionDataFileURLs:version:)``. -It receives the URLs of the files containing the reflection data of the proto files -describing the services of the server and the version of the reflection service. - -### Generating the reflection data - -The server from this example uses the `GreeterProvider` and the `EchoProvider`, -besides the `ReflectionService`. - -The associated proto files are located at `Examples/v1/HelloWorld/Model/helloworld.proto`, and -`Examples/v1/Echo/Model/echo.proto` respectively. - -In order to generate the reflection data for the `helloworld.proto`, you can run the following command: - -```sh -$ protoc Examples/v1/HelloWorld/Model/helloworld.proto \ - --proto_path=Examples/v1/HelloWorld/Model \ - --grpc-swift_opt=Client=false,Server=false,ReflectionData=true \ - --grpc-swift_out=Examples/v1/ReflectionService/Generated -``` - -Let's break the command down: -- The first argument passed to `protoc` is the path - to the `.proto` file to generate reflection data - for: [`Examples/v1/HelloWorld/Model/helloworld.proto`][helloworld-proto]. -- The `proto_path` flag is the path to search for imports: `Examples/v1/HelloWorld/Model`. -- The 'grpc-swift_opt' flag allows us to list options for the Swift generator. - To generate only the reflection data set: `Client=false,Server=false,ReflectionData=true`. -- The `grpc-swift_out` flag is used to set the path of the directory - where the generated file will be located: `Examples/v1/ReflectionService/Generated`. - -This command assumes that the `protoc-gen-grpc-swift` plugin is in your `$PATH` environment variable. -You can learn how to get the plugin from this section of the `grpc-swift` README: -https://github.com/grpc/grpc-swift#getting-the-protoc-plugins. - -The command for generating the reflection data for the `Echo` service is similar. - -You can use Swift Package Manager [resources][swiftpm-resources] to add the generated reflection data to your target. -In our example the reflection data is written into the "Generated" directory within the target -so we include the `.copy("Generated")` rule in our target's resource list. - -### Instantiating the Reflection service - -To instantiate the `ReflectionService` you need to pass the URLs of the files containing -the generated reflection data and the version to use, in our case `.v1`. - -Depending on the version of [gRPCurl][grpcurl] you are using you might need to use the `.v1alpha` instead. -Beginning with [gRPCurl v1.8.8][grpcurl-v188] it uses the [v1][v1] reflection. Earlier versions use [v1alpha][v1alpha] -reflection. - -```swift -// Getting the URLs of the files containing the reflection data. -guard - let greeterURL = Bundle.module.url( - forResource: "helloworld", - withExtension: "grpc.reflection", - subdirectory: "Generated" - ), - let echoURL = Bundle.module.url( - forResource: "echo", - withExtension: "grpc.reflection", - subdirectory: "Generated" - ) -else { - print("The resource could not be loaded.") - throw ExitCode.failure -} -let reflectionService = try ReflectionService( - reflectionDataFileURLs: [greeterURL, echoURL], - version: .v1 -) -``` - -### Swift Package Manager Plugin - -Reflection data can also be generated via the SPM plugin by including `"reflectionData": true` in `grpc-swift-config.json`. This will generate the same reflection data as running `protoc` above. The generated reflection files are added to your module Bundle and can be accessed at runtime. More about [spm-plugin][spm-plugin] can be found here. - -```json -{ - "invocations": [ - { - "protoFiles": [ - "helloworld.proto" - ], - "visibility": "public", - "server": true, - "reflectionData": true - } - ] -} -``` - -To instantiate the `ReflectionService` you can search for files with the extension `reflection` in your module Bundle. - -```swift -let reflectionDataFilePaths = Bundle.module.paths( - forResourcesOfType: "reflection", - inDirectory: nil -) -let reflectionService = try ReflectionService( - reflectionDataFilePaths: reflectionDataFilePaths, - version: .v1Alpha -) -``` - -### Running the server - -In our example the server isn't configured with TLS and listens on localhost port 1234. -The following code configures and starts the server: - -```swift -let server = try await Server.insecure(group: group) - .withServiceProviders([reflectionService, GreeterProvider(), EchoProvider()]) - .bind(host: "localhost", port: self.port) - .get() - -``` - -To run the server, from the root of the package run: - -```sh -$ swift run ReflectionServer -``` - -## Calling the Reflection service with gRPCurl - -Please follow the instructions from the [gRPCurl README][grpcurl-setup] to set up gRPCurl. - -From a different terminal than the one used for running the server, we will call gRPCurl commands, -following the format: `grpcurl [flags] [address] [list|describe] [symbol]`. - -We use the `-plaintext` flag, because the server isn't configured with TLS, and -the address is set to `localhost:1234`. - - -To see the available services use `list`: - -```sh -$ grpcurl -plaintext localhost:1234 list -echo.Echo -helloworld.Greeter -``` - -To see what methods are available for a service: - -```sh -$ grpcurl -plaintext localhost:1234 list echo.Echo -echo.Echo.Collect -echo.Echo.Expand -echo.Echo.Get -echo.Echo.Update -``` - -You can also get descriptions of objects like services, methods, and messages. The following -command fetches a description of the Echo service: - -```sh -$ grpcurl -plaintext localhost:1234 describe echo.Echo -echo.Echo is a service: -service Echo { - // Collects a stream of messages and returns them concatenated when the caller closes. - rpc Collect ( stream .echo.EchoRequest ) returns ( .echo.EchoResponse ); - // Splits a request into words and returns each word in a stream of messages. - rpc Expand ( .echo.EchoRequest ) returns ( stream .echo.EchoResponse ); - // Immediately returns an echo of a request. - rpc Get ( .echo.EchoRequest ) returns ( .echo.EchoResponse ); - // Streams back messages as they are received in an input stream. - rpc Update ( stream .echo.EchoRequest ) returns ( stream .echo.EchoResponse ); -} -``` - -You can send requests to the services with gRPCurl: - -```sh -$ grpcurl -d '{ "text": "test" }' -plaintext localhost:1234 echo.Echo.Get -{ - "text": "Swift echo get: test" -} -``` - -Note that when specifying a service, a method or a symbol, we have to use the fully qualified names: -- service: \.\ -- method: \.\.\ -- type: \.\ - -[grpcurl-setup]: https://github.com/fullstorydev/grpcurl#grpcurl -[grpcurl]: https://github.com/fullstorydev/grpcurl -[grpc-cli]: https://github.com/grpc/grpc/blob/5011420f160b91129a7baebe21df9444a07896a6/doc/command_line_tool.md -[v1]: ../v1/reflection-v1.proto -[v1alpha]: ../v1Alpha/reflection-v1alpha.proto -[reflection-server]: ../../Examples/v1/ReflectionService/ReflectionServer.swift -[helloworld-proto]: ../../Examples/v1/HelloWorld/Model/helloworld.proto -[echo-proto]: ../../Examples/v1/Echo/Model/echo.proto -[grpcurl-v188]: https://github.com/fullstorydev/grpcurl/releases/tag/v1.8.8 -[swiftpm-resources]: https://github.com/apple/swift-package-manager/blob/main/Documentation/PackageDescription.md#resource -[spm-plugin]: ../../protoc-gen-grpc-swift/Docs.docc/spm-plugin.md diff --git a/Sources/GRPCReflectionService/Server/ReflectionService.swift b/Sources/GRPCReflectionService/Server/ReflectionService.swift deleted file mode 100644 index d6bcb1f..0000000 --- a/Sources/GRPCReflectionService/Server/ReflectionService.swift +++ /dev/null @@ -1,379 +0,0 @@ -/* - * Copyright 2023, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import DequeModule -import Foundation -import GRPC -import SwiftProtobuf - -public final class ReflectionService: CallHandlerProvider, Sendable { - private let provider: Provider - - public var serviceName: Substring { - switch self.provider { - case .v1(let provider): - return provider.serviceName - case .v1Alpha(let provider): - return provider.serviceName - } - } - - /// Creates a `ReflectionService` by loading serialized reflection data created by `protoc-gen-grpc-swift`. - /// - /// You can generate serialized reflection data using the `protoc-gen-grpc-swift` plugin for `protoc` by - /// setting the `ReflectionData` option to `True`. - /// - /// - Parameter fileURLs: The URLs of the files containing serialized reflection data. - /// - Parameter version: The version of the reflection service to create. - /// - /// - Note: Reflection data for well-known-types must be provided if any of your reflection data depends - /// on them. - /// - Throws: When a file can't be read from disk or parsed. - public convenience init(reflectionDataFileURLs fileURLs: [URL], version: Version) throws { - let filePaths: [String] - #if os(Linux) - filePaths = fileURLs.map { $0.path } - #else - if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) { - filePaths = fileURLs.map { $0.path() } - } else { - filePaths = fileURLs.map { $0.path } - } - #endif - try self.init(reflectionDataFilePaths: filePaths, version: version) - } - - /// Creates a `ReflectionService` by loading serialized reflection data created by `protoc-gen-grpc-swift`. - /// - /// You can generate serialized reflection data using the `protoc-gen-grpc-swift` plugin for `protoc` by - /// setting the `ReflectionData` option to `True`. The paths provided should be absolute or relative to the - /// current working directory. - /// - /// - Parameter filePaths: The paths to files containing serialized reflection data. - /// - Parameter version: The version of the reflection service to create. - /// - /// - Note: Reflection data for well-known-types must be provided if any of your reflection data depends - /// on them. - /// - Throws: When a file can't be read from disk or parsed. - public init(reflectionDataFilePaths filePaths: [String], version: Version) throws { - let fileDescriptorProtos = try ReflectionService.readSerializedFileDescriptorProtos( - atPaths: filePaths - ) - switch version.wrapped { - case .v1: - self.provider = .v1( - try ReflectionServiceProviderV1(fileDescriptorProtos: fileDescriptorProtos) - ) - case .v1Alpha: - self.provider = .v1Alpha( - try ReflectionServiceProviderV1Alpha(fileDescriptorProtos: fileDescriptorProtos) - ) - } - } - - public init(fileDescriptorProtos: [Google_Protobuf_FileDescriptorProto], version: Version) throws - { - switch version.wrapped { - case .v1: - self.provider = .v1( - try ReflectionServiceProviderV1(fileDescriptorProtos: fileDescriptorProtos) - ) - case .v1Alpha: - self.provider = .v1Alpha( - try ReflectionServiceProviderV1Alpha(fileDescriptorProtos: fileDescriptorProtos) - ) - } - } - - public func handle( - method name: Substring, - context: GRPC.CallHandlerContext - ) -> GRPC.GRPCServerHandlerProtocol? { - switch self.provider { - case .v1(let reflectionV1Provider): - return reflectionV1Provider.handle(method: name, context: context) - case .v1Alpha(let reflectionV1AlphaProvider): - return reflectionV1AlphaProvider.handle(method: name, context: context) - } - } -} - -internal struct ReflectionServiceData: Sendable { - internal struct FileDescriptorProtoData: Sendable { - internal var serializedFileDescriptorProto: Data - internal var dependencyFileNames: [String] - } - private struct ExtensionDescriptor: Sendable, Hashable { - internal let extendeeTypeName: String - internal let fieldNumber: Int32 - } - - internal var fileDescriptorDataByFilename: [String: FileDescriptorProtoData] - internal var serviceNames: [String] - internal var fileNameBySymbol: [String: String] - - // Stores the file names for each extension identified by an ExtensionDescriptor object. - private var fileNameByExtensionDescriptor: [ExtensionDescriptor: String] - // Stores the field numbers for each type that has extensions. - private var fieldNumbersByType: [String: [Int32]] - - internal init(fileDescriptors: [Google_Protobuf_FileDescriptorProto]) throws { - self.serviceNames = [] - self.fileDescriptorDataByFilename = [:] - self.fileNameBySymbol = [:] - self.fileNameByExtensionDescriptor = [:] - self.fieldNumbersByType = [:] - - for fileDescriptorProto in fileDescriptors { - let serializedFileDescriptorProto: Data - do { - serializedFileDescriptorProto = try fileDescriptorProto.serializedData() - } catch { - throw GRPCStatus( - code: .invalidArgument, - message: - "The \(fileDescriptorProto.name) could not be serialized." - ) - } - let protoData = FileDescriptorProtoData( - serializedFileDescriptorProto: serializedFileDescriptorProto, - dependencyFileNames: fileDescriptorProto.dependency - ) - self.fileDescriptorDataByFilename[fileDescriptorProto.name] = protoData - self.serviceNames.append( - contentsOf: fileDescriptorProto.service.map { fileDescriptorProto.package + "." + $0.name } - ) - // Populating the dictionary. - for qualifiedSybolName in fileDescriptorProto.qualifiedSymbolNames { - let oldValue = self.fileNameBySymbol.updateValue( - fileDescriptorProto.name, - forKey: qualifiedSybolName - ) - if let oldValue = oldValue { - throw GRPCStatus( - code: .alreadyExists, - message: - "The \(qualifiedSybolName) symbol from \(fileDescriptorProto.name) already exists in \(oldValue)." - ) - } - } - - for typeName in fileDescriptorProto.qualifiedMessageTypes { - self.fieldNumbersByType[typeName] = [] - } - - // Populating the dictionary and the one. - for `extension` in fileDescriptorProto.extension { - let typeName = String(`extension`.extendee.drop(while: { $0 == "." })) - let extensionDescriptor = ExtensionDescriptor( - extendeeTypeName: typeName, - fieldNumber: `extension`.number - ) - let oldFileName = self.fileNameByExtensionDescriptor.updateValue( - fileDescriptorProto.name, - forKey: extensionDescriptor - ) - if let oldFileName = oldFileName { - throw GRPCStatus( - code: .alreadyExists, - message: - """ - The extension of the \(extensionDescriptor.extendeeTypeName) type with the field number equal to \ - \(extensionDescriptor.fieldNumber) from \(fileDescriptorProto.name) already exists in \(oldFileName). - """ - ) - } - self.fieldNumbersByType[typeName, default: []].append(`extension`.number) - } - } - } - - internal func serialisedFileDescriptorProtosForDependenciesOfFile( - named fileName: String - ) -> Result<[Data], GRPCStatus> { - var toVisit = Deque() - var visited = Set() - var serializedFileDescriptorProtos: [Data] = [] - toVisit.append(fileName) - - while let currentFileName = toVisit.popFirst() { - if let protoData = self.fileDescriptorDataByFilename[currentFileName] { - toVisit.append( - contentsOf: protoData.dependencyFileNames - .filter { name in - return !visited.contains(name) - } - ) - - let serializedFileDescriptorProto = protoData.serializedFileDescriptorProto - serializedFileDescriptorProtos.append(serializedFileDescriptorProto) - } else { - let base = "No reflection data for '\(currentFileName)'" - let message: String - if fileName == currentFileName { - message = base + "." - } else { - message = base + " which is a dependency of '\(fileName)'." - } - return .failure(GRPCStatus(code: .notFound, message: message)) - } - visited.insert(currentFileName) - } - return .success(serializedFileDescriptorProtos) - } - - internal func nameOfFileContainingSymbol(named symbolName: String) -> Result { - guard let fileName = self.fileNameBySymbol[symbolName] else { - return .failure( - GRPCStatus( - code: .notFound, - message: "The provided symbol could not be found." - ) - ) - } - return .success(fileName) - } - - internal func nameOfFileContainingExtension( - extendeeName: String, - fieldNumber number: Int32 - ) -> Result { - let key = ExtensionDescriptor(extendeeTypeName: extendeeName, fieldNumber: number) - guard let fileName = self.fileNameByExtensionDescriptor[key] else { - return .failure( - GRPCStatus( - code: .notFound, - message: "The provided extension could not be found." - ) - ) - } - return .success(fileName) - } - - // Returns an empty array if the type has no extensions. - internal func extensionsFieldNumbersOfType( - named typeName: String - ) -> Result<[Int32], GRPCStatus> { - guard let fieldNumbers = self.fieldNumbersByType[typeName] else { - return .failure( - GRPCStatus( - code: .invalidArgument, - message: "The provided type is invalid." - ) - ) - } - return .success(fieldNumbers) - } -} - -extension Google_Protobuf_FileDescriptorProto { - var qualifiedServiceAndMethodNames: [String] { - var names: [String] = [] - - for service in self.service { - names.append(self.package + "." + service.name) - names.append( - contentsOf: service.method - .map { self.package + "." + service.name + "." + $0.name } - ) - } - return names - } - - var qualifiedMessageTypes: [String] { - return self.messageType.map { - self.package + "." + $0.name - } - } - - var qualifiedEnumTypes: [String] { - return self.enumType.map { - self.package + "." + $0.name - } - } - - var qualifiedSymbolNames: [String] { - var names = self.qualifiedServiceAndMethodNames - names.append(contentsOf: self.qualifiedMessageTypes) - names.append(contentsOf: self.qualifiedEnumTypes) - return names - } -} - -extension ReflectionService { - /// The version of the reflection service. - /// - /// Depending in the version you are using, when creating the ReflectionService - /// provide the corresponding `Version` variable (`v1` or `v1Alpha`). - public struct Version: Sendable, Hashable { - internal enum Wrapped { - case v1 - case v1Alpha - } - var wrapped: Wrapped - private init(_ wrapped: Wrapped) { self.wrapped = wrapped } - - /// The v1 version of reflection service: https://github.com/grpc/grpc/blob/5011420f160b91129a7baebe21df9444a07896a6/src/proto/grpc/reflection/v1/reflection.proto. - public static var v1: Self { Self(.v1) } - /// The v1alpha version of reflection service: https://github.com/grpc/grpc/blob/5011420f160b91129a7baebe21df9444a07896a6/src/proto/grpc/reflection/v1alpha/reflection.proto. - public static var v1Alpha: Self { Self(.v1Alpha) } - } - - private enum Provider { - case v1(ReflectionServiceProviderV1) - case v1Alpha(ReflectionServiceProviderV1Alpha) - } -} - -extension ReflectionService { - static func readSerializedFileDescriptorProto( - atPath path: String - ) throws -> Google_Protobuf_FileDescriptorProto { - let fileURL: URL - #if os(Linux) - fileURL = URL(fileURLWithPath: path) - #else - if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) { - fileURL = URL(filePath: path, directoryHint: .notDirectory) - } else { - fileURL = URL(fileURLWithPath: path) - } - #endif - let binaryData = try Data(contentsOf: fileURL) - guard let serializedData = Data(base64Encoded: binaryData) else { - throw GRPCStatus( - code: .invalidArgument, - message: - """ - The \(path) file contents could not be transformed \ - into serialized data representing a file descriptor proto. - """ - ) - } - return try Google_Protobuf_FileDescriptorProto(serializedBytes: serializedData) - } - - static func readSerializedFileDescriptorProtos( - atPaths paths: [String] - ) throws -> [Google_Protobuf_FileDescriptorProto] { - var fileDescriptorProtos = [Google_Protobuf_FileDescriptorProto]() - fileDescriptorProtos.reserveCapacity(paths.count) - for path in paths { - try fileDescriptorProtos.append(readSerializedFileDescriptorProto(atPath: path)) - } - return fileDescriptorProtos - } -} diff --git a/Sources/GRPCReflectionService/Server/ReflectionServiceV1.swift b/Sources/GRPCReflectionService/Server/ReflectionServiceV1.swift deleted file mode 100644 index 38fa99e..0000000 --- a/Sources/GRPCReflectionService/Server/ReflectionServiceV1.swift +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright 2023, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Foundation -import GRPC -import SwiftProtobuf - -internal final class ReflectionServiceProviderV1: Grpc_Reflection_V1_ServerReflectionAsyncProvider { - private let protoRegistry: ReflectionServiceData - - internal init(fileDescriptorProtos: [Google_Protobuf_FileDescriptorProto]) throws { - self.protoRegistry = try ReflectionServiceData( - fileDescriptors: fileDescriptorProtos - ) - } - - internal func _findFileByFileName( - _ fileName: String - ) -> Result { - return self.protoRegistry - .serialisedFileDescriptorProtosForDependenciesOfFile(named: fileName) - .map { fileDescriptorProtos in - Grpc_Reflection_V1_ServerReflectionResponse.OneOf_MessageResponse.fileDescriptorResponse( - .with { - $0.fileDescriptorProto = fileDescriptorProtos - } - ) - } - } - - internal func findFileByFileName( - _ fileName: String, - request: Grpc_Reflection_V1_ServerReflectionRequest - ) -> Grpc_Reflection_V1_ServerReflectionResponse { - let result = self._findFileByFileName(fileName) - return result.makeResponse(request: request) - } - - internal func getServicesNames( - request: Grpc_Reflection_V1_ServerReflectionRequest - ) throws -> Grpc_Reflection_V1_ServerReflectionResponse { - var listServicesResponse = Grpc_Reflection_V1_ListServiceResponse() - listServicesResponse.service = self.protoRegistry.serviceNames.map { serviceName in - Grpc_Reflection_V1_ServiceResponse.with { - $0.name = serviceName - } - } - return Grpc_Reflection_V1_ServerReflectionResponse( - request: request, - messageResponse: .listServicesResponse(listServicesResponse) - ) - } - - internal func findFileBySymbol( - _ symbolName: String, - request: Grpc_Reflection_V1_ServerReflectionRequest - ) -> Grpc_Reflection_V1_ServerReflectionResponse { - let result = self.protoRegistry.nameOfFileContainingSymbol( - named: symbolName - ).flatMap { - self._findFileByFileName($0) - } - return result.makeResponse(request: request) - } - - internal func findFileByExtension( - extensionRequest: Grpc_Reflection_V1_ExtensionRequest, - request: Grpc_Reflection_V1_ServerReflectionRequest - ) -> Grpc_Reflection_V1_ServerReflectionResponse { - let result = self.protoRegistry.nameOfFileContainingExtension( - extendeeName: extensionRequest.containingType, - fieldNumber: extensionRequest.extensionNumber - ).flatMap { - self._findFileByFileName($0) - } - return result.makeResponse(request: request) - } - - internal func findExtensionsFieldNumbersOfType( - named typeName: String, - request: Grpc_Reflection_V1_ServerReflectionRequest - ) -> Grpc_Reflection_V1_ServerReflectionResponse { - let result = self.protoRegistry.extensionsFieldNumbersOfType( - named: typeName - ).map { fieldNumbers in - Grpc_Reflection_V1_ServerReflectionResponse.OneOf_MessageResponse.allExtensionNumbersResponse( - Grpc_Reflection_V1_ExtensionNumberResponse.with { - $0.baseTypeName = typeName - $0.extensionNumber = fieldNumbers - } - ) - } - return result.makeResponse(request: request) - } - - internal func serverReflectionInfo( - requestStream: GRPCAsyncRequestStream, - responseStream: GRPCAsyncResponseStreamWriter, - context: GRPCAsyncServerCallContext - ) async throws { - for try await request in requestStream { - switch request.messageRequest { - case let .fileByFilename(fileName): - let response = self.findFileByFileName( - fileName, - request: request - ) - try await responseStream.send(response) - - case .listServices: - let response = try self.getServicesNames(request: request) - try await responseStream.send(response) - - case let .fileContainingSymbol(symbolName): - let response = self.findFileBySymbol( - symbolName, - request: request - ) - try await responseStream.send(response) - - case let .fileContainingExtension(extensionRequest): - let response = self.findFileByExtension( - extensionRequest: extensionRequest, - request: request - ) - try await responseStream.send(response) - - case let .allExtensionNumbersOfType(typeName): - let response = self.findExtensionsFieldNumbersOfType( - named: typeName, - request: request - ) - try await responseStream.send(response) - - default: - let response = Grpc_Reflection_V1_ServerReflectionResponse( - request: request, - messageResponse: .errorResponse( - Grpc_Reflection_V1_ErrorResponse.with { - $0.errorCode = Int32(GRPCStatus.Code.unimplemented.rawValue) - $0.errorMessage = "The request is not implemented." - } - ) - ) - try await responseStream.send(response) - } - } - } -} - -extension Grpc_Reflection_V1_ServerReflectionResponse { - init( - request: Grpc_Reflection_V1_ServerReflectionRequest, - messageResponse: Grpc_Reflection_V1_ServerReflectionResponse.OneOf_MessageResponse - ) { - self = .with { - $0.validHost = request.host - $0.originalRequest = request - $0.messageResponse = messageResponse - } - } -} - -extension Result { - func recover() -> Result - { - self.flatMapError { status in - let error = Grpc_Reflection_V1_ErrorResponse.with { - $0.errorCode = Int32(status.code.rawValue) - $0.errorMessage = status.message ?? "" - } - return .success(.errorResponse(error)) - } - } - - func makeResponse( - request: Grpc_Reflection_V1_ServerReflectionRequest - ) -> Grpc_Reflection_V1_ServerReflectionResponse { - let result = self.recover().attachRequest(request) - return result.get() - } -} - -extension Result -where Success == Grpc_Reflection_V1_ServerReflectionResponse.OneOf_MessageResponse { - func attachRequest( - _ request: Grpc_Reflection_V1_ServerReflectionRequest - ) -> Result { - self.map { message in - Grpc_Reflection_V1_ServerReflectionResponse(request: request, messageResponse: message) - } - } -} diff --git a/Sources/GRPCReflectionService/Server/ReflectionServiceV1Alpha.swift b/Sources/GRPCReflectionService/Server/ReflectionServiceV1Alpha.swift deleted file mode 100644 index d22e820..0000000 --- a/Sources/GRPCReflectionService/Server/ReflectionServiceV1Alpha.swift +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2023, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Foundation -import GRPC -import SwiftProtobuf - -internal final class ReflectionServiceProviderV1Alpha: - Grpc_Reflection_V1alpha_ServerReflectionAsyncProvider -{ - private let protoRegistry: ReflectionServiceData - - internal init(fileDescriptorProtos: [Google_Protobuf_FileDescriptorProto]) throws { - self.protoRegistry = try ReflectionServiceData( - fileDescriptors: fileDescriptorProtos - ) - } - - internal func _findFileByFileName( - _ fileName: String - ) -> Result { - return self.protoRegistry - .serialisedFileDescriptorProtosForDependenciesOfFile(named: fileName) - .map { fileDescriptorProtos in - Grpc_Reflection_V1alpha_ServerReflectionResponse.OneOf_MessageResponse - .fileDescriptorResponse( - .with { - $0.fileDescriptorProto = fileDescriptorProtos - } - ) - } - } - - internal func findFileByFileName( - _ fileName: String, - request: Grpc_Reflection_V1alpha_ServerReflectionRequest - ) -> Grpc_Reflection_V1alpha_ServerReflectionResponse { - let result = self._findFileByFileName(fileName) - return result.makeResponse(request: request) - } - - internal func getServicesNames( - request: Grpc_Reflection_V1alpha_ServerReflectionRequest - ) throws -> Grpc_Reflection_V1alpha_ServerReflectionResponse { - var listServicesResponse = Grpc_Reflection_V1alpha_ListServiceResponse() - listServicesResponse.service = self.protoRegistry.serviceNames.map { serviceName in - Grpc_Reflection_V1alpha_ServiceResponse.with { - $0.name = serviceName - } - } - return Grpc_Reflection_V1alpha_ServerReflectionResponse( - request: request, - messageResponse: .listServicesResponse(listServicesResponse) - ) - } - - internal func findFileBySymbol( - _ symbolName: String, - request: Grpc_Reflection_V1alpha_ServerReflectionRequest - ) -> Grpc_Reflection_V1alpha_ServerReflectionResponse { - let result = self.protoRegistry.nameOfFileContainingSymbol( - named: symbolName - ).flatMap { - self._findFileByFileName($0) - } - return result.makeResponse(request: request) - } - - internal func findFileByExtension( - extensionRequest: Grpc_Reflection_V1alpha_ExtensionRequest, - request: Grpc_Reflection_V1alpha_ServerReflectionRequest - ) -> Grpc_Reflection_V1alpha_ServerReflectionResponse { - let result = self.protoRegistry.nameOfFileContainingExtension( - extendeeName: extensionRequest.containingType, - fieldNumber: extensionRequest.extensionNumber - ).flatMap { - self._findFileByFileName($0) - } - return result.makeResponse(request: request) - } - - internal func findExtensionsFieldNumbersOfType( - named typeName: String, - request: Grpc_Reflection_V1alpha_ServerReflectionRequest - ) -> Grpc_Reflection_V1alpha_ServerReflectionResponse { - let result = self.protoRegistry.extensionsFieldNumbersOfType( - named: typeName - ).map { fieldNumbers in - Grpc_Reflection_V1alpha_ServerReflectionResponse.OneOf_MessageResponse - .allExtensionNumbersResponse( - Grpc_Reflection_V1alpha_ExtensionNumberResponse.with { - $0.baseTypeName = typeName - $0.extensionNumber = fieldNumbers - } - ) - } - return result.makeResponse(request: request) - } - - internal func serverReflectionInfo( - requestStream: GRPCAsyncRequestStream, - responseStream: GRPCAsyncResponseStreamWriter, - context: GRPCAsyncServerCallContext - ) async throws { - for try await request in requestStream { - switch request.messageRequest { - case let .fileByFilename(fileName): - let response = self.findFileByFileName( - fileName, - request: request - ) - try await responseStream.send(response) - - case .listServices: - let response = try self.getServicesNames(request: request) - try await responseStream.send(response) - - case let .fileContainingSymbol(symbolName): - let response = self.findFileBySymbol( - symbolName, - request: request - ) - try await responseStream.send(response) - - case let .fileContainingExtension(extensionRequest): - let response = self.findFileByExtension( - extensionRequest: extensionRequest, - request: request - ) - try await responseStream.send(response) - - case let .allExtensionNumbersOfType(typeName): - let response = self.findExtensionsFieldNumbersOfType( - named: typeName, - request: request - ) - try await responseStream.send(response) - - default: - let response = Grpc_Reflection_V1alpha_ServerReflectionResponse( - request: request, - messageResponse: .errorResponse( - Grpc_Reflection_V1alpha_ErrorResponse.with { - $0.errorCode = Int32(GRPCStatus.Code.unimplemented.rawValue) - $0.errorMessage = "The request is not implemented." - } - ) - ) - try await responseStream.send(response) - } - } - } -} - -extension Grpc_Reflection_V1alpha_ServerReflectionResponse { - init( - request: Grpc_Reflection_V1alpha_ServerReflectionRequest, - messageResponse: Grpc_Reflection_V1alpha_ServerReflectionResponse.OneOf_MessageResponse - ) { - self = .with { - $0.validHost = request.host - $0.originalRequest = request - $0.messageResponse = messageResponse - } - } -} - -extension Result -{ - func recover() -> Result< - Grpc_Reflection_V1alpha_ServerReflectionResponse.OneOf_MessageResponse, Never - > { - self.flatMapError { status in - let error = Grpc_Reflection_V1alpha_ErrorResponse.with { - $0.errorCode = Int32(status.code.rawValue) - $0.errorMessage = status.message ?? "" - } - return .success(.errorResponse(error)) - } - } - - func makeResponse( - request: Grpc_Reflection_V1alpha_ServerReflectionRequest - ) -> Grpc_Reflection_V1alpha_ServerReflectionResponse { - let result = self.recover().attachRequest(request) - return result.get() - } -} - -extension Result -where Success == Grpc_Reflection_V1alpha_ServerReflectionResponse.OneOf_MessageResponse { - func attachRequest( - _ request: Grpc_Reflection_V1alpha_ServerReflectionRequest - ) -> Result { - self.map { message in - Grpc_Reflection_V1alpha_ServerReflectionResponse(request: request, messageResponse: message) - } - } -} - -#if compiler(<6.0) -extension Result where Failure == Never { - func get() -> Success { - switch self { - case .success(let success): - return success - case .failure: - fatalError("Unreachable") - } - } -} -#endif diff --git a/Sources/GRPCReflectionService/v1/reflection-v1.grpc.swift b/Sources/GRPCReflectionService/v1/reflection-v1.grpc.swift deleted file mode 100644 index 4991f2b..0000000 --- a/Sources/GRPCReflectionService/v1/reflection-v1.grpc.swift +++ /dev/null @@ -1,120 +0,0 @@ -// -// DO NOT EDIT. -// swift-format-ignore-file -// -// Generated by the protocol buffer compiler. -// Source: reflection.proto -// -import GRPC -import NIO -import NIOConcurrencyHelpers -import SwiftProtobuf - - -/// To build a server, implement a class that conforms to this protocol. -internal protocol Grpc_Reflection_V1_ServerReflectionProvider: CallHandlerProvider { - var interceptors: Grpc_Reflection_V1_ServerReflectionServerInterceptorFactoryProtocol? { get } - - /// The reflection service is structured as a bidirectional stream, ensuring - /// all related requests go to a single server. - func serverReflectionInfo(context: StreamingResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> -} - -extension Grpc_Reflection_V1_ServerReflectionProvider { - internal var serviceName: Substring { - return Grpc_Reflection_V1_ServerReflectionServerMetadata.serviceDescriptor.fullName[...] - } - - /// Determines, calls and returns the appropriate request handler, depending on the request's method. - /// Returns nil for methods not handled by this service. - internal func handle( - method name: Substring, - context: CallHandlerContext - ) -> GRPCServerHandlerProtocol? { - switch name { - case "ServerReflectionInfo": - return BidirectionalStreamingServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeServerReflectionInfoInterceptors() ?? [], - observerFactory: self.serverReflectionInfo(context:) - ) - - default: - return nil - } - } -} - -/// To implement a server, implement an object which conforms to this protocol. -internal protocol Grpc_Reflection_V1_ServerReflectionAsyncProvider: CallHandlerProvider, Sendable { - static var serviceDescriptor: GRPCServiceDescriptor { get } - var interceptors: Grpc_Reflection_V1_ServerReflectionServerInterceptorFactoryProtocol? { get } - - /// The reflection service is structured as a bidirectional stream, ensuring - /// all related requests go to a single server. - func serverReflectionInfo( - requestStream: GRPCAsyncRequestStream, - responseStream: GRPCAsyncResponseStreamWriter, - context: GRPCAsyncServerCallContext - ) async throws -} - -extension Grpc_Reflection_V1_ServerReflectionAsyncProvider { - internal static var serviceDescriptor: GRPCServiceDescriptor { - return Grpc_Reflection_V1_ServerReflectionServerMetadata.serviceDescriptor - } - - internal var serviceName: Substring { - return Grpc_Reflection_V1_ServerReflectionServerMetadata.serviceDescriptor.fullName[...] - } - - internal var interceptors: Grpc_Reflection_V1_ServerReflectionServerInterceptorFactoryProtocol? { - return nil - } - - internal func handle( - method name: Substring, - context: CallHandlerContext - ) -> GRPCServerHandlerProtocol? { - switch name { - case "ServerReflectionInfo": - return GRPCAsyncServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeServerReflectionInfoInterceptors() ?? [], - wrapping: { try await self.serverReflectionInfo(requestStream: $0, responseStream: $1, context: $2) } - ) - - default: - return nil - } - } -} - -internal protocol Grpc_Reflection_V1_ServerReflectionServerInterceptorFactoryProtocol: Sendable { - - /// - Returns: Interceptors to use when handling 'serverReflectionInfo'. - /// Defaults to calling `self.makeInterceptors()`. - func makeServerReflectionInfoInterceptors() -> [ServerInterceptor] -} - -internal enum Grpc_Reflection_V1_ServerReflectionServerMetadata { - internal static let serviceDescriptor = GRPCServiceDescriptor( - name: "ServerReflection", - fullName: "grpc.reflection.v1.ServerReflection", - methods: [ - Grpc_Reflection_V1_ServerReflectionServerMetadata.Methods.serverReflectionInfo, - ] - ) - - internal enum Methods { - internal static let serverReflectionInfo = GRPCMethodDescriptor( - name: "ServerReflectionInfo", - path: "/grpc.reflection.v1.ServerReflection/ServerReflectionInfo", - type: GRPCCallType.bidirectionalStreaming - ) - } -} diff --git a/Sources/GRPCReflectionService/v1/reflection-v1.pb.swift b/Sources/GRPCReflectionService/v1/reflection-v1.pb.swift deleted file mode 100644 index 0d15778..0000000 --- a/Sources/GRPCReflectionService/v1/reflection-v1.pb.swift +++ /dev/null @@ -1,775 +0,0 @@ -// DO NOT EDIT. -// swift-format-ignore-file -// swiftlint:disable all -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: reflection.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/apple/swift-protobuf/ - -// Copyright 2016 The gRPC Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Service exported by server reflection. A more complete description of how -// server reflection works can be found at -// https://github.com/grpc/grpc/blob/master/doc/server-reflection.md -// -// The canonical version of this proto can be found at -// https://github.com/grpc/grpc-proto/blob/master/grpc/reflection/v1/reflection.proto - -import Foundation -import SwiftProtobuf - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that you are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// The message sent by the client when calling ServerReflectionInfo method. -public struct Grpc_Reflection_V1_ServerReflectionRequest: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - public var host: String = String() - - /// To use reflection service, the client should set one of the following - /// fields in message_request. The server distinguishes requests by their - /// defined field and then handles them using corresponding methods. - public var messageRequest: Grpc_Reflection_V1_ServerReflectionRequest.OneOf_MessageRequest? = nil - - /// Find a proto file by the file name. - public var fileByFilename: String { - get { - if case .fileByFilename(let v)? = messageRequest {return v} - return String() - } - set {messageRequest = .fileByFilename(newValue)} - } - - /// Find the proto file that declares the given fully-qualified symbol name. - /// This field should be a fully-qualified symbol name - /// (e.g. .[.] or .). - public var fileContainingSymbol: String { - get { - if case .fileContainingSymbol(let v)? = messageRequest {return v} - return String() - } - set {messageRequest = .fileContainingSymbol(newValue)} - } - - /// Find the proto file which defines an extension extending the given - /// message type with the given field number. - public var fileContainingExtension: Grpc_Reflection_V1_ExtensionRequest { - get { - if case .fileContainingExtension(let v)? = messageRequest {return v} - return Grpc_Reflection_V1_ExtensionRequest() - } - set {messageRequest = .fileContainingExtension(newValue)} - } - - /// Finds the tag numbers used by all known extensions of the given message - /// type, and appends them to ExtensionNumberResponse in an undefined order. - /// Its corresponding method is best-effort: it's not guaranteed that the - /// reflection service will implement this method, and it's not guaranteed - /// that this method will provide all extensions. Returns - /// StatusCode::UNIMPLEMENTED if it's not implemented. - /// This field should be a fully-qualified type name. The format is - /// . - public var allExtensionNumbersOfType: String { - get { - if case .allExtensionNumbersOfType(let v)? = messageRequest {return v} - return String() - } - set {messageRequest = .allExtensionNumbersOfType(newValue)} - } - - /// List the full names of registered services. The content will not be - /// checked. - public var listServices: String { - get { - if case .listServices(let v)? = messageRequest {return v} - return String() - } - set {messageRequest = .listServices(newValue)} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - /// To use reflection service, the client should set one of the following - /// fields in message_request. The server distinguishes requests by their - /// defined field and then handles them using corresponding methods. - public enum OneOf_MessageRequest: Equatable, Sendable { - /// Find a proto file by the file name. - case fileByFilename(String) - /// Find the proto file that declares the given fully-qualified symbol name. - /// This field should be a fully-qualified symbol name - /// (e.g. .[.] or .). - case fileContainingSymbol(String) - /// Find the proto file which defines an extension extending the given - /// message type with the given field number. - case fileContainingExtension(Grpc_Reflection_V1_ExtensionRequest) - /// Finds the tag numbers used by all known extensions of the given message - /// type, and appends them to ExtensionNumberResponse in an undefined order. - /// Its corresponding method is best-effort: it's not guaranteed that the - /// reflection service will implement this method, and it's not guaranteed - /// that this method will provide all extensions. Returns - /// StatusCode::UNIMPLEMENTED if it's not implemented. - /// This field should be a fully-qualified type name. The format is - /// . - case allExtensionNumbersOfType(String) - /// List the full names of registered services. The content will not be - /// checked. - case listServices(String) - - } - - public init() {} -} - -/// The type name and extension number sent by the client when requesting -/// file_containing_extension. -public struct Grpc_Reflection_V1_ExtensionRequest: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Fully-qualified type name. The format should be . - public var containingType: String = String() - - public var extensionNumber: Int32 = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// The message sent by the server to answer ServerReflectionInfo method. -public struct Grpc_Reflection_V1_ServerReflectionResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - public var validHost: String = String() - - public var originalRequest: Grpc_Reflection_V1_ServerReflectionRequest { - get {return _originalRequest ?? Grpc_Reflection_V1_ServerReflectionRequest()} - set {_originalRequest = newValue} - } - /// Returns true if `originalRequest` has been explicitly set. - public var hasOriginalRequest: Bool {return self._originalRequest != nil} - /// Clears the value of `originalRequest`. Subsequent reads from it will return its default value. - public mutating func clearOriginalRequest() {self._originalRequest = nil} - - /// The server sets one of the following fields according to the message_request - /// in the request. - public var messageResponse: Grpc_Reflection_V1_ServerReflectionResponse.OneOf_MessageResponse? = nil - - /// This message is used to answer file_by_filename, file_containing_symbol, - /// file_containing_extension requests with transitive dependencies. - /// As the repeated label is not allowed in oneof fields, we use a - /// FileDescriptorResponse message to encapsulate the repeated fields. - /// The reflection service is allowed to avoid sending FileDescriptorProtos - /// that were previously sent in response to earlier requests in the stream. - public var fileDescriptorResponse: Grpc_Reflection_V1_FileDescriptorResponse { - get { - if case .fileDescriptorResponse(let v)? = messageResponse {return v} - return Grpc_Reflection_V1_FileDescriptorResponse() - } - set {messageResponse = .fileDescriptorResponse(newValue)} - } - - /// This message is used to answer all_extension_numbers_of_type requests. - public var allExtensionNumbersResponse: Grpc_Reflection_V1_ExtensionNumberResponse { - get { - if case .allExtensionNumbersResponse(let v)? = messageResponse {return v} - return Grpc_Reflection_V1_ExtensionNumberResponse() - } - set {messageResponse = .allExtensionNumbersResponse(newValue)} - } - - /// This message is used to answer list_services requests. - public var listServicesResponse: Grpc_Reflection_V1_ListServiceResponse { - get { - if case .listServicesResponse(let v)? = messageResponse {return v} - return Grpc_Reflection_V1_ListServiceResponse() - } - set {messageResponse = .listServicesResponse(newValue)} - } - - /// This message is used when an error occurs. - public var errorResponse: Grpc_Reflection_V1_ErrorResponse { - get { - if case .errorResponse(let v)? = messageResponse {return v} - return Grpc_Reflection_V1_ErrorResponse() - } - set {messageResponse = .errorResponse(newValue)} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - /// The server sets one of the following fields according to the message_request - /// in the request. - public enum OneOf_MessageResponse: Equatable, Sendable { - /// This message is used to answer file_by_filename, file_containing_symbol, - /// file_containing_extension requests with transitive dependencies. - /// As the repeated label is not allowed in oneof fields, we use a - /// FileDescriptorResponse message to encapsulate the repeated fields. - /// The reflection service is allowed to avoid sending FileDescriptorProtos - /// that were previously sent in response to earlier requests in the stream. - case fileDescriptorResponse(Grpc_Reflection_V1_FileDescriptorResponse) - /// This message is used to answer all_extension_numbers_of_type requests. - case allExtensionNumbersResponse(Grpc_Reflection_V1_ExtensionNumberResponse) - /// This message is used to answer list_services requests. - case listServicesResponse(Grpc_Reflection_V1_ListServiceResponse) - /// This message is used when an error occurs. - case errorResponse(Grpc_Reflection_V1_ErrorResponse) - - } - - public init() {} - - fileprivate var _originalRequest: Grpc_Reflection_V1_ServerReflectionRequest? = nil -} - -/// Serialized FileDescriptorProto messages sent by the server answering -/// a file_by_filename, file_containing_symbol, or file_containing_extension -/// request. -public struct Grpc_Reflection_V1_FileDescriptorResponse: @unchecked Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Serialized FileDescriptorProto messages. We avoid taking a dependency on - /// descriptor.proto, which uses proto2 only features, by making them opaque - /// bytes instead. - public var fileDescriptorProto: [Data] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// A list of extension numbers sent by the server answering -/// all_extension_numbers_of_type request. -public struct Grpc_Reflection_V1_ExtensionNumberResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Full name of the base type, including the package name. The format - /// is . - public var baseTypeName: String = String() - - public var extensionNumber: [Int32] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// A list of ServiceResponse sent by the server answering list_services request. -public struct Grpc_Reflection_V1_ListServiceResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The information of each service may be expanded in the future, so we use - /// ServiceResponse message to encapsulate it. - public var service: [Grpc_Reflection_V1_ServiceResponse] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// The information of a single service used by ListServiceResponse to answer -/// list_services request. -public struct Grpc_Reflection_V1_ServiceResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Full name of a registered service, including its package name. The format - /// is . - public var name: String = String() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// The error code and error message sent by the server when an error occurs. -public struct Grpc_Reflection_V1_ErrorResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// This field uses the error codes defined in grpc::StatusCode. - public var errorCode: Int32 = 0 - - public var errorMessage: String = String() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "grpc.reflection.v1" - -extension Grpc_Reflection_V1_ServerReflectionRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ServerReflectionRequest" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "host"), - 3: .standard(proto: "file_by_filename"), - 4: .standard(proto: "file_containing_symbol"), - 5: .standard(proto: "file_containing_extension"), - 6: .standard(proto: "all_extension_numbers_of_type"), - 7: .standard(proto: "list_services"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.host) }() - case 3: try { - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v { - if self.messageRequest != nil {try decoder.handleConflictingOneOf()} - self.messageRequest = .fileByFilename(v) - } - }() - case 4: try { - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v { - if self.messageRequest != nil {try decoder.handleConflictingOneOf()} - self.messageRequest = .fileContainingSymbol(v) - } - }() - case 5: try { - var v: Grpc_Reflection_V1_ExtensionRequest? - var hadOneofValue = false - if let current = self.messageRequest { - hadOneofValue = true - if case .fileContainingExtension(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageRequest = .fileContainingExtension(v) - } - }() - case 6: try { - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v { - if self.messageRequest != nil {try decoder.handleConflictingOneOf()} - self.messageRequest = .allExtensionNumbersOfType(v) - } - }() - case 7: try { - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v { - if self.messageRequest != nil {try decoder.handleConflictingOneOf()} - self.messageRequest = .listServices(v) - } - }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - if !self.host.isEmpty { - try visitor.visitSingularStringField(value: self.host, fieldNumber: 1) - } - switch self.messageRequest { - case .fileByFilename?: try { - guard case .fileByFilename(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularStringField(value: v, fieldNumber: 3) - }() - case .fileContainingSymbol?: try { - guard case .fileContainingSymbol(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularStringField(value: v, fieldNumber: 4) - }() - case .fileContainingExtension?: try { - guard case .fileContainingExtension(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - }() - case .allExtensionNumbersOfType?: try { - guard case .allExtensionNumbersOfType(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularStringField(value: v, fieldNumber: 6) - }() - case .listServices?: try { - guard case .listServices(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularStringField(value: v, fieldNumber: 7) - }() - case nil: break - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1_ServerReflectionRequest, rhs: Grpc_Reflection_V1_ServerReflectionRequest) -> Bool { - if lhs.host != rhs.host {return false} - if lhs.messageRequest != rhs.messageRequest {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1_ExtensionRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ExtensionRequest" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "containing_type"), - 2: .standard(proto: "extension_number"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.containingType) }() - case 2: try { try decoder.decodeSingularInt32Field(value: &self.extensionNumber) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.containingType.isEmpty { - try visitor.visitSingularStringField(value: self.containingType, fieldNumber: 1) - } - if self.extensionNumber != 0 { - try visitor.visitSingularInt32Field(value: self.extensionNumber, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1_ExtensionRequest, rhs: Grpc_Reflection_V1_ExtensionRequest) -> Bool { - if lhs.containingType != rhs.containingType {return false} - if lhs.extensionNumber != rhs.extensionNumber {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1_ServerReflectionResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ServerReflectionResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "valid_host"), - 2: .standard(proto: "original_request"), - 4: .standard(proto: "file_descriptor_response"), - 5: .standard(proto: "all_extension_numbers_response"), - 6: .standard(proto: "list_services_response"), - 7: .standard(proto: "error_response"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.validHost) }() - case 2: try { try decoder.decodeSingularMessageField(value: &self._originalRequest) }() - case 4: try { - var v: Grpc_Reflection_V1_FileDescriptorResponse? - var hadOneofValue = false - if let current = self.messageResponse { - hadOneofValue = true - if case .fileDescriptorResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageResponse = .fileDescriptorResponse(v) - } - }() - case 5: try { - var v: Grpc_Reflection_V1_ExtensionNumberResponse? - var hadOneofValue = false - if let current = self.messageResponse { - hadOneofValue = true - if case .allExtensionNumbersResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageResponse = .allExtensionNumbersResponse(v) - } - }() - case 6: try { - var v: Grpc_Reflection_V1_ListServiceResponse? - var hadOneofValue = false - if let current = self.messageResponse { - hadOneofValue = true - if case .listServicesResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageResponse = .listServicesResponse(v) - } - }() - case 7: try { - var v: Grpc_Reflection_V1_ErrorResponse? - var hadOneofValue = false - if let current = self.messageResponse { - hadOneofValue = true - if case .errorResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageResponse = .errorResponse(v) - } - }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - if !self.validHost.isEmpty { - try visitor.visitSingularStringField(value: self.validHost, fieldNumber: 1) - } - try { if let v = self._originalRequest { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } }() - switch self.messageResponse { - case .fileDescriptorResponse?: try { - guard case .fileDescriptorResponse(let v)? = self.messageResponse else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 4) - }() - case .allExtensionNumbersResponse?: try { - guard case .allExtensionNumbersResponse(let v)? = self.messageResponse else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - }() - case .listServicesResponse?: try { - guard case .listServicesResponse(let v)? = self.messageResponse else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 6) - }() - case .errorResponse?: try { - guard case .errorResponse(let v)? = self.messageResponse else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 7) - }() - case nil: break - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1_ServerReflectionResponse, rhs: Grpc_Reflection_V1_ServerReflectionResponse) -> Bool { - if lhs.validHost != rhs.validHost {return false} - if lhs._originalRequest != rhs._originalRequest {return false} - if lhs.messageResponse != rhs.messageResponse {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1_FileDescriptorResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".FileDescriptorResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "file_descriptor_proto"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeRepeatedBytesField(value: &self.fileDescriptorProto) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.fileDescriptorProto.isEmpty { - try visitor.visitRepeatedBytesField(value: self.fileDescriptorProto, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1_FileDescriptorResponse, rhs: Grpc_Reflection_V1_FileDescriptorResponse) -> Bool { - if lhs.fileDescriptorProto != rhs.fileDescriptorProto {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1_ExtensionNumberResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ExtensionNumberResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "base_type_name"), - 2: .standard(proto: "extension_number"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.baseTypeName) }() - case 2: try { try decoder.decodeRepeatedInt32Field(value: &self.extensionNumber) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.baseTypeName.isEmpty { - try visitor.visitSingularStringField(value: self.baseTypeName, fieldNumber: 1) - } - if !self.extensionNumber.isEmpty { - try visitor.visitPackedInt32Field(value: self.extensionNumber, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1_ExtensionNumberResponse, rhs: Grpc_Reflection_V1_ExtensionNumberResponse) -> Bool { - if lhs.baseTypeName != rhs.baseTypeName {return false} - if lhs.extensionNumber != rhs.extensionNumber {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1_ListServiceResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ListServiceResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "service"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeRepeatedMessageField(value: &self.service) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.service.isEmpty { - try visitor.visitRepeatedMessageField(value: self.service, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1_ListServiceResponse, rhs: Grpc_Reflection_V1_ListServiceResponse) -> Bool { - if lhs.service != rhs.service {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1_ServiceResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ServiceResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1_ServiceResponse, rhs: Grpc_Reflection_V1_ServiceResponse) -> Bool { - if lhs.name != rhs.name {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1_ErrorResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ErrorResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "error_code"), - 2: .standard(proto: "error_message"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularInt32Field(value: &self.errorCode) }() - case 2: try { try decoder.decodeSingularStringField(value: &self.errorMessage) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.errorCode != 0 { - try visitor.visitSingularInt32Field(value: self.errorCode, fieldNumber: 1) - } - if !self.errorMessage.isEmpty { - try visitor.visitSingularStringField(value: self.errorMessage, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1_ErrorResponse, rhs: Grpc_Reflection_V1_ErrorResponse) -> Bool { - if lhs.errorCode != rhs.errorCode {return false} - if lhs.errorMessage != rhs.errorMessage {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.grpc.swift b/Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.grpc.swift deleted file mode 100644 index 17b307c..0000000 --- a/Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.grpc.swift +++ /dev/null @@ -1,120 +0,0 @@ -// -// DO NOT EDIT. -// swift-format-ignore-file -// -// Generated by the protocol buffer compiler. -// Source: reflection.proto -// -import GRPC -import NIO -import NIOConcurrencyHelpers -import SwiftProtobuf - - -/// To build a server, implement a class that conforms to this protocol. -internal protocol Grpc_Reflection_V1alpha_ServerReflectionProvider: CallHandlerProvider { - var interceptors: Grpc_Reflection_V1alpha_ServerReflectionServerInterceptorFactoryProtocol? { get } - - /// The reflection service is structured as a bidirectional stream, ensuring - /// all related requests go to a single server. - func serverReflectionInfo(context: StreamingResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> -} - -extension Grpc_Reflection_V1alpha_ServerReflectionProvider { - internal var serviceName: Substring { - return Grpc_Reflection_V1alpha_ServerReflectionServerMetadata.serviceDescriptor.fullName[...] - } - - /// Determines, calls and returns the appropriate request handler, depending on the request's method. - /// Returns nil for methods not handled by this service. - internal func handle( - method name: Substring, - context: CallHandlerContext - ) -> GRPCServerHandlerProtocol? { - switch name { - case "ServerReflectionInfo": - return BidirectionalStreamingServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeServerReflectionInfoInterceptors() ?? [], - observerFactory: self.serverReflectionInfo(context:) - ) - - default: - return nil - } - } -} - -/// To implement a server, implement an object which conforms to this protocol. -internal protocol Grpc_Reflection_V1alpha_ServerReflectionAsyncProvider: CallHandlerProvider, Sendable { - static var serviceDescriptor: GRPCServiceDescriptor { get } - var interceptors: Grpc_Reflection_V1alpha_ServerReflectionServerInterceptorFactoryProtocol? { get } - - /// The reflection service is structured as a bidirectional stream, ensuring - /// all related requests go to a single server. - func serverReflectionInfo( - requestStream: GRPCAsyncRequestStream, - responseStream: GRPCAsyncResponseStreamWriter, - context: GRPCAsyncServerCallContext - ) async throws -} - -extension Grpc_Reflection_V1alpha_ServerReflectionAsyncProvider { - internal static var serviceDescriptor: GRPCServiceDescriptor { - return Grpc_Reflection_V1alpha_ServerReflectionServerMetadata.serviceDescriptor - } - - internal var serviceName: Substring { - return Grpc_Reflection_V1alpha_ServerReflectionServerMetadata.serviceDescriptor.fullName[...] - } - - internal var interceptors: Grpc_Reflection_V1alpha_ServerReflectionServerInterceptorFactoryProtocol? { - return nil - } - - internal func handle( - method name: Substring, - context: CallHandlerContext - ) -> GRPCServerHandlerProtocol? { - switch name { - case "ServerReflectionInfo": - return GRPCAsyncServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeServerReflectionInfoInterceptors() ?? [], - wrapping: { try await self.serverReflectionInfo(requestStream: $0, responseStream: $1, context: $2) } - ) - - default: - return nil - } - } -} - -internal protocol Grpc_Reflection_V1alpha_ServerReflectionServerInterceptorFactoryProtocol: Sendable { - - /// - Returns: Interceptors to use when handling 'serverReflectionInfo'. - /// Defaults to calling `self.makeInterceptors()`. - func makeServerReflectionInfoInterceptors() -> [ServerInterceptor] -} - -internal enum Grpc_Reflection_V1alpha_ServerReflectionServerMetadata { - internal static let serviceDescriptor = GRPCServiceDescriptor( - name: "ServerReflection", - fullName: "grpc.reflection.v1alpha.ServerReflection", - methods: [ - Grpc_Reflection_V1alpha_ServerReflectionServerMetadata.Methods.serverReflectionInfo, - ] - ) - - internal enum Methods { - internal static let serverReflectionInfo = GRPCMethodDescriptor( - name: "ServerReflectionInfo", - path: "/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo", - type: GRPCCallType.bidirectionalStreaming - ) - } -} diff --git a/Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.pb.swift b/Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.pb.swift deleted file mode 100644 index 5560e7d..0000000 --- a/Sources/GRPCReflectionService/v1Alpha/reflection-v1alpha.pb.swift +++ /dev/null @@ -1,788 +0,0 @@ -// DO NOT EDIT. -// swift-format-ignore-file -// swiftlint:disable all -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: reflection.proto -// -// For information on using the generated types, please see the documentation: -// https://github.com/apple/swift-protobuf/ - -// Copyright 2016 The gRPC Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// Service exported by server reflection - -// Warning: this entire file is deprecated. Use this instead: -// https://github.com/grpc/grpc-proto/blob/master/grpc/reflection/v1/reflection.proto - -import Foundation -import SwiftProtobuf - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that you are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// The message sent by the client when calling ServerReflectionInfo method. -/// -/// NOTE: The whole .proto file that defined this message was marked as deprecated. -public struct Grpc_Reflection_V1alpha_ServerReflectionRequest: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - public var host: String = String() - - /// To use reflection service, the client should set one of the following - /// fields in message_request. The server distinguishes requests by their - /// defined field and then handles them using corresponding methods. - public var messageRequest: Grpc_Reflection_V1alpha_ServerReflectionRequest.OneOf_MessageRequest? = nil - - /// Find a proto file by the file name. - public var fileByFilename: String { - get { - if case .fileByFilename(let v)? = messageRequest {return v} - return String() - } - set {messageRequest = .fileByFilename(newValue)} - } - - /// Find the proto file that declares the given fully-qualified symbol name. - /// This field should be a fully-qualified symbol name - /// (e.g. .[.] or .). - public var fileContainingSymbol: String { - get { - if case .fileContainingSymbol(let v)? = messageRequest {return v} - return String() - } - set {messageRequest = .fileContainingSymbol(newValue)} - } - - /// Find the proto file which defines an extension extending the given - /// message type with the given field number. - public var fileContainingExtension: Grpc_Reflection_V1alpha_ExtensionRequest { - get { - if case .fileContainingExtension(let v)? = messageRequest {return v} - return Grpc_Reflection_V1alpha_ExtensionRequest() - } - set {messageRequest = .fileContainingExtension(newValue)} - } - - /// Finds the tag numbers used by all known extensions of extendee_type, and - /// appends them to ExtensionNumberResponse in an undefined order. - /// Its corresponding method is best-effort: it's not guaranteed that the - /// reflection service will implement this method, and it's not guaranteed - /// that this method will provide all extensions. Returns - /// StatusCode::UNIMPLEMENTED if it's not implemented. - /// This field should be a fully-qualified type name. The format is - /// . - public var allExtensionNumbersOfType: String { - get { - if case .allExtensionNumbersOfType(let v)? = messageRequest {return v} - return String() - } - set {messageRequest = .allExtensionNumbersOfType(newValue)} - } - - /// List the full names of registered services. The content will not be - /// checked. - public var listServices: String { - get { - if case .listServices(let v)? = messageRequest {return v} - return String() - } - set {messageRequest = .listServices(newValue)} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - /// To use reflection service, the client should set one of the following - /// fields in message_request. The server distinguishes requests by their - /// defined field and then handles them using corresponding methods. - public enum OneOf_MessageRequest: Equatable, Sendable { - /// Find a proto file by the file name. - case fileByFilename(String) - /// Find the proto file that declares the given fully-qualified symbol name. - /// This field should be a fully-qualified symbol name - /// (e.g. .[.] or .). - case fileContainingSymbol(String) - /// Find the proto file which defines an extension extending the given - /// message type with the given field number. - case fileContainingExtension(Grpc_Reflection_V1alpha_ExtensionRequest) - /// Finds the tag numbers used by all known extensions of extendee_type, and - /// appends them to ExtensionNumberResponse in an undefined order. - /// Its corresponding method is best-effort: it's not guaranteed that the - /// reflection service will implement this method, and it's not guaranteed - /// that this method will provide all extensions. Returns - /// StatusCode::UNIMPLEMENTED if it's not implemented. - /// This field should be a fully-qualified type name. The format is - /// . - case allExtensionNumbersOfType(String) - /// List the full names of registered services. The content will not be - /// checked. - case listServices(String) - - } - - public init() {} -} - -/// The type name and extension number sent by the client when requesting -/// file_containing_extension. -/// -/// NOTE: The whole .proto file that defined this message was marked as deprecated. -public struct Grpc_Reflection_V1alpha_ExtensionRequest: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Fully-qualified type name. The format should be . - public var containingType: String = String() - - public var extensionNumber: Int32 = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// The message sent by the server to answer ServerReflectionInfo method. -/// -/// NOTE: The whole .proto file that defined this message was marked as deprecated. -public struct Grpc_Reflection_V1alpha_ServerReflectionResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - public var validHost: String = String() - - public var originalRequest: Grpc_Reflection_V1alpha_ServerReflectionRequest { - get {return _originalRequest ?? Grpc_Reflection_V1alpha_ServerReflectionRequest()} - set {_originalRequest = newValue} - } - /// Returns true if `originalRequest` has been explicitly set. - public var hasOriginalRequest: Bool {return self._originalRequest != nil} - /// Clears the value of `originalRequest`. Subsequent reads from it will return its default value. - public mutating func clearOriginalRequest() {self._originalRequest = nil} - - /// The server set one of the following fields according to the message_request - /// in the request. - public var messageResponse: Grpc_Reflection_V1alpha_ServerReflectionResponse.OneOf_MessageResponse? = nil - - /// This message is used to answer file_by_filename, file_containing_symbol, - /// file_containing_extension requests with transitive dependencies. As - /// the repeated label is not allowed in oneof fields, we use a - /// FileDescriptorResponse message to encapsulate the repeated fields. - /// The reflection service is allowed to avoid sending FileDescriptorProtos - /// that were previously sent in response to earlier requests in the stream. - public var fileDescriptorResponse: Grpc_Reflection_V1alpha_FileDescriptorResponse { - get { - if case .fileDescriptorResponse(let v)? = messageResponse {return v} - return Grpc_Reflection_V1alpha_FileDescriptorResponse() - } - set {messageResponse = .fileDescriptorResponse(newValue)} - } - - /// This message is used to answer all_extension_numbers_of_type requst. - public var allExtensionNumbersResponse: Grpc_Reflection_V1alpha_ExtensionNumberResponse { - get { - if case .allExtensionNumbersResponse(let v)? = messageResponse {return v} - return Grpc_Reflection_V1alpha_ExtensionNumberResponse() - } - set {messageResponse = .allExtensionNumbersResponse(newValue)} - } - - /// This message is used to answer list_services request. - public var listServicesResponse: Grpc_Reflection_V1alpha_ListServiceResponse { - get { - if case .listServicesResponse(let v)? = messageResponse {return v} - return Grpc_Reflection_V1alpha_ListServiceResponse() - } - set {messageResponse = .listServicesResponse(newValue)} - } - - /// This message is used when an error occurs. - public var errorResponse: Grpc_Reflection_V1alpha_ErrorResponse { - get { - if case .errorResponse(let v)? = messageResponse {return v} - return Grpc_Reflection_V1alpha_ErrorResponse() - } - set {messageResponse = .errorResponse(newValue)} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - /// The server set one of the following fields according to the message_request - /// in the request. - public enum OneOf_MessageResponse: Equatable, Sendable { - /// This message is used to answer file_by_filename, file_containing_symbol, - /// file_containing_extension requests with transitive dependencies. As - /// the repeated label is not allowed in oneof fields, we use a - /// FileDescriptorResponse message to encapsulate the repeated fields. - /// The reflection service is allowed to avoid sending FileDescriptorProtos - /// that were previously sent in response to earlier requests in the stream. - case fileDescriptorResponse(Grpc_Reflection_V1alpha_FileDescriptorResponse) - /// This message is used to answer all_extension_numbers_of_type requst. - case allExtensionNumbersResponse(Grpc_Reflection_V1alpha_ExtensionNumberResponse) - /// This message is used to answer list_services request. - case listServicesResponse(Grpc_Reflection_V1alpha_ListServiceResponse) - /// This message is used when an error occurs. - case errorResponse(Grpc_Reflection_V1alpha_ErrorResponse) - - } - - public init() {} - - fileprivate var _originalRequest: Grpc_Reflection_V1alpha_ServerReflectionRequest? = nil -} - -/// Serialized FileDescriptorProto messages sent by the server answering -/// a file_by_filename, file_containing_symbol, or file_containing_extension -/// request. -/// -/// NOTE: The whole .proto file that defined this message was marked as deprecated. -public struct Grpc_Reflection_V1alpha_FileDescriptorResponse: @unchecked Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Serialized FileDescriptorProto messages. We avoid taking a dependency on - /// descriptor.proto, which uses proto2 only features, by making them opaque - /// bytes instead. - public var fileDescriptorProto: [Data] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// A list of extension numbers sent by the server answering -/// all_extension_numbers_of_type request. -/// -/// NOTE: The whole .proto file that defined this message was marked as deprecated. -public struct Grpc_Reflection_V1alpha_ExtensionNumberResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Full name of the base type, including the package name. The format - /// is . - public var baseTypeName: String = String() - - public var extensionNumber: [Int32] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// A list of ServiceResponse sent by the server answering list_services request. -/// -/// NOTE: The whole .proto file that defined this message was marked as deprecated. -public struct Grpc_Reflection_V1alpha_ListServiceResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The information of each service may be expanded in the future, so we use - /// ServiceResponse message to encapsulate it. - public var service: [Grpc_Reflection_V1alpha_ServiceResponse] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// The information of a single service used by ListServiceResponse to answer -/// list_services request. -/// -/// NOTE: The whole .proto file that defined this message was marked as deprecated. -public struct Grpc_Reflection_V1alpha_ServiceResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Full name of a registered service, including its package name. The format - /// is . - public var name: String = String() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// The error code and error message sent by the server when an error occurs. -/// -/// NOTE: The whole .proto file that defined this message was marked as deprecated. -public struct Grpc_Reflection_V1alpha_ErrorResponse: Sendable { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// This field uses the error codes defined in grpc::StatusCode. - public var errorCode: Int32 = 0 - - public var errorMessage: String = String() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "grpc.reflection.v1alpha" - -extension Grpc_Reflection_V1alpha_ServerReflectionRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ServerReflectionRequest" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "host"), - 3: .standard(proto: "file_by_filename"), - 4: .standard(proto: "file_containing_symbol"), - 5: .standard(proto: "file_containing_extension"), - 6: .standard(proto: "all_extension_numbers_of_type"), - 7: .standard(proto: "list_services"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.host) }() - case 3: try { - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v { - if self.messageRequest != nil {try decoder.handleConflictingOneOf()} - self.messageRequest = .fileByFilename(v) - } - }() - case 4: try { - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v { - if self.messageRequest != nil {try decoder.handleConflictingOneOf()} - self.messageRequest = .fileContainingSymbol(v) - } - }() - case 5: try { - var v: Grpc_Reflection_V1alpha_ExtensionRequest? - var hadOneofValue = false - if let current = self.messageRequest { - hadOneofValue = true - if case .fileContainingExtension(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageRequest = .fileContainingExtension(v) - } - }() - case 6: try { - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v { - if self.messageRequest != nil {try decoder.handleConflictingOneOf()} - self.messageRequest = .allExtensionNumbersOfType(v) - } - }() - case 7: try { - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v { - if self.messageRequest != nil {try decoder.handleConflictingOneOf()} - self.messageRequest = .listServices(v) - } - }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - if !self.host.isEmpty { - try visitor.visitSingularStringField(value: self.host, fieldNumber: 1) - } - switch self.messageRequest { - case .fileByFilename?: try { - guard case .fileByFilename(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularStringField(value: v, fieldNumber: 3) - }() - case .fileContainingSymbol?: try { - guard case .fileContainingSymbol(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularStringField(value: v, fieldNumber: 4) - }() - case .fileContainingExtension?: try { - guard case .fileContainingExtension(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - }() - case .allExtensionNumbersOfType?: try { - guard case .allExtensionNumbersOfType(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularStringField(value: v, fieldNumber: 6) - }() - case .listServices?: try { - guard case .listServices(let v)? = self.messageRequest else { preconditionFailure() } - try visitor.visitSingularStringField(value: v, fieldNumber: 7) - }() - case nil: break - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1alpha_ServerReflectionRequest, rhs: Grpc_Reflection_V1alpha_ServerReflectionRequest) -> Bool { - if lhs.host != rhs.host {return false} - if lhs.messageRequest != rhs.messageRequest {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1alpha_ExtensionRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ExtensionRequest" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "containing_type"), - 2: .standard(proto: "extension_number"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.containingType) }() - case 2: try { try decoder.decodeSingularInt32Field(value: &self.extensionNumber) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.containingType.isEmpty { - try visitor.visitSingularStringField(value: self.containingType, fieldNumber: 1) - } - if self.extensionNumber != 0 { - try visitor.visitSingularInt32Field(value: self.extensionNumber, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1alpha_ExtensionRequest, rhs: Grpc_Reflection_V1alpha_ExtensionRequest) -> Bool { - if lhs.containingType != rhs.containingType {return false} - if lhs.extensionNumber != rhs.extensionNumber {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1alpha_ServerReflectionResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ServerReflectionResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "valid_host"), - 2: .standard(proto: "original_request"), - 4: .standard(proto: "file_descriptor_response"), - 5: .standard(proto: "all_extension_numbers_response"), - 6: .standard(proto: "list_services_response"), - 7: .standard(proto: "error_response"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.validHost) }() - case 2: try { try decoder.decodeSingularMessageField(value: &self._originalRequest) }() - case 4: try { - var v: Grpc_Reflection_V1alpha_FileDescriptorResponse? - var hadOneofValue = false - if let current = self.messageResponse { - hadOneofValue = true - if case .fileDescriptorResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageResponse = .fileDescriptorResponse(v) - } - }() - case 5: try { - var v: Grpc_Reflection_V1alpha_ExtensionNumberResponse? - var hadOneofValue = false - if let current = self.messageResponse { - hadOneofValue = true - if case .allExtensionNumbersResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageResponse = .allExtensionNumbersResponse(v) - } - }() - case 6: try { - var v: Grpc_Reflection_V1alpha_ListServiceResponse? - var hadOneofValue = false - if let current = self.messageResponse { - hadOneofValue = true - if case .listServicesResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageResponse = .listServicesResponse(v) - } - }() - case 7: try { - var v: Grpc_Reflection_V1alpha_ErrorResponse? - var hadOneofValue = false - if let current = self.messageResponse { - hadOneofValue = true - if case .errorResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.messageResponse = .errorResponse(v) - } - }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every if/case branch local when no optimizations - // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and - // https://github.com/apple/swift-protobuf/issues/1182 - if !self.validHost.isEmpty { - try visitor.visitSingularStringField(value: self.validHost, fieldNumber: 1) - } - try { if let v = self._originalRequest { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } }() - switch self.messageResponse { - case .fileDescriptorResponse?: try { - guard case .fileDescriptorResponse(let v)? = self.messageResponse else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 4) - }() - case .allExtensionNumbersResponse?: try { - guard case .allExtensionNumbersResponse(let v)? = self.messageResponse else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - }() - case .listServicesResponse?: try { - guard case .listServicesResponse(let v)? = self.messageResponse else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 6) - }() - case .errorResponse?: try { - guard case .errorResponse(let v)? = self.messageResponse else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 7) - }() - case nil: break - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1alpha_ServerReflectionResponse, rhs: Grpc_Reflection_V1alpha_ServerReflectionResponse) -> Bool { - if lhs.validHost != rhs.validHost {return false} - if lhs._originalRequest != rhs._originalRequest {return false} - if lhs.messageResponse != rhs.messageResponse {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1alpha_FileDescriptorResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".FileDescriptorResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "file_descriptor_proto"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeRepeatedBytesField(value: &self.fileDescriptorProto) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.fileDescriptorProto.isEmpty { - try visitor.visitRepeatedBytesField(value: self.fileDescriptorProto, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1alpha_FileDescriptorResponse, rhs: Grpc_Reflection_V1alpha_FileDescriptorResponse) -> Bool { - if lhs.fileDescriptorProto != rhs.fileDescriptorProto {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1alpha_ExtensionNumberResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ExtensionNumberResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "base_type_name"), - 2: .standard(proto: "extension_number"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.baseTypeName) }() - case 2: try { try decoder.decodeRepeatedInt32Field(value: &self.extensionNumber) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.baseTypeName.isEmpty { - try visitor.visitSingularStringField(value: self.baseTypeName, fieldNumber: 1) - } - if !self.extensionNumber.isEmpty { - try visitor.visitPackedInt32Field(value: self.extensionNumber, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1alpha_ExtensionNumberResponse, rhs: Grpc_Reflection_V1alpha_ExtensionNumberResponse) -> Bool { - if lhs.baseTypeName != rhs.baseTypeName {return false} - if lhs.extensionNumber != rhs.extensionNumber {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1alpha_ListServiceResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ListServiceResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "service"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeRepeatedMessageField(value: &self.service) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.service.isEmpty { - try visitor.visitRepeatedMessageField(value: self.service, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1alpha_ListServiceResponse, rhs: Grpc_Reflection_V1alpha_ListServiceResponse) -> Bool { - if lhs.service != rhs.service {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1alpha_ServiceResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ServiceResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1alpha_ServiceResponse, rhs: Grpc_Reflection_V1alpha_ServiceResponse) -> Bool { - if lhs.name != rhs.name {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Grpc_Reflection_V1alpha_ErrorResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ErrorResponse" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "error_code"), - 2: .standard(proto: "error_message"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularInt32Field(value: &self.errorCode) }() - case 2: try { try decoder.decodeSingularStringField(value: &self.errorMessage) }() - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.errorCode != 0 { - try visitor.visitSingularInt32Field(value: self.errorCode, fieldNumber: 1) - } - if !self.errorMessage.isEmpty { - try visitor.visitSingularStringField(value: self.errorMessage, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Grpc_Reflection_V1alpha_ErrorResponse, rhs: Grpc_Reflection_V1alpha_ErrorResponse) -> Bool { - if lhs.errorCode != rhs.errorCode {return false} - if lhs.errorMessage != rhs.errorMessage {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -}