echo.grpc.swift 12 KB

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