a.grpc.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: a.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 A_ServiceAClient, then call methods of this protocol to make API calls.
  28. internal protocol A_ServiceAClientProtocol {
  29. func callServiceA(_ request: A_MessageA, callOptions: CallOptions?) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>
  30. }
  31. internal final class A_ServiceAClient: GRPCClient, A_ServiceAClientProtocol {
  32. internal let channel: GRPCChannel
  33. internal var defaultCallOptions: CallOptions
  34. /// Creates a client for the a.ServiceA service.
  35. ///
  36. /// - Parameters:
  37. /// - channel: `GRPCChannel` to the service host.
  38. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  39. internal init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
  40. self.channel = channel
  41. self.defaultCallOptions = defaultCallOptions
  42. }
  43. /// Unary call to CallServiceA
  44. ///
  45. /// - Parameters:
  46. /// - request: Request to send to CallServiceA.
  47. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  48. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  49. internal func callServiceA(
  50. _ request: A_MessageA,
  51. callOptions: CallOptions? = nil
  52. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
  53. return self.makeUnaryCall(
  54. path: "/a.ServiceA/CallServiceA",
  55. request: request,
  56. callOptions: callOptions ?? self.defaultCallOptions
  57. )
  58. }
  59. }
  60. /// To build a server, implement a class that conforms to this protocol.
  61. internal protocol A_ServiceAProvider: CallHandlerProvider {
  62. func callServiceA(request: A_MessageA, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
  63. }
  64. extension A_ServiceAProvider {
  65. internal var serviceName: String { return "a.ServiceA" }
  66. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  67. /// Returns nil for methods not handled by this service.
  68. internal func handleMethod(_ methodName: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  69. switch methodName {
  70. case "CallServiceA":
  71. return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in
  72. return { request in
  73. self.callServiceA(request: request, context: context)
  74. }
  75. }
  76. default: return nil
  77. }
  78. }
  79. }
  80. // Provides conformance to `GRPCPayload`
  81. extension A_MessageA: GRPCProtobufPayload {}