helloworld.grpc.swift 3.3 KB

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