a.grpc.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // DO NOT EDIT.
  3. // swift-format-ignore-file
  4. //
  5. // Generated by the protocol buffer compiler.
  6. // Source: a.proto
  7. //
  8. //
  9. // Copyright 2018, gRPC Authors All rights reserved.
  10. //
  11. // Licensed under the Apache License, Version 2.0 (the "License");
  12. // you may not use this file except in compliance with the License.
  13. // You may obtain a copy of the License at
  14. //
  15. // http://www.apache.org/licenses/LICENSE-2.0
  16. //
  17. // Unless required by applicable law or agreed to in writing, software
  18. // distributed under the License is distributed on an "AS IS" BASIS,
  19. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. // See the License for the specific language governing permissions and
  21. // limitations under the License.
  22. //
  23. import GRPC
  24. import NIO
  25. import SwiftProtobuf
  26. import ModuleB
  27. /// Usage: instantiate `A_ServiceAClient`, then call methods of this protocol to make API calls.
  28. internal protocol A_ServiceAClientProtocol: GRPCClient {
  29. var serviceName: String { get }
  30. var interceptors: A_ServiceAClientInterceptorFactoryProtocol? { get }
  31. func callServiceA(
  32. _ request: A_MessageA,
  33. callOptions: CallOptions?
  34. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>
  35. }
  36. extension A_ServiceAClientProtocol {
  37. internal var serviceName: String {
  38. return "a.ServiceA"
  39. }
  40. /// Unary call to CallServiceA
  41. ///
  42. /// - Parameters:
  43. /// - request: Request to send to CallServiceA.
  44. /// - callOptions: Call options.
  45. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  46. internal func callServiceA(
  47. _ request: A_MessageA,
  48. callOptions: CallOptions? = nil
  49. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
  50. return self.makeUnaryCall(
  51. path: "/a.ServiceA/CallServiceA",
  52. request: request,
  53. callOptions: callOptions ?? self.defaultCallOptions,
  54. interceptors: self.interceptors?.makeCallServiceAInterceptors() ?? []
  55. )
  56. }
  57. }
  58. internal protocol A_ServiceAClientInterceptorFactoryProtocol {
  59. /// - Returns: Interceptors to use when invoking 'callServiceA'.
  60. func makeCallServiceAInterceptors() -> [ClientInterceptor<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>]
  61. }
  62. internal final class A_ServiceAClient: A_ServiceAClientProtocol {
  63. internal let channel: GRPCChannel
  64. internal var defaultCallOptions: CallOptions
  65. internal var interceptors: A_ServiceAClientInterceptorFactoryProtocol?
  66. /// Creates a client for the a.ServiceA service.
  67. ///
  68. /// - Parameters:
  69. /// - channel: `GRPCChannel` to the service host.
  70. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  71. /// - interceptors: A factory providing interceptors for each RPC.
  72. internal init(
  73. channel: GRPCChannel,
  74. defaultCallOptions: CallOptions = CallOptions(),
  75. interceptors: A_ServiceAClientInterceptorFactoryProtocol? = nil
  76. ) {
  77. self.channel = channel
  78. self.defaultCallOptions = defaultCallOptions
  79. self.interceptors = interceptors
  80. }
  81. }
  82. /// To build a server, implement a class that conforms to this protocol.
  83. internal protocol A_ServiceAProvider: CallHandlerProvider {
  84. var interceptors: A_ServiceAServerInterceptorFactoryProtocol? { get }
  85. func callServiceA(request: A_MessageA, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
  86. }
  87. extension A_ServiceAProvider {
  88. internal var serviceName: Substring { return "a.ServiceA" }
  89. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  90. /// Returns nil for methods not handled by this service.
  91. internal func handle(
  92. method name: Substring,
  93. context: CallHandlerContext
  94. ) -> GRPCServerHandlerProtocol? {
  95. switch name {
  96. case "CallServiceA":
  97. return UnaryServerHandler(
  98. context: context,
  99. requestDeserializer: ProtobufDeserializer<A_MessageA>(),
  100. responseSerializer: ProtobufSerializer<SwiftProtobuf.Google_Protobuf_Empty>(),
  101. interceptors: self.interceptors?.makeCallServiceAInterceptors() ?? [],
  102. userFunction: self.callServiceA(request:context:)
  103. )
  104. default:
  105. return nil
  106. }
  107. }
  108. }
  109. internal protocol A_ServiceAServerInterceptorFactoryProtocol {
  110. /// - Returns: Interceptors to use when handling 'callServiceA'.
  111. /// Defaults to calling `self.makeInterceptors()`.
  112. func makeCallServiceAInterceptors() -> [ServerInterceptor<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>]
  113. }