b.grpc.swift 4.2 KB

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