2
0

echo.grpc.swift 18 KB

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