echo.grpc.swift 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall
  105. /// Asynchronous. Server-streaming.
  106. /// Send the initial message.
  107. /// Use methods on the returned object to get streamed responses.
  108. func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall
  109. /// Asynchronous. Client-streaming.
  110. /// Use methods on the returned object to stream messages and
  111. /// to close the connection and wait for a final response.
  112. func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall
  113. /// Asynchronous. Bidirectional-streaming.
  114. /// Use methods on the returned object to stream messages,
  115. /// to wait for replies, and to close the connection.
  116. func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall
  117. }
  118. internal extension Echo_EchoService {
  119. /// Synchronous. Unary.
  120. func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
  121. return try self.get(request, metadata: self.metadata)
  122. }
  123. /// Asynchronous. Unary.
  124. func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  125. return try self.get(request, metadata: self.metadata, completion: completion)
  126. }
  127. /// Asynchronous. Server-streaming.
  128. func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  129. return try self.expand(request, metadata: self.metadata, completion: completion)
  130. }
  131. /// Asynchronous. Client-streaming.
  132. func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  133. return try self.collect(metadata: self.metadata, completion: completion)
  134. }
  135. /// Asynchronous. Bidirectional-streaming.
  136. func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  137. return try self.update(metadata: self.metadata, completion: completion)
  138. }
  139. }
  140. internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService {
  141. /// Synchronous. Unary.
  142. internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse {
  143. return try Echo_EchoGetCallBase(channel)
  144. .run(request: request, metadata: customMetadata)
  145. }
  146. /// Asynchronous. Unary.
  147. internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  148. return try Echo_EchoGetCallBase(channel)
  149. .start(request: request, metadata: customMetadata, completion: completion)
  150. }
  151. /// Asynchronous. Server-streaming.
  152. /// Send the initial message.
  153. /// Use methods on the returned object to get streamed responses.
  154. internal func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  155. return try Echo_EchoExpandCallBase(channel)
  156. .start(request: request, metadata: customMetadata, completion: completion)
  157. }
  158. /// Asynchronous. Client-streaming.
  159. /// Use methods on the returned object to stream messages and
  160. /// to close the connection and wait for a final response.
  161. internal func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  162. return try Echo_EchoCollectCallBase(channel)
  163. .start(metadata: customMetadata, completion: completion)
  164. }
  165. /// Asynchronous. Bidirectional-streaming.
  166. /// Use methods on the returned object to stream messages,
  167. /// to wait for replies, and to close the connection.
  168. internal func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  169. return try Echo_EchoUpdateCallBase(channel)
  170. .start(metadata: customMetadata, completion: completion)
  171. }
  172. }
  173. class Echo_EchoServiceTestStub: ServiceClientTestStubBase, Echo_EchoService {
  174. var getRequests: [Echo_EchoRequest] = []
  175. var getResponses: [Echo_EchoResponse] = []
  176. func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse {
  177. getRequests.append(request)
  178. defer { getResponses.removeFirst() }
  179. return getResponses.first!
  180. }
  181. func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  182. fatalError("not implemented")
  183. }
  184. var expandRequests: [Echo_EchoRequest] = []
  185. var expandCalls: [Echo_EchoExpandCall] = []
  186. func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  187. expandRequests.append(request)
  188. defer { expandCalls.removeFirst() }
  189. return expandCalls.first!
  190. }
  191. var collectCalls: [Echo_EchoCollectCall] = []
  192. func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  193. defer { collectCalls.removeFirst() }
  194. return collectCalls.first!
  195. }
  196. var updateCalls: [Echo_EchoUpdateCall] = []
  197. func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  198. defer { updateCalls.removeFirst() }
  199. return updateCalls.first!
  200. }
  201. }
  202. /// To build a server, implement a class that conforms to this protocol.
  203. /// If one of the methods returning `ServerStatus?` returns nil,
  204. /// it is expected that you have already returned a status to the client by means of `session.close`.
  205. internal protocol Echo_EchoProvider: ServiceProvider {
  206. func get(request: Echo_EchoRequest, session: Echo_EchoGetSession) throws -> Echo_EchoResponse
  207. func expand(request: Echo_EchoRequest, session: Echo_EchoExpandSession) throws -> ServerStatus?
  208. func collect(session: Echo_EchoCollectSession) throws -> Echo_EchoResponse?
  209. func update(session: Echo_EchoUpdateSession) throws -> ServerStatus?
  210. }
  211. extension Echo_EchoProvider {
  212. internal var serviceName: String { return "echo.Echo" }
  213. /// Determines and calls the appropriate request handler, depending on the request's method.
  214. /// Throws `HandleMethodError.unknownMethod` for methods not handled by this service.
  215. internal func handleMethod(_ method: String, handler: Handler) throws -> ServerStatus? {
  216. switch method {
  217. case "/echo.Echo/Get":
  218. return try Echo_EchoGetSessionBase(
  219. handler: handler,
  220. providerBlock: { try self.get(request: $0, session: $1 as! Echo_EchoGetSessionBase) })
  221. .run()
  222. case "/echo.Echo/Expand":
  223. return try Echo_EchoExpandSessionBase(
  224. handler: handler,
  225. providerBlock: { try self.expand(request: $0, session: $1 as! Echo_EchoExpandSessionBase) })
  226. .run()
  227. case "/echo.Echo/Collect":
  228. return try Echo_EchoCollectSessionBase(
  229. handler: handler,
  230. providerBlock: { try self.collect(session: $0 as! Echo_EchoCollectSessionBase) })
  231. .run()
  232. case "/echo.Echo/Update":
  233. return try Echo_EchoUpdateSessionBase(
  234. handler: handler,
  235. providerBlock: { try self.update(session: $0 as! Echo_EchoUpdateSessionBase) })
  236. .run()
  237. default:
  238. throw HandleMethodError.unknownMethod
  239. }
  240. }
  241. }
  242. internal protocol Echo_EchoGetSession: ServerSessionUnary {}
  243. fileprivate final class Echo_EchoGetSessionBase: ServerSessionUnaryBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetSession {}
  244. class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession {}
  245. internal protocol Echo_EchoExpandSession: ServerSessionServerStreaming {
  246. /// Send a message to the stream. Nonblocking.
  247. func send(_ message: Echo_EchoResponse, completion: @escaping (Error?) -> Void) throws
  248. /// Do not call this directly, call `send()` in the protocol extension below instead.
  249. func _send(_ message: Echo_EchoResponse, timeout: DispatchTime) throws
  250. /// Close the connection and send the status. Non-blocking.
  251. /// This method should be called if and only if your request handler returns a nil value instead of a server status;
  252. /// otherwise SwiftGRPC will take care of sending the status for you.
  253. func close(withStatus status: ServerStatus, completion: (() -> Void)?) throws
  254. }
  255. internal extension Echo_EchoExpandSession {
  256. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  257. func send(_ message: Echo_EchoResponse, timeout: DispatchTime = .distantFuture) throws { try self._send(message, timeout: timeout) }
  258. }
  259. fileprivate final class Echo_EchoExpandSessionBase: ServerSessionServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession {}
  260. class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession {}
  261. internal protocol Echo_EchoCollectSession: ServerSessionClientStreaming {
  262. /// Do not call this directly, call `receive()` in the protocol extension below instead.
  263. func _receive(timeout: DispatchTime) throws -> Echo_EchoRequest?
  264. /// Call this to wait for a result. Nonblocking.
  265. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoRequest?>) -> Void) throws
  266. /// Exactly one of these two methods should be called if and only if your request handler returns nil;
  267. /// otherwise SwiftGRPC will take care of sending the response and status for you.
  268. /// Close the connection and send a single result. Non-blocking.
  269. func sendAndClose(response: Echo_EchoResponse, status: ServerStatus, completion: (() -> Void)?) throws
  270. /// Close the connection and send an error. Non-blocking.
  271. /// Use this method if you encountered an error that makes it impossible to send a response.
  272. /// Accordingly, it does not make sense to call this method with a status of `.ok`.
  273. func sendErrorAndClose(status: ServerStatus, completion: (() -> Void)?) throws
  274. }
  275. internal extension Echo_EchoCollectSession {
  276. /// Call this to wait for a result. Blocking.
  277. func receive(timeout: DispatchTime = .distantFuture) throws -> Echo_EchoRequest? { return try self._receive(timeout: timeout) }
  278. }
  279. fileprivate final class Echo_EchoCollectSessionBase: ServerSessionClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  280. class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  281. internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
  282. /// Do not call this directly, call `receive()` in the protocol extension below instead.
  283. func _receive(timeout: DispatchTime) throws -> Echo_EchoRequest?
  284. /// Call this to wait for a result. Nonblocking.
  285. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoRequest?>) -> Void) throws
  286. /// Send a message to the stream. Nonblocking.
  287. func send(_ message: Echo_EchoResponse, completion: @escaping (Error?) -> Void) throws
  288. /// Do not call this directly, call `send()` in the protocol extension below instead.
  289. func _send(_ message: Echo_EchoResponse, timeout: DispatchTime) throws
  290. /// Close the connection and send the status. Non-blocking.
  291. /// This method should be called if and only if your request handler returns a nil value instead of a server status;
  292. /// otherwise SwiftGRPC will take care of sending the status for you.
  293. func close(withStatus status: ServerStatus, completion: (() -> Void)?) throws
  294. }
  295. internal extension Echo_EchoUpdateSession {
  296. /// Call this to wait for a result. Blocking.
  297. func receive(timeout: DispatchTime = .distantFuture) throws -> Echo_EchoRequest? { return try self._receive(timeout: timeout) }
  298. }
  299. internal extension Echo_EchoUpdateSession {
  300. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  301. func send(_ message: Echo_EchoResponse, timeout: DispatchTime = .distantFuture) throws { try self._send(message, timeout: timeout) }
  302. }
  303. fileprivate final class Echo_EchoUpdateSessionBase: ServerSessionBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
  304. class Echo_EchoUpdateSessionTestStub: ServerSessionBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}