helloworld.grpc.swift 4.5 KB

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