a.grpc.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 Foundation
  23. import GRPC
  24. import NIO
  25. import NIOHTTP1
  26. import SwiftProtobuf
  27. import ModuleB
  28. /// Usage: instantiate A_ServiceAClient, then call methods of this protocol to make API calls.
  29. internal protocol A_ServiceAClientProtocol: GRPCClient {
  30. func callServiceA(
  31. _ request: A_MessageA,
  32. callOptions: CallOptions?
  33. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty>
  34. }
  35. extension A_ServiceAClientProtocol {
  36. /// Unary call to CallServiceA
  37. ///
  38. /// - Parameters:
  39. /// - request: Request to send to CallServiceA.
  40. /// - callOptions: Call options.
  41. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  42. internal func callServiceA(
  43. _ request: A_MessageA,
  44. callOptions: CallOptions? = nil
  45. ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
  46. return self.makeUnaryCall(
  47. path: "/a.ServiceA/CallServiceA",
  48. request: request,
  49. callOptions: callOptions ?? self.defaultCallOptions
  50. )
  51. }
  52. }
  53. internal final class A_ServiceAClient: A_ServiceAClientProtocol {
  54. internal let channel: GRPCChannel
  55. internal var defaultCallOptions: CallOptions
  56. /// Creates a client for the a.ServiceA service.
  57. ///
  58. /// - Parameters:
  59. /// - channel: `GRPCChannel` to the service host.
  60. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  61. internal init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
  62. self.channel = channel
  63. self.defaultCallOptions = defaultCallOptions
  64. }
  65. }
  66. /// To build a server, implement a class that conforms to this protocol.
  67. internal protocol A_ServiceAProvider: CallHandlerProvider {
  68. func callServiceA(request: A_MessageA, context: StatusOnlyCallContext) -> EventLoopFuture<SwiftProtobuf.Google_Protobuf_Empty>
  69. }
  70. extension A_ServiceAProvider {
  71. internal var serviceName: Substring { return "a.ServiceA" }
  72. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  73. /// Returns nil for methods not handled by this service.
  74. internal func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  75. switch methodName {
  76. case "CallServiceA":
  77. return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in
  78. return { request in
  79. self.callServiceA(request: request, context: context)
  80. }
  81. }
  82. default: return nil
  83. }
  84. }
  85. }