b.grpc.swift 4.6 KB

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