helloworld.grpc.swift 3.5 KB

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