test.grpc.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // DO NOT EDIT.
  3. // swift-format-ignore-file
  4. //
  5. // Generated by the protocol buffer compiler.
  6. // Source: test.proto
  7. //
  8. //
  9. // Copyright 2018, gRPC Authors All rights reserved.
  10. //
  11. // Licensed under the Apache License, Version 2.0 (the "License");
  12. // you may not use this file except in compliance with the License.
  13. // You may obtain a copy of the License at
  14. //
  15. // http://www.apache.org/licenses/LICENSE-2.0
  16. //
  17. // Unless required by applicable law or agreed to in writing, software
  18. // distributed under the License is distributed on an "AS IS" BASIS,
  19. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. // See the License for the specific language governing permissions and
  21. // limitations under the License.
  22. //
  23. import GRPC
  24. import NIO
  25. import SwiftProtobuf
  26. /// Usage: instantiate `Codegentest_FooClient`, then call methods of this protocol to make API calls.
  27. internal protocol Codegentest_FooClientProtocol: GRPCClient {
  28. var serviceName: String { get }
  29. var interceptors: Codegentest_FooClientInterceptorFactoryProtocol? { get }
  30. func bar(
  31. _ request: SwiftProtobuf.Google_Protobuf_Empty,
  32. callOptions: CallOptions?
  33. ) -> UnaryCall<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty>
  34. }
  35. extension Codegentest_FooClientProtocol {
  36. internal var serviceName: String {
  37. return "codegentest.Foo"
  38. }
  39. /// Unary call to Bar
  40. ///
  41. /// - Parameters:
  42. /// - request: Request to send to Bar.
  43. /// - callOptions: Call options.
  44. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  45. internal func bar(
  46. _ request: SwiftProtobuf.Google_Protobuf_Empty,
  47. callOptions: CallOptions? = nil
  48. ) -> UnaryCall<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty> {
  49. return self.makeUnaryCall(
  50. path: "/codegentest.Foo/Bar",
  51. request: request,
  52. callOptions: callOptions ?? self.defaultCallOptions,
  53. interceptors: self.interceptors?.makeBarInterceptors() ?? []
  54. )
  55. }
  56. }
  57. internal protocol Codegentest_FooClientInterceptorFactoryProtocol {
  58. /// - Returns: Interceptors to use when invoking 'bar'.
  59. func makeBarInterceptors() -> [ClientInterceptor<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty>]
  60. }
  61. internal final class Codegentest_FooClient: Codegentest_FooClientProtocol {
  62. internal let channel: GRPCChannel
  63. internal var defaultCallOptions: CallOptions
  64. internal var interceptors: Codegentest_FooClientInterceptorFactoryProtocol?
  65. /// Creates a client for the codegentest.Foo service.
  66. ///
  67. /// - Parameters:
  68. /// - channel: `GRPCChannel` to the service host.
  69. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  70. /// - interceptors: A factory providing interceptors for each RPC.
  71. internal init(
  72. channel: GRPCChannel,
  73. defaultCallOptions: CallOptions = CallOptions(),
  74. interceptors: Codegentest_FooClientInterceptorFactoryProtocol? = nil
  75. ) {
  76. self.channel = channel
  77. self.defaultCallOptions = defaultCallOptions
  78. self.interceptors = interceptors
  79. }
  80. }
  81. /// To build a server, implement a class that conforms to this protocol.
  82. internal protocol Codegentest_FooProvider: CallHandlerProvider {
  83. var interceptors: Codegentest_FooServerInterceptorFactoryProtocol? { get }
  84. func bar(request: SwiftProtobuf.Google_Protobuf_Empty, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
  85. }
  86. extension Codegentest_FooProvider {
  87. internal var serviceName: Substring { return "codegentest.Foo" }
  88. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  89. /// Returns nil for methods not handled by this service.
  90. internal func handle(
  91. method name: Substring,
  92. context: CallHandlerContext
  93. ) -> GRPCServerHandlerProtocol? {
  94. switch name {
  95. case "Bar":
  96. return UnaryServerHandler(
  97. context: context,
  98. requestDeserializer: ProtobufDeserializer<SwiftProtobuf.Google_Protobuf_Empty>(),
  99. responseSerializer: ProtobufSerializer<SwiftProtobuf.Google_Protobuf_Empty>(),
  100. interceptors: self.interceptors?.makeBarInterceptors() ?? [],
  101. userFunction: self.bar(request:context:)
  102. )
  103. default:
  104. return nil
  105. }
  106. }
  107. }
  108. internal protocol Codegentest_FooServerInterceptorFactoryProtocol {
  109. /// - Returns: Interceptors to use when handling 'bar'.
  110. /// Defaults to calling `self.makeInterceptors()`.
  111. func makeBarInterceptors() -> [ServerInterceptor<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty>]
  112. }