echo.grpc.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * DO NOT EDIT.
  3. *
  4. * Generated by the protocol buffer compiler.
  5. * Source: echo.proto
  6. *
  7. */
  8. /*
  9. * Copyright 2018, gRPC Authors All rights reserved.
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. import Foundation
  24. import Dispatch
  25. import gRPC
  26. import SwiftProtobuf
  27. internal protocol Echo_EchoGetCall: ClientCallUnary { }
  28. fileprivate final class Echo_EchoGetCallImpl: ClientCallUnaryImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetCall {
  29. override class var method: String { return "/echo.Echo/Get" }
  30. }
  31. internal protocol Echo_EchoExpandCall: ClientCallServerStreamingBase {
  32. /// Call this to wait for a result. Blocking.
  33. func receive() throws -> Echo_EchoResponse
  34. /// Call this to wait for a result. Nonblocking.
  35. func receive(completion: @escaping (Echo_EchoResponse?, ClientError?) -> Void) throws
  36. }
  37. fileprivate final class Echo_EchoExpandCallImpl: ClientCallServerStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandCall {
  38. override class var method: String { return "/echo.Echo/Expand" }
  39. }
  40. class Echo_EchoExpandCallTestStub: ClientCallServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandCall {
  41. override class var method: String { return "/echo.Echo/Expand" }
  42. }
  43. internal protocol Echo_EchoCollectCall: ClientCallClientStreamingBase {
  44. /// Call this to send each message in the request stream. Nonblocking.
  45. func send(_ message: Echo_EchoRequest, errorHandler: @escaping (Error) -> Void) throws
  46. /// Call this to close the connection and wait for a response. Blocking.
  47. func closeAndReceive() throws -> Echo_EchoResponse
  48. /// Call this to close the connection and wait for a response. Nonblocking.
  49. func closeAndReceive(completion: @escaping (Echo_EchoResponse?, ClientError?) -> Void) throws
  50. }
  51. fileprivate final class Echo_EchoCollectCallImpl: ClientCallClientStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
  52. override class var method: String { return "/echo.Echo/Collect" }
  53. }
  54. /// Simple fake implementation of Echo_EchoCollectCall
  55. /// stores sent values for later verification and finall returns a previously-defined result.
  56. class Echo_EchoCollectCallTestStub: ClientCallClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
  57. override class var method: String { return "/echo.Echo/Collect" }
  58. }
  59. internal protocol Echo_EchoUpdateCall: ClientCallBidirectionalStreamingBase {
  60. /// Call this to wait for a result. Blocking.
  61. func receive() throws -> Echo_EchoResponse
  62. /// Call this to wait for a result. Nonblocking.
  63. func receive(completion: @escaping (Echo_EchoResponse?, ClientError?) -> Void) throws
  64. /// Call this to send each message in the request stream.
  65. func send(_ message: Echo_EchoRequest, errorHandler: @escaping (Error) -> Void) throws
  66. /// Call this to close the sending connection. Blocking.
  67. func closeSend() throws
  68. /// Call this to close the sending connection. Nonblocking.
  69. func closeSend(completion: (() -> Void)?) throws
  70. }
  71. fileprivate final class Echo_EchoUpdateCallImpl: ClientCallBidirectionalStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateCall {
  72. override class var method: String { return "/echo.Echo/Update" }
  73. }
  74. class Echo_EchoUpdateCallTestStub: ClientCallBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateCall {
  75. override class var method: String { return "/echo.Echo/Update" }
  76. }
  77. /// Instantiate Echo_EchoServiceImpl, then call methods of this protocol to make API calls.
  78. internal protocol Echo_EchoService: ServiceClient {
  79. /// Synchronous. Unary.
  80. func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse
  81. /// Asynchronous. Unary.
  82. func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall
  83. /// Asynchronous. Server-streaming.
  84. /// Send the initial message.
  85. /// Use methods on the returned object to get streamed responses.
  86. func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall
  87. /// Asynchronous. Client-streaming.
  88. /// Use methods on the returned object to stream messages and
  89. /// to close the connection and wait for a final response.
  90. func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall
  91. /// Asynchronous. Bidirectional-streaming.
  92. /// Use methods on the returned object to stream messages,
  93. /// to wait for replies, and to close the connection.
  94. func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall
  95. }
  96. internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService {
  97. /// Synchronous. Unary.
  98. internal func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
  99. return try Echo_EchoGetCallImpl(channel)
  100. .run(request: request, metadata: metadata)
  101. }
  102. /// Asynchronous. Unary.
  103. internal func get(_ request: Echo_EchoRequest,
  104. completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  105. return try Echo_EchoGetCallImpl(channel)
  106. .start(request: request, metadata: metadata, completion: completion)
  107. }
  108. /// Asynchronous. Server-streaming.
  109. /// Send the initial message.
  110. /// Use methods on the returned object to get streamed responses.
  111. internal func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  112. return try Echo_EchoExpandCallImpl(channel)
  113. .start(request:request, metadata:metadata, completion:completion)
  114. }
  115. /// Asynchronous. Client-streaming.
  116. /// Use methods on the returned object to stream messages and
  117. /// to close the connection and wait for a final response.
  118. internal func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  119. return try Echo_EchoCollectCallImpl(channel)
  120. .start(metadata: metadata, completion: completion)
  121. }
  122. /// Asynchronous. Bidirectional-streaming.
  123. /// Use methods on the returned object to stream messages,
  124. /// to wait for replies, and to close the connection.
  125. internal func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  126. return try Echo_EchoUpdateCallImpl(channel)
  127. .start(metadata: metadata, completion: completion)
  128. }
  129. }
  130. class Echo_EchoServiceTestStub: ServiceClientTestStubBase, Echo_EchoService {
  131. var getRequests: [Echo_EchoRequest] = []
  132. var getResponses: [Echo_EchoResponse] = []
  133. func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
  134. getRequests.append(request)
  135. defer { getResponses.removeFirst() }
  136. return getResponses.first!
  137. }
  138. func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  139. fatalError("not implemented")
  140. }
  141. var expandRequests: [Echo_EchoRequest] = []
  142. var expandCalls: [Echo_EchoExpandCall] = []
  143. func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  144. expandRequests.append(request)
  145. defer { expandCalls.removeFirst() }
  146. return expandCalls.first!
  147. }
  148. var collectCalls: [Echo_EchoCollectCall] = []
  149. func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  150. defer { collectCalls.removeFirst() }
  151. return collectCalls.first!
  152. }
  153. var updateCalls: [Echo_EchoUpdateCall] = []
  154. func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  155. defer { updateCalls.removeFirst() }
  156. return updateCalls.first!
  157. }
  158. }
  159. /// To build a server, implement a class that conforms to this protocol.
  160. internal protocol Echo_EchoProvider {
  161. func get(request : Echo_EchoRequest, session : Echo_EchoGetSession) throws -> Echo_EchoResponse
  162. func expand(request : Echo_EchoRequest, session : Echo_EchoExpandSession) throws
  163. func collect(session : Echo_EchoCollectSession) throws
  164. func update(session : Echo_EchoUpdateSession) throws
  165. }
  166. internal protocol Echo_EchoGetSession: ServerSessionUnary { }
  167. fileprivate final class Echo_EchoGetSessionImpl: ServerSessionUnaryImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetSession {}
  168. class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession {}
  169. internal protocol Echo_EchoExpandSession: ServerSessionServerStreaming {
  170. /// Send a message. Nonblocking.
  171. func send(_ response: Echo_EchoResponse, completion: ((Bool) -> Void)?) throws
  172. }
  173. fileprivate final class Echo_EchoExpandSessionImpl: ServerSessionServerStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession {}
  174. class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession {}
  175. internal protocol Echo_EchoCollectSession: ServerSessionClientStreaming {
  176. /// Receive a message. Blocks until a message is received or the client closes the connection.
  177. func receive() throws -> Echo_EchoRequest
  178. /// Send a response and close the connection.
  179. func sendAndClose(_ response: Echo_EchoResponse) throws
  180. }
  181. fileprivate final class Echo_EchoCollectSessionImpl: ServerSessionClientStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  182. class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  183. internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
  184. /// Receive a message. Blocks until a message is received or the client closes the connection.
  185. func receive() throws -> Echo_EchoRequest
  186. /// Send a message. Nonblocking.
  187. func send(_ response: Echo_EchoResponse, completion: ((Bool) -> Void)?) throws
  188. /// Close a connection. Blocks until the connection is closed.
  189. func close() throws
  190. }
  191. fileprivate final class Echo_EchoUpdateSessionImpl: ServerSessionBidirectionalStreamingImpl<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
  192. class Echo_EchoUpdateSessionTestStub: ServerSessionBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
  193. /// Main server for generated service
  194. internal final class Echo_EchoServer: ServiceServer {
  195. private var provider: Echo_EchoProvider
  196. internal init(address: String, provider: Echo_EchoProvider) {
  197. self.provider = provider
  198. super.init(address: address)
  199. }
  200. internal init?(address: String, certificateURL: URL, keyURL: URL, provider: Echo_EchoProvider) {
  201. self.provider = provider
  202. super.init(address: address, certificateURL: certificateURL, keyURL: keyURL)
  203. }
  204. /// Start the server.
  205. internal override func handleMethod(_ method: String, handler: Handler, queue: DispatchQueue) throws -> Bool {
  206. let provider = self.provider
  207. switch method {
  208. case "/echo.Echo/Get":
  209. try Echo_EchoGetSessionImpl(
  210. handler: handler,
  211. providerBlock: { try provider.get(request: $0, session: $1 as! Echo_EchoGetSessionImpl) })
  212. .run(queue: queue)
  213. return true
  214. case "/echo.Echo/Expand":
  215. try Echo_EchoExpandSessionImpl(
  216. handler: handler,
  217. providerBlock: { try provider.expand(request: $0, session: $1 as! Echo_EchoExpandSessionImpl) })
  218. .run(queue: queue)
  219. return true
  220. case "/echo.Echo/Collect":
  221. try Echo_EchoCollectSessionImpl(
  222. handler: handler,
  223. providerBlock: { try provider.collect(session: $0 as! Echo_EchoCollectSessionImpl) })
  224. .run(queue: queue)
  225. return true
  226. case "/echo.Echo/Update":
  227. try Echo_EchoUpdateSessionImpl(
  228. handler: handler,
  229. providerBlock: { try provider.update(session: $0 as! Echo_EchoUpdateSessionImpl) })
  230. .run(queue: queue)
  231. return true
  232. default:
  233. return false
  234. }
  235. }
  236. }