helloworld.grpc.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. func sayHello(
  28. _ request: Helloworld_HelloRequest,
  29. callOptions: CallOptions?
  30. ) -> UnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply>
  31. }
  32. extension Helloworld_GreeterClientProtocol {
  33. /// Sends a greeting.
  34. ///
  35. /// - Parameters:
  36. /// - request: Request to send to SayHello.
  37. /// - callOptions: Call options.
  38. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  39. public func sayHello(
  40. _ request: Helloworld_HelloRequest,
  41. callOptions: CallOptions? = nil
  42. ) -> UnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply> {
  43. return self.makeUnaryCall(
  44. path: "/helloworld.Greeter/SayHello",
  45. request: request,
  46. callOptions: callOptions ?? self.defaultCallOptions
  47. )
  48. }
  49. }
  50. public final class Helloworld_GreeterClient: Helloworld_GreeterClientProtocol {
  51. public let channel: GRPCChannel
  52. public var defaultCallOptions: CallOptions
  53. /// Creates a client for the helloworld.Greeter service.
  54. ///
  55. /// - Parameters:
  56. /// - channel: `GRPCChannel` to the service host.
  57. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  58. public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
  59. self.channel = channel
  60. self.defaultCallOptions = defaultCallOptions
  61. }
  62. }
  63. /// To build a server, implement a class that conforms to this protocol.
  64. public protocol Helloworld_GreeterProvider: CallHandlerProvider {
  65. /// Sends a greeting.
  66. func sayHello(request: Helloworld_HelloRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Helloworld_HelloReply>
  67. }
  68. extension Helloworld_GreeterProvider {
  69. public var serviceName: Substring { return "helloworld.Greeter" }
  70. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  71. /// Returns nil for methods not handled by this service.
  72. public func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  73. switch methodName {
  74. case "SayHello":
  75. return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in
  76. return { request in
  77. self.sayHello(request: request, context: context)
  78. }
  79. }
  80. default: return nil
  81. }
  82. }
  83. }