test.grpc.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: test.proto
  6. //
  7. //
  8. // Copyright 2018, gRPC Authors All rights reserved.
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. //
  22. import Foundation
  23. import GRPC
  24. import NIO
  25. import NIOHTTP1
  26. import SwiftProtobuf
  27. /// Usage: instantiate Codegentest_FooClient, then call methods of this protocol to make API calls.
  28. internal protocol Codegentest_FooClientProtocol {
  29. func bar(_ request: SwiftProtobuf.Google_Protobuf_Empty, callOptions: CallOptions?) -> UnaryCall<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty>
  30. }
  31. internal final class Codegentest_FooClient: GRPCClient, Codegentest_FooClientProtocol {
  32. internal let channel: GRPCChannel
  33. internal var defaultCallOptions: CallOptions
  34. /// Creates a client for the codegentest.Foo service.
  35. ///
  36. /// - Parameters:
  37. /// - channel: `GRPCChannel` to the service host.
  38. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  39. internal init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
  40. self.channel = channel
  41. self.defaultCallOptions = defaultCallOptions
  42. }
  43. /// Unary call to Bar
  44. ///
  45. /// - Parameters:
  46. /// - request: Request to send to Bar.
  47. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  48. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  49. internal func bar(_ request: SwiftProtobuf.Google_Protobuf_Empty, callOptions: CallOptions? = nil) -> UnaryCall<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty> {
  50. return self.makeUnaryCall(path: "/codegentest.Foo/Bar",
  51. request: request,
  52. callOptions: callOptions ?? self.defaultCallOptions)
  53. }
  54. }
  55. /// To build a server, implement a class that conforms to this protocol.
  56. internal protocol Codegentest_FooProvider: CallHandlerProvider {
  57. func bar(request: SwiftProtobuf.Google_Protobuf_Empty, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
  58. }
  59. extension Codegentest_FooProvider {
  60. internal var serviceName: String { return "codegentest.Foo" }
  61. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  62. /// Returns nil for methods not handled by this service.
  63. internal func handleMethod(_ methodName: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  64. switch methodName {
  65. case "Bar":
  66. return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in
  67. return { request in
  68. self.bar(request: request, context: context)
  69. }
  70. }
  71. default: return nil
  72. }
  73. }
  74. }