b.grpc.swift 4.3 KB

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