a.grpc.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // DO NOT EDIT.
  3. // swift-format-ignore-file
  4. //
  5. // Generated by the protocol buffer compiler.
  6. // Source: a.proto
  7. //
  8. import GRPC
  9. import NIO
  10. import SwiftProtobuf
  11. import ModuleB
  12. /// Usage: instantiate `A_ServiceAClient`, then call methods of this protocol to make API calls.
  13. internal protocol A_ServiceAClientProtocol: GRPCClient {
  14. var serviceName: String { get }
  15. var interceptors: A_ServiceAClientInterceptorFactoryProtocol? { get }
  16. func callServiceA(
  17. _ request: A_MessageA,
  18. callOptions: CallOptions?
  19. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>
  20. }
  21. extension A_ServiceAClientProtocol {
  22. internal var serviceName: String {
  23. return "a.ServiceA"
  24. }
  25. /// Unary call to CallServiceA
  26. ///
  27. /// - Parameters:
  28. /// - request: Request to send to CallServiceA.
  29. /// - callOptions: Call options.
  30. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  31. internal func callServiceA(
  32. _ request: A_MessageA,
  33. callOptions: CallOptions? = nil
  34. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
  35. return self.makeUnaryCall(
  36. path: "/a.ServiceA/CallServiceA",
  37. request: request,
  38. callOptions: callOptions ?? self.defaultCallOptions,
  39. interceptors: self.interceptors?.makeCallServiceAInterceptors() ?? []
  40. )
  41. }
  42. }
  43. internal protocol A_ServiceAClientInterceptorFactoryProtocol {
  44. /// - Returns: Interceptors to use when invoking 'callServiceA'.
  45. func makeCallServiceAInterceptors() -> [ClientInterceptor<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>]
  46. }
  47. internal final class A_ServiceAClient: A_ServiceAClientProtocol {
  48. internal let channel: GRPCChannel
  49. internal var defaultCallOptions: CallOptions
  50. internal var interceptors: A_ServiceAClientInterceptorFactoryProtocol?
  51. /// Creates a client for the a.ServiceA service.
  52. ///
  53. /// - Parameters:
  54. /// - channel: `GRPCChannel` to the service host.
  55. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  56. /// - interceptors: A factory providing interceptors for each RPC.
  57. internal init(
  58. channel: GRPCChannel,
  59. defaultCallOptions: CallOptions = CallOptions(),
  60. interceptors: A_ServiceAClientInterceptorFactoryProtocol? = nil
  61. ) {
  62. self.channel = channel
  63. self.defaultCallOptions = defaultCallOptions
  64. self.interceptors = interceptors
  65. }
  66. }
  67. /// To build a server, implement a class that conforms to this protocol.
  68. internal protocol A_ServiceAProvider: CallHandlerProvider {
  69. var interceptors: A_ServiceAServerInterceptorFactoryProtocol? { get }
  70. func callServiceA(request: A_MessageA, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
  71. }
  72. extension A_ServiceAProvider {
  73. internal var serviceName: Substring { return "a.ServiceA" }
  74. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  75. /// Returns nil for methods not handled by this service.
  76. internal func handle(
  77. method name: Substring,
  78. context: CallHandlerContext
  79. ) -> GRPCServerHandlerProtocol? {
  80. switch name {
  81. case "CallServiceA":
  82. return UnaryServerHandler(
  83. context: context,
  84. requestDeserializer: ProtobufDeserializer<A_MessageA>(),
  85. responseSerializer: ProtobufSerializer<SwiftProtobuf.Google_Protobuf_Empty>(),
  86. interceptors: self.interceptors?.makeCallServiceAInterceptors() ?? [],
  87. userFunction: self.callServiceA(request:context:)
  88. )
  89. default:
  90. return nil
  91. }
  92. }
  93. }
  94. internal protocol A_ServiceAServerInterceptorFactoryProtocol {
  95. /// - Returns: Interceptors to use when handling 'callServiceA'.
  96. /// Defaults to calling `self.makeInterceptors()`.
  97. func makeCallServiceAInterceptors() -> [ServerInterceptor<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>]
  98. }