a.grpc.swift 3.2 KB

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