service.grpc.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // DO NOT EDIT.
  3. // swift-format-ignore-file
  4. //
  5. // Generated by the protocol buffer compiler.
  6. // Source: service.proto
  7. //
  8. import GRPC
  9. import NIO
  10. import SwiftProtobuf
  11. /// Usage: instantiate `Codegentest_FooClient`, then call methods of this protocol to make API calls.
  12. internal protocol Codegentest_FooClientProtocol: GRPCClient {
  13. var serviceName: String { get }
  14. var interceptors: Codegentest_FooClientInterceptorFactoryProtocol? { get }
  15. func get(
  16. _ request: Codegentest_FooMessage,
  17. callOptions: CallOptions?
  18. ) -> UnaryCall<Codegentest_FooMessage, Codegentest_FooMessage>
  19. }
  20. extension Codegentest_FooClientProtocol {
  21. internal var serviceName: String {
  22. return "codegentest.Foo"
  23. }
  24. /// Unary call to Get
  25. ///
  26. /// - Parameters:
  27. /// - request: Request to send to Get.
  28. /// - callOptions: Call options.
  29. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  30. internal func get(
  31. _ request: Codegentest_FooMessage,
  32. callOptions: CallOptions? = nil
  33. ) -> UnaryCall<Codegentest_FooMessage, Codegentest_FooMessage> {
  34. return self.makeUnaryCall(
  35. path: "/codegentest.Foo/Get",
  36. request: request,
  37. callOptions: callOptions ?? self.defaultCallOptions,
  38. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  39. )
  40. }
  41. }
  42. internal protocol Codegentest_FooClientInterceptorFactoryProtocol {
  43. /// - Returns: Interceptors to use when invoking 'get'.
  44. func makeGetInterceptors() -> [ClientInterceptor<Codegentest_FooMessage, Codegentest_FooMessage>]
  45. }
  46. internal final class Codegentest_FooClient: Codegentest_FooClientProtocol {
  47. internal let channel: GRPCChannel
  48. internal var defaultCallOptions: CallOptions
  49. internal var interceptors: Codegentest_FooClientInterceptorFactoryProtocol?
  50. /// Creates a client for the codegentest.Foo service.
  51. ///
  52. /// - Parameters:
  53. /// - channel: `GRPCChannel` to the service host.
  54. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  55. /// - interceptors: A factory providing interceptors for each RPC.
  56. internal init(
  57. channel: GRPCChannel,
  58. defaultCallOptions: CallOptions = CallOptions(),
  59. interceptors: Codegentest_FooClientInterceptorFactoryProtocol? = nil
  60. ) {
  61. self.channel = channel
  62. self.defaultCallOptions = defaultCallOptions
  63. self.interceptors = interceptors
  64. }
  65. }
  66. /// To build a server, implement a class that conforms to this protocol.
  67. internal protocol Codegentest_FooProvider: CallHandlerProvider {
  68. var interceptors: Codegentest_FooServerInterceptorFactoryProtocol? { get }
  69. func get(request: Codegentest_FooMessage, context: StatusOnlyCallContext) -> EventLoopFuture<Codegentest_FooMessage>
  70. }
  71. extension Codegentest_FooProvider {
  72. internal var serviceName: Substring { return "codegentest.Foo" }
  73. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  74. /// Returns nil for methods not handled by this service.
  75. internal func handle(
  76. method name: Substring,
  77. context: CallHandlerContext
  78. ) -> GRPCServerHandlerProtocol? {
  79. switch name {
  80. case "Get":
  81. return UnaryServerHandler(
  82. context: context,
  83. requestDeserializer: ProtobufDeserializer<Codegentest_FooMessage>(),
  84. responseSerializer: ProtobufSerializer<Codegentest_FooMessage>(),
  85. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  86. userFunction: self.get(request:context:)
  87. )
  88. default:
  89. return nil
  90. }
  91. }
  92. }
  93. internal protocol Codegentest_FooServerInterceptorFactoryProtocol {
  94. /// - Returns: Interceptors to use when handling 'get'.
  95. /// Defaults to calling `self.makeInterceptors()`.
  96. func makeGetInterceptors() -> [ServerInterceptor<Codegentest_FooMessage, Codegentest_FooMessage>]
  97. }