helloworld.grpc.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: helloworld.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 GRPC
  23. import NIO
  24. import SwiftProtobuf
  25. /// Usage: instantiate Helloworld_GreeterClient, then call methods of this protocol to make API calls.
  26. public protocol Helloworld_GreeterClientProtocol: GRPCClient {
  27. var interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol? { get }
  28. func sayHello(
  29. _ request: Helloworld_HelloRequest,
  30. callOptions: CallOptions?
  31. ) -> UnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply>
  32. }
  33. extension Helloworld_GreeterClientProtocol {
  34. /// Sends a greeting.
  35. ///
  36. /// - Parameters:
  37. /// - request: Request to send to SayHello.
  38. /// - callOptions: Call options.
  39. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  40. public func sayHello(
  41. _ request: Helloworld_HelloRequest,
  42. callOptions: CallOptions? = nil
  43. ) -> UnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply> {
  44. return self.makeUnaryCall(
  45. path: "/helloworld.Greeter/SayHello",
  46. request: request,
  47. callOptions: callOptions ?? self.defaultCallOptions,
  48. interceptors: self.interceptors?.makeSayHelloInterceptors() ?? []
  49. )
  50. }
  51. }
  52. public protocol Helloworld_GreeterClientInterceptorFactoryProtocol {
  53. /// - Returns: Interceptors to use when invoking 'sayHello'.
  54. func makeSayHelloInterceptors() -> [ClientInterceptor<Helloworld_HelloRequest, Helloworld_HelloReply>]
  55. }
  56. public final class Helloworld_GreeterClient: Helloworld_GreeterClientProtocol {
  57. public let channel: GRPCChannel
  58. public var defaultCallOptions: CallOptions
  59. public var interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol?
  60. /// Creates a client for the helloworld.Greeter service.
  61. ///
  62. /// - Parameters:
  63. /// - channel: `GRPCChannel` to the service host.
  64. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  65. /// - interceptors: A factory providing interceptors for each RPC.
  66. public init(
  67. channel: GRPCChannel,
  68. defaultCallOptions: CallOptions = CallOptions(),
  69. interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol? = nil
  70. ) {
  71. self.channel = channel
  72. self.defaultCallOptions = defaultCallOptions
  73. self.interceptors = interceptors
  74. }
  75. }
  76. /// To build a server, implement a class that conforms to this protocol.
  77. public protocol Helloworld_GreeterProvider: CallHandlerProvider {
  78. var interceptors: Helloworld_GreeterServerInterceptorFactoryProtocol? { get }
  79. /// Sends a greeting.
  80. func sayHello(request: Helloworld_HelloRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Helloworld_HelloReply>
  81. }
  82. extension Helloworld_GreeterProvider {
  83. public var serviceName: Substring { return "helloworld.Greeter" }
  84. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  85. /// Returns nil for methods not handled by this service.
  86. public func handleMethod(
  87. _ methodName: Substring,
  88. callHandlerContext: CallHandlerContext
  89. ) -> GRPCCallHandler? {
  90. switch methodName {
  91. case "SayHello":
  92. return CallHandlerFactory.makeUnary(
  93. callHandlerContext: callHandlerContext,
  94. interceptors: self.interceptors?.makeSayHelloInterceptors() ?? []
  95. ) { context in
  96. return { request in
  97. self.sayHello(request: request, context: context)
  98. }
  99. }
  100. default:
  101. return nil
  102. }
  103. }
  104. }
  105. public protocol Helloworld_GreeterServerInterceptorFactoryProtocol {
  106. /// - Returns: Interceptors to use when handling 'sayHello'.
  107. /// Defaults to calling `self.makeInterceptors()`.
  108. func makeSayHelloInterceptors() -> [ServerInterceptor<Helloworld_HelloRequest, Helloworld_HelloReply>]
  109. }