a.grpc.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /// Makes an array of generic interceptors. The per-method interceptor
  55. /// factories default to calling this function and it therefore provides a
  56. /// convenient way of setting interceptors for all methods on a client.
  57. /// - Returns: An array of interceptors generic over `Request` and `Response`.
  58. /// Defaults to an empty array.
  59. func makeInterceptors<Request: SwiftProtobuf.Message, Response: SwiftProtobuf.Message>() -> [ClientInterceptor<Request, Response>]
  60. /// - Returns: Interceptors to use when invoking 'callServiceA'.
  61. /// Defaults to calling `self.makeInterceptors()`.
  62. func makeCallServiceAInterceptors() -> [ClientInterceptor<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>]
  63. }
  64. extension A_ServiceAClientInterceptorFactoryProtocol {
  65. internal func makeInterceptors<Request: SwiftProtobuf.Message, Response: SwiftProtobuf.Message>() -> [ClientInterceptor<Request, Response>] {
  66. return []
  67. }
  68. internal func makeCallServiceAInterceptors() -> [ClientInterceptor<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>] {
  69. return self.makeInterceptors()
  70. }
  71. }
  72. internal final class A_ServiceAClient: A_ServiceAClientProtocol {
  73. internal let channel: GRPCChannel
  74. internal var defaultCallOptions: CallOptions
  75. internal var interceptors: A_ServiceAClientInterceptorFactoryProtocol?
  76. /// Creates a client for the a.ServiceA service.
  77. ///
  78. /// - Parameters:
  79. /// - channel: `GRPCChannel` to the service host.
  80. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  81. /// - interceptors: A factory providing interceptors for each RPC.
  82. internal init(
  83. channel: GRPCChannel,
  84. defaultCallOptions: CallOptions = CallOptions(),
  85. interceptors: A_ServiceAClientInterceptorFactoryProtocol? = nil
  86. ) {
  87. self.channel = channel
  88. self.defaultCallOptions = defaultCallOptions
  89. self.interceptors = interceptors
  90. }
  91. }
  92. /// To build a server, implement a class that conforms to this protocol.
  93. internal protocol A_ServiceAProvider: CallHandlerProvider {
  94. func callServiceA(request: A_MessageA, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
  95. }
  96. extension A_ServiceAProvider {
  97. internal var serviceName: Substring { return "a.ServiceA" }
  98. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  99. /// Returns nil for methods not handled by this service.
  100. internal func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  101. switch methodName {
  102. case "CallServiceA":
  103. return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in
  104. return { request in
  105. self.callServiceA(request: request, context: context)
  106. }
  107. }
  108. default: return nil
  109. }
  110. }
  111. }