echo.grpc.swift 18 KB

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