echo.grpc.swift 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: echo.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 Dispatch
  23. import Foundation
  24. import SwiftGRPC
  25. import SwiftProtobuf
  26. internal protocol Echo_EchoGetCall: ClientCallUnary {}
  27. fileprivate final class Echo_EchoGetCallBase: ClientCallUnaryBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetCall {
  28. override class var method: String { return "/echo.Echo/Get" }
  29. }
  30. internal protocol Echo_EchoExpandCall: ClientCallServerStreaming {
  31. /// Do not call this directly, call `receive()` in the protocol extension below instead.
  32. func _receive(timeout: DispatchTime) throws -> Echo_EchoResponse?
  33. /// Call this to wait for a result. Nonblocking.
  34. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoResponse?>) -> Void) throws
  35. }
  36. internal extension Echo_EchoExpandCall {
  37. /// Call this to wait for a result. Blocking.
  38. func receive(timeout: DispatchTime = .distantFuture) throws -> Echo_EchoResponse? { return try self._receive(timeout: timeout) }
  39. }
  40. fileprivate final class Echo_EchoExpandCallBase: ClientCallServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandCall {
  41. override class var method: String { return "/echo.Echo/Expand" }
  42. }
  43. internal protocol Echo_EchoCollectCall: ClientCallClientStreaming {
  44. /// Send a message to the stream. Nonblocking.
  45. func send(_ message: Echo_EchoRequest, completion: @escaping (Error?) -> Void) throws
  46. /// Do not call this directly, call `send()` in the protocol extension below instead.
  47. func _send(_ message: Echo_EchoRequest, timeout: DispatchTime) throws
  48. /// Call this to close the connection and wait for a response. Blocking.
  49. func closeAndReceive() throws -> Echo_EchoResponse
  50. /// Call this to close the connection and wait for a response. Nonblocking.
  51. func closeAndReceive(completion: @escaping (ResultOrRPCError<Echo_EchoResponse>) -> Void) throws
  52. }
  53. internal extension Echo_EchoCollectCall {
  54. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  55. func send(_ message: Echo_EchoRequest, timeout: DispatchTime = .distantFuture) throws { try self._send(message, timeout: timeout) }
  56. }
  57. fileprivate final class Echo_EchoCollectCallBase: ClientCallClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
  58. override class var method: String { return "/echo.Echo/Collect" }
  59. }
  60. internal protocol Echo_EchoUpdateCall: ClientCallBidirectionalStreaming {
  61. /// Do not call this directly, call `receive()` in the protocol extension below instead.
  62. func _receive(timeout: DispatchTime) throws -> Echo_EchoResponse?
  63. /// Call this to wait for a result. Nonblocking.
  64. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoResponse?>) -> Void) throws
  65. /// Send a message to the stream. Nonblocking.
  66. func send(_ message: Echo_EchoRequest, completion: @escaping (Error?) -> Void) throws
  67. /// Do not call this directly, call `send()` in the protocol extension below instead.
  68. func _send(_ message: Echo_EchoRequest, timeout: DispatchTime) throws
  69. /// Call this to close the sending connection. Blocking.
  70. func closeSend() throws
  71. /// Call this to close the sending connection. Nonblocking.
  72. func closeSend(completion: (() -> Void)?) throws
  73. }
  74. internal extension Echo_EchoUpdateCall {
  75. /// Call this to wait for a result. Blocking.
  76. func receive(timeout: DispatchTime = .distantFuture) throws -> Echo_EchoResponse? { return try self._receive(timeout: timeout) }
  77. }
  78. internal extension Echo_EchoUpdateCall {
  79. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  80. func send(_ message: Echo_EchoRequest, timeout: DispatchTime = .distantFuture) throws { try self._send(message, timeout: timeout) }
  81. }
  82. fileprivate final class Echo_EchoUpdateCallBase: ClientCallBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateCall {
  83. override class var method: String { return "/echo.Echo/Update" }
  84. }
  85. /// Instantiate Echo_EchoServiceClient, then call methods of this protocol to make API calls.
  86. internal protocol Echo_EchoService: ServiceClient {
  87. /// Synchronous. Unary.
  88. func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse
  89. /// Asynchronous. Unary.
  90. @discardableResult
  91. func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall
  92. /// Asynchronous. Server-streaming.
  93. /// Send the initial message.
  94. /// Use methods on the returned object to get streamed responses.
  95. func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall
  96. /// Asynchronous. Client-streaming.
  97. /// Use methods on the returned object to stream messages and
  98. /// to close the connection and wait for a final response.
  99. func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall
  100. /// Asynchronous. Bidirectional-streaming.
  101. /// Use methods on the returned object to stream messages,
  102. /// to wait for replies, and to close the connection.
  103. func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall
  104. }
  105. internal extension Echo_EchoService {
  106. /// Synchronous. Unary.
  107. func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
  108. return try self.get(request, metadata: self.metadata)
  109. }
  110. /// Asynchronous. Unary.
  111. @discardableResult
  112. func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  113. return try self.get(request, metadata: self.metadata, completion: completion)
  114. }
  115. /// Asynchronous. Server-streaming.
  116. func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  117. return try self.expand(request, metadata: self.metadata, completion: completion)
  118. }
  119. /// Asynchronous. Client-streaming.
  120. func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  121. return try self.collect(metadata: self.metadata, completion: completion)
  122. }
  123. /// Asynchronous. Bidirectional-streaming.
  124. func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  125. return try self.update(metadata: self.metadata, completion: completion)
  126. }
  127. }
  128. internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService {
  129. /// Synchronous. Unary.
  130. internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse {
  131. return try Echo_EchoGetCallBase(channel)
  132. .run(request: request, metadata: customMetadata)
  133. }
  134. /// Asynchronous. Unary.
  135. @discardableResult
  136. internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  137. return try Echo_EchoGetCallBase(channel)
  138. .start(request: request, metadata: customMetadata, completion: completion)
  139. }
  140. /// Asynchronous. Server-streaming.
  141. /// Send the initial message.
  142. /// Use methods on the returned object to get streamed responses.
  143. internal func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  144. return try Echo_EchoExpandCallBase(channel)
  145. .start(request: request, metadata: customMetadata, completion: completion)
  146. }
  147. /// Asynchronous. Client-streaming.
  148. /// Use methods on the returned object to stream messages and
  149. /// to close the connection and wait for a final response.
  150. internal func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  151. return try Echo_EchoCollectCallBase(channel)
  152. .start(metadata: customMetadata, completion: completion)
  153. }
  154. /// Asynchronous. Bidirectional-streaming.
  155. /// Use methods on the returned object to stream messages,
  156. /// to wait for replies, and to close the connection.
  157. internal func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  158. return try Echo_EchoUpdateCallBase(channel)
  159. .start(metadata: customMetadata, completion: completion)
  160. }
  161. }
  162. class Echo_EchoGetCallTestStub: ClientCallUnaryTestStub, Echo_EchoGetCall {
  163. override class var method: String { return "/echo.Echo/Get" }
  164. }
  165. class Echo_EchoExpandCallTestStub: ClientCallServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandCall {
  166. override class var method: String { return "/echo.Echo/Expand" }
  167. }
  168. /// Simple fake implementation of Echo_EchoCollectCall
  169. /// stores sent values for later verification and finall returns a previously-defined result.
  170. class Echo_EchoCollectCallTestStub: ClientCallClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
  171. override class var method: String { return "/echo.Echo/Collect" }
  172. }
  173. class Echo_EchoUpdateCallTestStub: ClientCallBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateCall {
  174. override class var method: String { return "/echo.Echo/Update" }
  175. }
  176. class Echo_EchoServiceTestStub: ServiceClientTestStubBase, Echo_EchoService {
  177. var getRequests: [Echo_EchoRequest] = []
  178. var getResponses: [Echo_EchoResponse] = []
  179. func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse {
  180. getRequests.append(request)
  181. defer { getResponses.removeFirst() }
  182. return getResponses.first!
  183. }
  184. @discardableResult
  185. func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  186. let response = try self.get(request)
  187. let callResult = CallResult(success: true, statusCode: .ok, statusMessage: "OK", resultData: nil, initialMetadata: nil, trailingMetadata: nil)
  188. completion(response, callResult)
  189. return Echo_EchoGetCallTestStub()
  190. }
  191. var expandRequests: [Echo_EchoRequest] = []
  192. var expandCalls: [Echo_EchoExpandCall] = []
  193. func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  194. expandRequests.append(request)
  195. defer { expandCalls.removeFirst() }
  196. return expandCalls.first!
  197. }
  198. var collectCalls: [Echo_EchoCollectCall] = []
  199. func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  200. defer { collectCalls.removeFirst() }
  201. return collectCalls.first!
  202. }
  203. var updateCalls: [Echo_EchoUpdateCall] = []
  204. func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  205. defer { updateCalls.removeFirst() }
  206. return updateCalls.first!
  207. }
  208. }
  209. /// To build a server, implement a class that conforms to this protocol.
  210. /// If one of the methods returning `ServerStatus?` returns nil,
  211. /// it is expected that you have already returned a status to the client by means of `session.close`.
  212. internal protocol Echo_EchoProvider: ServiceProvider {
  213. func get(request: Echo_EchoRequest, session: Echo_EchoGetSession) throws -> Echo_EchoResponse
  214. func expand(request: Echo_EchoRequest, session: Echo_EchoExpandSession) throws -> ServerStatus?
  215. func collect(session: Echo_EchoCollectSession) throws -> Echo_EchoResponse?
  216. func update(session: Echo_EchoUpdateSession) throws -> ServerStatus?
  217. }
  218. extension Echo_EchoProvider {
  219. internal var serviceName: String { return "echo.Echo" }
  220. /// Determines and calls the appropriate request handler, depending on the request's method.
  221. /// Throws `HandleMethodError.unknownMethod` for methods not handled by this service.
  222. internal func handleMethod(_ method: String, handler: Handler) throws -> ServerStatus? {
  223. switch method {
  224. case "/echo.Echo/Get":
  225. return try Echo_EchoGetSessionBase(
  226. handler: handler,
  227. providerBlock: { try self.get(request: $0, session: $1 as! Echo_EchoGetSessionBase) })
  228. .run()
  229. case "/echo.Echo/Expand":
  230. return try Echo_EchoExpandSessionBase(
  231. handler: handler,
  232. providerBlock: { try self.expand(request: $0, session: $1 as! Echo_EchoExpandSessionBase) })
  233. .run()
  234. case "/echo.Echo/Collect":
  235. return try Echo_EchoCollectSessionBase(
  236. handler: handler,
  237. providerBlock: { try self.collect(session: $0 as! Echo_EchoCollectSessionBase) })
  238. .run()
  239. case "/echo.Echo/Update":
  240. return try Echo_EchoUpdateSessionBase(
  241. handler: handler,
  242. providerBlock: { try self.update(session: $0 as! Echo_EchoUpdateSessionBase) })
  243. .run()
  244. default:
  245. throw HandleMethodError.unknownMethod
  246. }
  247. }
  248. }
  249. internal protocol Echo_EchoGetSession: ServerSessionUnary {}
  250. fileprivate final class Echo_EchoGetSessionBase: ServerSessionUnaryBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetSession {}
  251. class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession {}
  252. internal protocol Echo_EchoExpandSession: ServerSessionServerStreaming {
  253. /// Send a message to the stream. Nonblocking.
  254. func send(_ message: Echo_EchoResponse, completion: @escaping (Error?) -> Void) throws
  255. /// Do not call this directly, call `send()` in the protocol extension below instead.
  256. func _send(_ message: Echo_EchoResponse, timeout: DispatchTime) throws
  257. /// Close the connection and send the status. Non-blocking.
  258. /// This method should be called if and only if your request handler returns a nil value instead of a server status;
  259. /// otherwise SwiftGRPC will take care of sending the status for you.
  260. func close(withStatus status: ServerStatus, completion: (() -> Void)?) throws
  261. }
  262. internal extension Echo_EchoExpandSession {
  263. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  264. func send(_ message: Echo_EchoResponse, timeout: DispatchTime = .distantFuture) throws { try self._send(message, timeout: timeout) }
  265. }
  266. fileprivate final class Echo_EchoExpandSessionBase: ServerSessionServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession {}
  267. class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession {}
  268. internal protocol Echo_EchoCollectSession: ServerSessionClientStreaming {
  269. /// Do not call this directly, call `receive()` in the protocol extension below instead.
  270. func _receive(timeout: DispatchTime) throws -> Echo_EchoRequest?
  271. /// Call this to wait for a result. Nonblocking.
  272. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoRequest?>) -> Void) throws
  273. /// Exactly one of these two methods should be called if and only if your request handler returns nil;
  274. /// otherwise SwiftGRPC will take care of sending the response and status for you.
  275. /// Close the connection and send a single result. Non-blocking.
  276. func sendAndClose(response: Echo_EchoResponse, status: ServerStatus, completion: (() -> Void)?) throws
  277. /// Close the connection and send an error. Non-blocking.
  278. /// Use this method if you encountered an error that makes it impossible to send a response.
  279. /// Accordingly, it does not make sense to call this method with a status of `.ok`.
  280. func sendErrorAndClose(status: ServerStatus, completion: (() -> Void)?) throws
  281. }
  282. internal extension Echo_EchoCollectSession {
  283. /// Call this to wait for a result. Blocking.
  284. func receive(timeout: DispatchTime = .distantFuture) throws -> Echo_EchoRequest? { return try self._receive(timeout: timeout) }
  285. }
  286. fileprivate final class Echo_EchoCollectSessionBase: ServerSessionClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  287. class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  288. internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
  289. /// Do not call this directly, call `receive()` in the protocol extension below instead.
  290. func _receive(timeout: DispatchTime) throws -> Echo_EchoRequest?
  291. /// Call this to wait for a result. Nonblocking.
  292. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoRequest?>) -> Void) throws
  293. /// Send a message to the stream. Nonblocking.
  294. func send(_ message: Echo_EchoResponse, completion: @escaping (Error?) -> Void) throws
  295. /// Do not call this directly, call `send()` in the protocol extension below instead.
  296. func _send(_ message: Echo_EchoResponse, timeout: DispatchTime) throws
  297. /// Close the connection and send the status. Non-blocking.
  298. /// This method should be called if and only if your request handler returns a nil value instead of a server status;
  299. /// otherwise SwiftGRPC will take care of sending the status for you.
  300. func close(withStatus status: ServerStatus, completion: (() -> Void)?) throws
  301. }
  302. internal extension Echo_EchoUpdateSession {
  303. /// Call this to wait for a result. Blocking.
  304. func receive(timeout: DispatchTime = .distantFuture) throws -> Echo_EchoRequest? { return try self._receive(timeout: timeout) }
  305. }
  306. internal extension Echo_EchoUpdateSession {
  307. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  308. func send(_ message: Echo_EchoResponse, timeout: DispatchTime = .distantFuture) throws { try self._send(message, timeout: timeout) }
  309. }
  310. fileprivate final class Echo_EchoUpdateSessionBase: ServerSessionBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
  311. class Echo_EchoUpdateSessionTestStub: ServerSessionBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}