echo.grpc.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. /// Call this to wait for a result. Blocking.
  32. func receive() throws -> Echo_EchoResponse?
  33. /// Call this to wait for a result. Nonblocking.
  34. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoResponse?>) -> Void) throws
  35. }
  36. fileprivate final class Echo_EchoExpandCallBase: ClientCallServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandCall {
  37. override class var method: String { return "/echo.Echo/Expand" }
  38. }
  39. class Echo_EchoExpandCallTestStub: ClientCallServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandCall {
  40. override class var method: String { return "/echo.Echo/Expand" }
  41. }
  42. internal protocol Echo_EchoCollectCall: ClientCallClientStreaming {
  43. /// Send a message to the stream. Nonblocking.
  44. func send(_ message: Echo_EchoRequest, completion: @escaping (Error?) -> Void) throws
  45. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  46. func send(_ message: Echo_EchoRequest) throws
  47. /// Call this to close the connection and wait for a response. Blocking.
  48. func closeAndReceive() throws -> Echo_EchoResponse
  49. /// Call this to close the connection and wait for a response. Nonblocking.
  50. func closeAndReceive(completion: @escaping (ResultOrRPCError<Echo_EchoResponse>) -> Void) throws
  51. }
  52. fileprivate final class Echo_EchoCollectCallBase: ClientCallClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
  53. override class var method: String { return "/echo.Echo/Collect" }
  54. }
  55. /// Simple fake implementation of Echo_EchoCollectCall
  56. /// stores sent values for later verification and finall returns a previously-defined result.
  57. class Echo_EchoCollectCallTestStub: ClientCallClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
  58. override class var method: String { return "/echo.Echo/Collect" }
  59. }
  60. internal protocol Echo_EchoUpdateCall: ClientCallBidirectionalStreaming {
  61. /// Call this to wait for a result. Blocking.
  62. func receive() 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. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  68. func send(_ message: Echo_EchoRequest) 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. fileprivate final class Echo_EchoUpdateCallBase: ClientCallBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateCall {
  75. override class var method: String { return "/echo.Echo/Update" }
  76. }
  77. class Echo_EchoUpdateCallTestStub: ClientCallBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateCall {
  78. override class var method: String { return "/echo.Echo/Update" }
  79. }
  80. /// Instantiate Echo_EchoServiceClient, then call methods of this protocol to make API calls.
  81. internal protocol Echo_EchoService: ServiceClient {
  82. /// Synchronous. Unary.
  83. func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse
  84. /// Asynchronous. Unary.
  85. func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall
  86. /// Asynchronous. Server-streaming.
  87. /// Send the initial message.
  88. /// Use methods on the returned object to get streamed responses.
  89. func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall
  90. /// Asynchronous. Client-streaming.
  91. /// Use methods on the returned object to stream messages and
  92. /// to close the connection and wait for a final response.
  93. func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall
  94. /// Asynchronous. Bidirectional-streaming.
  95. /// Use methods on the returned object to stream messages,
  96. /// to wait for replies, and to close the connection.
  97. func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall
  98. }
  99. internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService {
  100. /// Synchronous. Unary.
  101. internal func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
  102. return try Echo_EchoGetCallBase(channel)
  103. .run(request: request, metadata: metadata)
  104. }
  105. /// Asynchronous. Unary.
  106. internal func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  107. return try Echo_EchoGetCallBase(channel)
  108. .start(request: request, metadata: metadata, completion: completion)
  109. }
  110. /// Asynchronous. Server-streaming.
  111. /// Send the initial message.
  112. /// Use methods on the returned object to get streamed responses.
  113. internal func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  114. return try Echo_EchoExpandCallBase(channel)
  115. .start(request: request, metadata: metadata, completion: completion)
  116. }
  117. /// Asynchronous. Client-streaming.
  118. /// Use methods on the returned object to stream messages and
  119. /// to close the connection and wait for a final response.
  120. internal func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  121. return try Echo_EchoCollectCallBase(channel)
  122. .start(metadata: metadata, completion: completion)
  123. }
  124. /// Asynchronous. Bidirectional-streaming.
  125. /// Use methods on the returned object to stream messages,
  126. /// to wait for replies, and to close the connection.
  127. internal func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  128. return try Echo_EchoUpdateCallBase(channel)
  129. .start(metadata: metadata, completion: completion)
  130. }
  131. }
  132. class Echo_EchoServiceTestStub: ServiceClientTestStubBase, Echo_EchoService {
  133. var getRequests: [Echo_EchoRequest] = []
  134. var getResponses: [Echo_EchoResponse] = []
  135. func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
  136. getRequests.append(request)
  137. defer { getResponses.removeFirst() }
  138. return getResponses.first!
  139. }
  140. func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  141. fatalError("not implemented")
  142. }
  143. var expandRequests: [Echo_EchoRequest] = []
  144. var expandCalls: [Echo_EchoExpandCall] = []
  145. func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  146. expandRequests.append(request)
  147. defer { expandCalls.removeFirst() }
  148. return expandCalls.first!
  149. }
  150. var collectCalls: [Echo_EchoCollectCall] = []
  151. func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  152. defer { collectCalls.removeFirst() }
  153. return collectCalls.first!
  154. }
  155. var updateCalls: [Echo_EchoUpdateCall] = []
  156. func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  157. defer { updateCalls.removeFirst() }
  158. return updateCalls.first!
  159. }
  160. }
  161. /// To build a server, implement a class that conforms to this protocol.
  162. internal protocol Echo_EchoProvider {
  163. func get(request: Echo_EchoRequest, session: Echo_EchoGetSession) throws -> Echo_EchoResponse
  164. func expand(request: Echo_EchoRequest, session: Echo_EchoExpandSession) throws
  165. func collect(session: Echo_EchoCollectSession) throws
  166. func update(session: Echo_EchoUpdateSession) throws
  167. }
  168. internal protocol Echo_EchoGetSession: ServerSessionUnary {}
  169. fileprivate final class Echo_EchoGetSessionBase: ServerSessionUnaryBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetSession {}
  170. class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession {}
  171. internal protocol Echo_EchoExpandSession: ServerSessionServerStreaming {
  172. /// Send a message to the stream. Nonblocking.
  173. func send(_ message: Echo_EchoResponse, completion: @escaping (Error?) -> Void) throws
  174. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  175. func send(_ message: Echo_EchoResponse) throws
  176. /// Close the connection and send the status. Non-blocking.
  177. /// You MUST call this method once you are done processing the request.
  178. func close(withStatus status: ServerStatus, completion: ((CallResult) -> Void)?) throws
  179. }
  180. fileprivate final class Echo_EchoExpandSessionBase: ServerSessionServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession {}
  181. class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession {}
  182. internal protocol Echo_EchoCollectSession: ServerSessionClientStreaming {
  183. /// Call this to wait for a result. Blocking.
  184. func receive() throws -> Echo_EchoRequest?
  185. /// Call this to wait for a result. Nonblocking.
  186. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoRequest?>) -> Void) throws
  187. /// You MUST call one of these two methods once you are done processing the request.
  188. /// Close the connection and send a single result. Non-blocking.
  189. func sendAndClose(response: Echo_EchoResponse, status: ServerStatus, completion: ((CallResult) -> Void)?) throws
  190. /// Close the connection and send an error. Non-blocking.
  191. /// Use this method if you encountered an error that makes it impossible to send a response.
  192. /// Accordingly, it does not make sense to call this method with a status of `.ok`.
  193. func sendErrorAndClose(status: ServerStatus, completion: ((CallResult) -> Void)?) throws
  194. }
  195. fileprivate final class Echo_EchoCollectSessionBase: ServerSessionClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  196. class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  197. internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
  198. /// Call this to wait for a result. Blocking.
  199. func receive() throws -> Echo_EchoRequest?
  200. /// Call this to wait for a result. Nonblocking.
  201. func receive(completion: @escaping (ResultOrRPCError<Echo_EchoRequest?>) -> Void) throws
  202. /// Send a message to the stream. Nonblocking.
  203. func send(_ message: Echo_EchoResponse, completion: @escaping (Error?) -> Void) throws
  204. /// Send a message to the stream and wait for the send operation to finish. Blocking.
  205. func send(_ message: Echo_EchoResponse) throws
  206. /// Close the connection and send the status. Non-blocking.
  207. /// You MUST call this method once you are done processing the request.
  208. func close(withStatus status: ServerStatus, completion: ((CallResult) -> Void)?) throws
  209. }
  210. fileprivate final class Echo_EchoUpdateSessionBase: ServerSessionBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
  211. class Echo_EchoUpdateSessionTestStub: ServerSessionBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
  212. /// Main server for generated service
  213. internal final class Echo_EchoServer: ServiceServer {
  214. private let provider: Echo_EchoProvider
  215. internal init(address: String, provider: Echo_EchoProvider) {
  216. self.provider = provider
  217. super.init(address: address)
  218. }
  219. internal init?(address: String, certificateURL: URL, keyURL: URL, provider: Echo_EchoProvider) {
  220. self.provider = provider
  221. super.init(address: address, certificateURL: certificateURL, keyURL: keyURL)
  222. }
  223. internal init?(address: String, certificateString: String, keyString: String, provider: Echo_EchoProvider) {
  224. self.provider = provider
  225. super.init(address: address, certificateString: certificateString, keyString: keyString)
  226. }
  227. /// Start the server.
  228. internal override func handleMethod(_ method: String, handler: Handler, queue: DispatchQueue) throws -> Bool {
  229. let provider = self.provider
  230. switch method {
  231. case "/echo.Echo/Get":
  232. try Echo_EchoGetSessionBase(
  233. handler: handler,
  234. providerBlock: { try provider.get(request: $0, session: $1 as! Echo_EchoGetSessionBase) })
  235. .run(queue: queue)
  236. return true
  237. case "/echo.Echo/Expand":
  238. try Echo_EchoExpandSessionBase(
  239. handler: handler,
  240. providerBlock: { try provider.expand(request: $0, session: $1 as! Echo_EchoExpandSessionBase) })
  241. .run(queue: queue)
  242. return true
  243. case "/echo.Echo/Collect":
  244. try Echo_EchoCollectSessionBase(
  245. handler: handler,
  246. providerBlock: { try provider.collect(session: $0 as! Echo_EchoCollectSessionBase) })
  247. .run(queue: queue)
  248. return true
  249. case "/echo.Echo/Update":
  250. try Echo_EchoUpdateSessionBase(
  251. handler: handler,
  252. providerBlock: { try provider.update(session: $0 as! Echo_EchoUpdateSessionBase) })
  253. .run(queue: queue)
  254. return true
  255. default:
  256. return false
  257. }
  258. }
  259. }