helloworld.grpc.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /// Copyright 2015 gRPC authors.
  2. ///
  3. /// Licensed under the Apache License, Version 2.0 (the "License");
  4. /// you may not use this file except in compliance with the License.
  5. /// You may obtain a copy of the License at
  6. ///
  7. /// http://www.apache.org/licenses/LICENSE-2.0
  8. ///
  9. /// Unless required by applicable law or agreed to in writing, software
  10. /// distributed under the License is distributed on an "AS IS" BASIS,
  11. /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. /// See the License for the specific language governing permissions and
  13. /// limitations under the License.
  14. // DO NOT EDIT.
  15. // swift-format-ignore-file
  16. //
  17. // Generated by the gRPC Swift generator plugin for the protocol buffer compiler.
  18. // Source: helloworld.proto
  19. //
  20. // For information on using the generated types, please see the documentation:
  21. // https://github.com/grpc/grpc-swift
  22. import GRPCCore
  23. import GRPCProtobuf
  24. // MARK: - helloworld.Greeter
  25. /// Namespace containing generated types for the "helloworld.Greeter" service.
  26. internal enum Helloworld_Greeter {
  27. /// Service descriptor for the "helloworld.Greeter" service.
  28. internal static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter")
  29. /// Namespace for method metadata.
  30. internal enum Method {
  31. /// Namespace for "SayHello" metadata.
  32. internal enum SayHello {
  33. /// Request type for "SayHello".
  34. internal typealias Input = Helloworld_HelloRequest
  35. /// Response type for "SayHello".
  36. internal typealias Output = Helloworld_HelloReply
  37. /// Descriptor for "SayHello".
  38. internal static let descriptor = GRPCCore.MethodDescriptor(
  39. service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter"),
  40. method: "SayHello"
  41. )
  42. }
  43. /// Descriptors for all methods in the "helloworld.Greeter" service.
  44. internal static let descriptors: [GRPCCore.MethodDescriptor] = [
  45. SayHello.descriptor
  46. ]
  47. }
  48. }
  49. extension GRPCCore.ServiceDescriptor {
  50. /// Service descriptor for the "helloworld.Greeter" service.
  51. internal static let helloworld_Greeter = GRPCCore.ServiceDescriptor(fullyQualifiedService: "helloworld.Greeter")
  52. }
  53. // MARK: helloworld.Greeter (server)
  54. extension Helloworld_Greeter {
  55. /// Streaming variant of the service protocol for the "helloworld.Greeter" service.
  56. ///
  57. /// This protocol is the lowest-level of the service protocols generated for this service
  58. /// giving you the most flexibility over the implementation of your service. This comes at
  59. /// the cost of more verbose and less strict APIs. Each RPC requires you to implement it in
  60. /// terms of a request stream and response stream. Where only a single request or response
  61. /// message is expected, you are responsible for enforcing this invariant is maintained.
  62. ///
  63. /// Where possible, prefer using the stricter, less-verbose ``ServiceProtocol``
  64. /// or ``SimpleServiceProtocol`` instead.
  65. ///
  66. /// > Source IDL Documentation:
  67. /// >
  68. /// > The greeting service definition.
  69. internal protocol StreamingServiceProtocol: GRPCCore.RegistrableRPCService {
  70. /// Handle the "SayHello" method.
  71. ///
  72. /// > Source IDL Documentation:
  73. /// >
  74. /// > Sends a greeting
  75. ///
  76. /// - Parameters:
  77. /// - request: A streaming request of `Helloworld_HelloRequest` messages.
  78. /// - context: Context providing information about the RPC.
  79. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  80. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  81. /// to an internal error.
  82. /// - Returns: A streaming response of `Helloworld_HelloReply` messages.
  83. func sayHello(
  84. request: GRPCCore.StreamingServerRequest<Helloworld_HelloRequest>,
  85. context: GRPCCore.ServerContext
  86. ) async throws -> GRPCCore.StreamingServerResponse<Helloworld_HelloReply>
  87. }
  88. /// Service protocol for the "helloworld.Greeter" service.
  89. ///
  90. /// This protocol is higher level than ``StreamingServiceProtocol`` but lower level than
  91. /// the ``SimpleServiceProtocol``, it provides access to request and response metadata and
  92. /// trailing response metadata. If you don't need these then consider using
  93. /// the ``SimpleServiceProtocol``. If you need fine grained control over your RPCs then
  94. /// use ``StreamingServiceProtocol``.
  95. ///
  96. /// > Source IDL Documentation:
  97. /// >
  98. /// > The greeting service definition.
  99. internal protocol ServiceProtocol: Helloworld_Greeter.StreamingServiceProtocol {
  100. /// Handle the "SayHello" method.
  101. ///
  102. /// > Source IDL Documentation:
  103. /// >
  104. /// > Sends a greeting
  105. ///
  106. /// - Parameters:
  107. /// - request: A request containing a single `Helloworld_HelloRequest` message.
  108. /// - context: Context providing information about the RPC.
  109. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  110. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  111. /// to an internal error.
  112. /// - Returns: A response containing a single `Helloworld_HelloReply` message.
  113. func sayHello(
  114. request: GRPCCore.ServerRequest<Helloworld_HelloRequest>,
  115. context: GRPCCore.ServerContext
  116. ) async throws -> GRPCCore.ServerResponse<Helloworld_HelloReply>
  117. }
  118. /// Simple service protocol for the "helloworld.Greeter" service.
  119. ///
  120. /// This is the highest level protocol for the service. The API is the easiest to use but
  121. /// doesn't provide access to request or response metadata. If you need access to these
  122. /// then use ``ServiceProtocol`` instead.
  123. ///
  124. /// > Source IDL Documentation:
  125. /// >
  126. /// > The greeting service definition.
  127. internal protocol SimpleServiceProtocol: Helloworld_Greeter.ServiceProtocol {
  128. /// Handle the "SayHello" method.
  129. ///
  130. /// > Source IDL Documentation:
  131. /// >
  132. /// > Sends a greeting
  133. ///
  134. /// - Parameters:
  135. /// - request: A `Helloworld_HelloRequest` message.
  136. /// - context: Context providing information about the RPC.
  137. /// - Throws: Any error which occurred during the processing of the request. Thrown errors
  138. /// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
  139. /// to an internal error.
  140. /// - Returns: A `Helloworld_HelloReply` to respond with.
  141. func sayHello(
  142. request: Helloworld_HelloRequest,
  143. context: GRPCCore.ServerContext
  144. ) async throws -> Helloworld_HelloReply
  145. }
  146. }
  147. // Default implementation of 'registerMethods(with:)'.
  148. extension Helloworld_Greeter.StreamingServiceProtocol {
  149. internal func registerMethods(with router: inout GRPCCore.RPCRouter) {
  150. router.registerHandler(
  151. forMethod: Helloworld_Greeter.Method.SayHello.descriptor,
  152. deserializer: GRPCProtobuf.ProtobufDeserializer<Helloworld_HelloRequest>(),
  153. serializer: GRPCProtobuf.ProtobufSerializer<Helloworld_HelloReply>(),
  154. handler: { request, context in
  155. try await self.sayHello(
  156. request: request,
  157. context: context
  158. )
  159. }
  160. )
  161. }
  162. }
  163. // Default implementation of streaming methods from 'StreamingServiceProtocol'.
  164. extension Helloworld_Greeter.ServiceProtocol {
  165. internal func sayHello(
  166. request: GRPCCore.StreamingServerRequest<Helloworld_HelloRequest>,
  167. context: GRPCCore.ServerContext
  168. ) async throws -> GRPCCore.StreamingServerResponse<Helloworld_HelloReply> {
  169. let response = try await self.sayHello(
  170. request: GRPCCore.ServerRequest(stream: request),
  171. context: context
  172. )
  173. return GRPCCore.StreamingServerResponse(single: response)
  174. }
  175. }
  176. // Default implementation of methods from 'ServiceProtocol'.
  177. extension Helloworld_Greeter.SimpleServiceProtocol {
  178. internal func sayHello(
  179. request: GRPCCore.ServerRequest<Helloworld_HelloRequest>,
  180. context: GRPCCore.ServerContext
  181. ) async throws -> GRPCCore.ServerResponse<Helloworld_HelloReply> {
  182. return GRPCCore.ServerResponse<Helloworld_HelloReply>(
  183. message: try await self.sayHello(
  184. request: request.message,
  185. context: context
  186. ),
  187. metadata: [:]
  188. )
  189. }
  190. }
  191. // MARK: helloworld.Greeter (client)
  192. extension Helloworld_Greeter {
  193. /// Generated client protocol for the "helloworld.Greeter" service.
  194. ///
  195. /// You don't need to implement this protocol directly, use the generated
  196. /// implementation, ``Client``.
  197. ///
  198. /// > Source IDL Documentation:
  199. /// >
  200. /// > The greeting service definition.
  201. internal protocol ClientProtocol: Sendable {
  202. /// Call the "SayHello" method.
  203. ///
  204. /// > Source IDL Documentation:
  205. /// >
  206. /// > Sends a greeting
  207. ///
  208. /// - Parameters:
  209. /// - request: A request containing a single `Helloworld_HelloRequest` message.
  210. /// - serializer: A serializer for `Helloworld_HelloRequest` messages.
  211. /// - deserializer: A deserializer for `Helloworld_HelloReply` messages.
  212. /// - options: Options to apply to this RPC.
  213. /// - handleResponse: A closure which handles the response, the result of which is
  214. /// returned to the caller. Returning from the closure will cancel the RPC if it
  215. /// hasn't already finished.
  216. /// - Returns: The result of `handleResponse`.
  217. func sayHello<Result>(
  218. request: GRPCCore.ClientRequest<Helloworld_HelloRequest>,
  219. serializer: some GRPCCore.MessageSerializer<Helloworld_HelloRequest>,
  220. deserializer: some GRPCCore.MessageDeserializer<Helloworld_HelloReply>,
  221. options: GRPCCore.CallOptions,
  222. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Helloworld_HelloReply>) async throws -> Result
  223. ) async throws -> Result where Result: Sendable
  224. }
  225. /// Generated client for the "helloworld.Greeter" service.
  226. ///
  227. /// The ``Client`` provides an implementation of ``ClientProtocol`` which wraps
  228. /// a `GRPCCore.GRPCCClient`. The underlying `GRPCClient` provides the long-lived
  229. /// means of communication with the remote peer.
  230. ///
  231. /// > Source IDL Documentation:
  232. /// >
  233. /// > The greeting service definition.
  234. internal struct Client: ClientProtocol {
  235. private let client: GRPCCore.GRPCClient
  236. /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`.
  237. ///
  238. /// - Parameters:
  239. /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service.
  240. internal init(wrapping client: GRPCCore.GRPCClient) {
  241. self.client = client
  242. }
  243. /// Call the "SayHello" method.
  244. ///
  245. /// > Source IDL Documentation:
  246. /// >
  247. /// > Sends a greeting
  248. ///
  249. /// - Parameters:
  250. /// - request: A request containing a single `Helloworld_HelloRequest` message.
  251. /// - serializer: A serializer for `Helloworld_HelloRequest` messages.
  252. /// - deserializer: A deserializer for `Helloworld_HelloReply` messages.
  253. /// - options: Options to apply to this RPC.
  254. /// - handleResponse: A closure which handles the response, the result of which is
  255. /// returned to the caller. Returning from the closure will cancel the RPC if it
  256. /// hasn't already finished.
  257. /// - Returns: The result of `handleResponse`.
  258. internal func sayHello<Result>(
  259. request: GRPCCore.ClientRequest<Helloworld_HelloRequest>,
  260. serializer: some GRPCCore.MessageSerializer<Helloworld_HelloRequest>,
  261. deserializer: some GRPCCore.MessageDeserializer<Helloworld_HelloReply>,
  262. options: GRPCCore.CallOptions = .defaults,
  263. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Helloworld_HelloReply>) async throws -> Result = { response in
  264. try response.message
  265. }
  266. ) async throws -> Result where Result: Sendable {
  267. try await self.client.unary(
  268. request: request,
  269. descriptor: Helloworld_Greeter.Method.SayHello.descriptor,
  270. serializer: serializer,
  271. deserializer: deserializer,
  272. options: options,
  273. onResponse: handleResponse
  274. )
  275. }
  276. }
  277. }
  278. // Helpers providing default arguments to 'ClientProtocol' methods.
  279. extension Helloworld_Greeter.ClientProtocol {
  280. /// Call the "SayHello" method.
  281. ///
  282. /// > Source IDL Documentation:
  283. /// >
  284. /// > Sends a greeting
  285. ///
  286. /// - Parameters:
  287. /// - request: A request containing a single `Helloworld_HelloRequest` message.
  288. /// - options: Options to apply to this RPC.
  289. /// - handleResponse: A closure which handles the response, the result of which is
  290. /// returned to the caller. Returning from the closure will cancel the RPC if it
  291. /// hasn't already finished.
  292. /// - Returns: The result of `handleResponse`.
  293. internal func sayHello<Result>(
  294. request: GRPCCore.ClientRequest<Helloworld_HelloRequest>,
  295. options: GRPCCore.CallOptions = .defaults,
  296. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Helloworld_HelloReply>) async throws -> Result = { response in
  297. try response.message
  298. }
  299. ) async throws -> Result where Result: Sendable {
  300. try await self.sayHello(
  301. request: request,
  302. serializer: GRPCProtobuf.ProtobufSerializer<Helloworld_HelloRequest>(),
  303. deserializer: GRPCProtobuf.ProtobufDeserializer<Helloworld_HelloReply>(),
  304. options: options,
  305. onResponse: handleResponse
  306. )
  307. }
  308. }
  309. // Helpers providing sugared APIs for 'ClientProtocol' methods.
  310. extension Helloworld_Greeter.ClientProtocol {
  311. /// Call the "SayHello" method.
  312. ///
  313. /// > Source IDL Documentation:
  314. /// >
  315. /// > Sends a greeting
  316. ///
  317. /// - Parameters:
  318. /// - message: request message to send.
  319. /// - metadata: Additional metadata to send, defaults to empty.
  320. /// - options: Options to apply to this RPC, defaults to `.defaults`.
  321. /// - handleResponse: A closure which handles the response, the result of which is
  322. /// returned to the caller. Returning from the closure will cancel the RPC if it
  323. /// hasn't already finished.
  324. /// - Returns: The result of `handleResponse`.
  325. internal func sayHello<Result>(
  326. _ message: Helloworld_HelloRequest,
  327. metadata: GRPCCore.Metadata = [:],
  328. options: GRPCCore.CallOptions = .defaults,
  329. onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Helloworld_HelloReply>) async throws -> Result = { response in
  330. try response.message
  331. }
  332. ) async throws -> Result where Result: Sendable {
  333. let request = GRPCCore.ClientRequest<Helloworld_HelloRequest>(
  334. message: message,
  335. metadata: metadata
  336. )
  337. return try await self.sayHello(
  338. request: request,
  339. options: options,
  340. onResponse: handleResponse
  341. )
  342. }
  343. }