helloworld.grpc.swift 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: helloworld.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. /// The greeting service definition.
  26. ///
  27. /// Usage: instantiate `Helloworld_GreeterClient`, then call methods of this protocol to make API calls.
  28. public protocol Helloworld_GreeterClientProtocol: GRPCClient {
  29. var serviceName: String { get }
  30. var interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol? { get }
  31. func sayHello(
  32. _ request: Helloworld_HelloRequest,
  33. callOptions: CallOptions?
  34. ) -> UnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply>
  35. }
  36. extension Helloworld_GreeterClientProtocol {
  37. public var serviceName: String {
  38. return "helloworld.Greeter"
  39. }
  40. /// Sends a greeting.
  41. ///
  42. /// - Parameters:
  43. /// - request: Request to send to SayHello.
  44. /// - callOptions: Call options.
  45. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  46. public func sayHello(
  47. _ request: Helloworld_HelloRequest,
  48. callOptions: CallOptions? = nil
  49. ) -> UnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply> {
  50. return self.makeUnaryCall(
  51. path: Helloworld_GreeterClientMetadata.Methods.sayHello.path,
  52. request: request,
  53. callOptions: callOptions ?? self.defaultCallOptions,
  54. interceptors: self.interceptors?.makeSayHelloInterceptors() ?? []
  55. )
  56. }
  57. }
  58. public final class Helloworld_GreeterClient: Helloworld_GreeterClientProtocol {
  59. public let channel: GRPCChannel
  60. public var defaultCallOptions: CallOptions
  61. public var interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol?
  62. /// Creates a client for the helloworld.Greeter service.
  63. ///
  64. /// - Parameters:
  65. /// - channel: `GRPCChannel` to the service host.
  66. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  67. /// - interceptors: A factory providing interceptors for each RPC.
  68. public init(
  69. channel: GRPCChannel,
  70. defaultCallOptions: CallOptions = CallOptions(),
  71. interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol? = nil
  72. ) {
  73. self.channel = channel
  74. self.defaultCallOptions = defaultCallOptions
  75. self.interceptors = interceptors
  76. }
  77. }
  78. #if compiler(>=5.6)
  79. /// The greeting service definition.
  80. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  81. public protocol Helloworld_GreeterAsyncClientProtocol: GRPCClient {
  82. static var serviceDescriptor: GRPCServiceDescriptor { get }
  83. var interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol? { get }
  84. func makeSayHelloCall(
  85. _ request: Helloworld_HelloRequest,
  86. callOptions: CallOptions?
  87. ) -> GRPCAsyncUnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply>
  88. }
  89. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  90. extension Helloworld_GreeterAsyncClientProtocol {
  91. public static var serviceDescriptor: GRPCServiceDescriptor {
  92. return Helloworld_GreeterClientMetadata.serviceDescriptor
  93. }
  94. public var interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol? {
  95. return nil
  96. }
  97. public func makeSayHelloCall(
  98. _ request: Helloworld_HelloRequest,
  99. callOptions: CallOptions? = nil
  100. ) -> GRPCAsyncUnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply> {
  101. return self.makeAsyncUnaryCall(
  102. path: Helloworld_GreeterClientMetadata.Methods.sayHello.path,
  103. request: request,
  104. callOptions: callOptions ?? self.defaultCallOptions,
  105. interceptors: self.interceptors?.makeSayHelloInterceptors() ?? []
  106. )
  107. }
  108. }
  109. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  110. extension Helloworld_GreeterAsyncClientProtocol {
  111. public func sayHello(
  112. _ request: Helloworld_HelloRequest,
  113. callOptions: CallOptions? = nil
  114. ) async throws -> Helloworld_HelloReply {
  115. return try await self.performAsyncUnaryCall(
  116. path: Helloworld_GreeterClientMetadata.Methods.sayHello.path,
  117. request: request,
  118. callOptions: callOptions ?? self.defaultCallOptions,
  119. interceptors: self.interceptors?.makeSayHelloInterceptors() ?? []
  120. )
  121. }
  122. }
  123. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  124. public struct Helloworld_GreeterAsyncClient: Helloworld_GreeterAsyncClientProtocol {
  125. public var channel: GRPCChannel
  126. public var defaultCallOptions: CallOptions
  127. public var interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol?
  128. public init(
  129. channel: GRPCChannel,
  130. defaultCallOptions: CallOptions = CallOptions(),
  131. interceptors: Helloworld_GreeterClientInterceptorFactoryProtocol? = nil
  132. ) {
  133. self.channel = channel
  134. self.defaultCallOptions = defaultCallOptions
  135. self.interceptors = interceptors
  136. }
  137. }
  138. #endif // compiler(>=5.6)
  139. public protocol Helloworld_GreeterClientInterceptorFactoryProtocol {
  140. /// - Returns: Interceptors to use when invoking 'sayHello'.
  141. func makeSayHelloInterceptors() -> [ClientInterceptor<Helloworld_HelloRequest, Helloworld_HelloReply>]
  142. }
  143. public enum Helloworld_GreeterClientMetadata {
  144. public static let serviceDescriptor = GRPCServiceDescriptor(
  145. name: "Greeter",
  146. fullName: "helloworld.Greeter",
  147. methods: [
  148. Helloworld_GreeterClientMetadata.Methods.sayHello,
  149. ]
  150. )
  151. public enum Methods {
  152. public static let sayHello = GRPCMethodDescriptor(
  153. name: "SayHello",
  154. path: "/helloworld.Greeter/SayHello",
  155. type: GRPCCallType.unary
  156. )
  157. }
  158. }
  159. /// The greeting service definition.
  160. ///
  161. /// To build a server, implement a class that conforms to this protocol.
  162. public protocol Helloworld_GreeterProvider: CallHandlerProvider {
  163. var interceptors: Helloworld_GreeterServerInterceptorFactoryProtocol? { get }
  164. /// Sends a greeting.
  165. func sayHello(request: Helloworld_HelloRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Helloworld_HelloReply>
  166. }
  167. extension Helloworld_GreeterProvider {
  168. public var serviceName: Substring {
  169. return Helloworld_GreeterServerMetadata.serviceDescriptor.fullName[...]
  170. }
  171. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  172. /// Returns nil for methods not handled by this service.
  173. public func handle(
  174. method name: Substring,
  175. context: CallHandlerContext
  176. ) -> GRPCServerHandlerProtocol? {
  177. switch name {
  178. case "SayHello":
  179. return UnaryServerHandler(
  180. context: context,
  181. requestDeserializer: ProtobufDeserializer<Helloworld_HelloRequest>(),
  182. responseSerializer: ProtobufSerializer<Helloworld_HelloReply>(),
  183. interceptors: self.interceptors?.makeSayHelloInterceptors() ?? [],
  184. userFunction: self.sayHello(request:context:)
  185. )
  186. default:
  187. return nil
  188. }
  189. }
  190. }
  191. #if compiler(>=5.6)
  192. /// The greeting service definition.
  193. ///
  194. /// To implement a server, implement an object which conforms to this protocol.
  195. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  196. public protocol Helloworld_GreeterAsyncProvider: CallHandlerProvider {
  197. static var serviceDescriptor: GRPCServiceDescriptor { get }
  198. var interceptors: Helloworld_GreeterServerInterceptorFactoryProtocol? { get }
  199. /// Sends a greeting.
  200. @Sendable func sayHello(
  201. request: Helloworld_HelloRequest,
  202. context: GRPCAsyncServerCallContext
  203. ) async throws -> Helloworld_HelloReply
  204. }
  205. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  206. extension Helloworld_GreeterAsyncProvider {
  207. public static var serviceDescriptor: GRPCServiceDescriptor {
  208. return Helloworld_GreeterServerMetadata.serviceDescriptor
  209. }
  210. public var serviceName: Substring {
  211. return Helloworld_GreeterServerMetadata.serviceDescriptor.fullName[...]
  212. }
  213. public var interceptors: Helloworld_GreeterServerInterceptorFactoryProtocol? {
  214. return nil
  215. }
  216. public func handle(
  217. method name: Substring,
  218. context: CallHandlerContext
  219. ) -> GRPCServerHandlerProtocol? {
  220. switch name {
  221. case "SayHello":
  222. return GRPCAsyncServerHandler(
  223. context: context,
  224. requestDeserializer: ProtobufDeserializer<Helloworld_HelloRequest>(),
  225. responseSerializer: ProtobufSerializer<Helloworld_HelloReply>(),
  226. interceptors: self.interceptors?.makeSayHelloInterceptors() ?? [],
  227. wrapping: self.sayHello(request:context:)
  228. )
  229. default:
  230. return nil
  231. }
  232. }
  233. }
  234. #endif // compiler(>=5.6)
  235. public protocol Helloworld_GreeterServerInterceptorFactoryProtocol {
  236. /// - Returns: Interceptors to use when handling 'sayHello'.
  237. /// Defaults to calling `self.makeInterceptors()`.
  238. func makeSayHelloInterceptors() -> [ServerInterceptor<Helloworld_HelloRequest, Helloworld_HelloReply>]
  239. }
  240. public enum Helloworld_GreeterServerMetadata {
  241. public static let serviceDescriptor = GRPCServiceDescriptor(
  242. name: "Greeter",
  243. fullName: "helloworld.Greeter",
  244. methods: [
  245. Helloworld_GreeterServerMetadata.Methods.sayHello,
  246. ]
  247. )
  248. public enum Methods {
  249. public static let sayHello = GRPCMethodDescriptor(
  250. name: "SayHello",
  251. path: "/helloworld.Greeter/SayHello",
  252. type: GRPCCallType.unary
  253. )
  254. }
  255. }