a.grpc.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 GRPC
  23. import NIO
  24. import SwiftProtobuf
  25. import ModuleB
  26. /// Usage: instantiate A_ServiceAClient, then call methods of this protocol to make API calls.
  27. internal protocol A_ServiceAClientProtocol: GRPCClient {
  28. var interceptors: A_ServiceAClientInterceptorFactoryProtocol? { get }
  29. func callServiceA(
  30. _ request: A_MessageA,
  31. callOptions: CallOptions?
  32. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>
  33. }
  34. extension A_ServiceAClientProtocol {
  35. /// Unary call to CallServiceA
  36. ///
  37. /// - Parameters:
  38. /// - request: Request to send to CallServiceA.
  39. /// - callOptions: Call options.
  40. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  41. internal func callServiceA(
  42. _ request: A_MessageA,
  43. callOptions: CallOptions? = nil
  44. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
  45. return self.makeUnaryCall(
  46. path: "/a.ServiceA/CallServiceA",
  47. request: request,
  48. callOptions: callOptions ?? self.defaultCallOptions,
  49. interceptors: self.interceptors?.makeCallServiceAInterceptors() ?? []
  50. )
  51. }
  52. }
  53. internal protocol A_ServiceAClientInterceptorFactoryProtocol {
  54. /// - Returns: Interceptors to use when invoking 'callServiceA'.
  55. func makeCallServiceAInterceptors() -> [ClientInterceptor<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>]
  56. }
  57. internal final class A_ServiceAClient: A_ServiceAClientProtocol {
  58. internal let channel: GRPCChannel
  59. internal var defaultCallOptions: CallOptions
  60. internal var interceptors: A_ServiceAClientInterceptorFactoryProtocol?
  61. /// Creates a client for the a.ServiceA service.
  62. ///
  63. /// - Parameters:
  64. /// - channel: `GRPCChannel` to the service host.
  65. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  66. /// - interceptors: A factory providing interceptors for each RPC.
  67. internal init(
  68. channel: GRPCChannel,
  69. defaultCallOptions: CallOptions = CallOptions(),
  70. interceptors: A_ServiceAClientInterceptorFactoryProtocol? = nil
  71. ) {
  72. self.channel = channel
  73. self.defaultCallOptions = defaultCallOptions
  74. self.interceptors = interceptors
  75. }
  76. }
  77. /// To build a server, implement a class that conforms to this protocol.
  78. internal protocol A_ServiceAProvider: CallHandlerProvider {
  79. var interceptors: A_ServiceAServerInterceptorFactoryProtocol? { get }
  80. func callServiceA(request: A_MessageA, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
  81. }
  82. extension A_ServiceAProvider {
  83. internal var serviceName: Substring { return "a.ServiceA" }
  84. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  85. /// Returns nil for methods not handled by this service.
  86. internal func handleMethod(
  87. _ methodName: Substring,
  88. callHandlerContext: CallHandlerContext
  89. ) -> GRPCCallHandler? {
  90. switch methodName {
  91. case "CallServiceA":
  92. return CallHandlerFactory.makeUnary(
  93. callHandlerContext: callHandlerContext,
  94. interceptors: self.interceptors?.makeCallServiceAInterceptors() ?? []
  95. ) { context in
  96. return { request in
  97. self.callServiceA(request: request, context: context)
  98. }
  99. }
  100. default:
  101. return nil
  102. }
  103. }
  104. }
  105. internal protocol A_ServiceAServerInterceptorFactoryProtocol {
  106. /// - Returns: Interceptors to use when handling 'callServiceA'.
  107. /// Defaults to calling `self.makeInterceptors()`.
  108. func makeCallServiceAInterceptors() -> [ServerInterceptor<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>]
  109. }