helloworld.grpc.swift 11 KB

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