helloworld.grpc.swift 3.1 KB

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