helloworld.grpc.swift 11 KB

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