a.grpc.swift 4.3 KB

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