helloworld.grpc.swift 11 KB

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