echo.grpc.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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_EchoGetCallBase: ClientCallUnaryBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetCall {
  29. override class var method: String { return "/echo.Echo/Get" }
  30. }
  31. internal protocol Echo_EchoExpandCall: ClientCallServerStreaming {
  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_EchoExpandCallBase: ClientCallServerStreamingBase<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: ClientCallClientStreaming {
  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_EchoCollectCallBase: ClientCallClientStreamingBase<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: ClientCallBidirectionalStreaming {
  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_EchoUpdateCallBase: ClientCallBidirectionalStreamingBase<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_EchoServiceClient, 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_EchoGetCallBase(channel)
  100. .run(request: request, metadata: metadata)
  101. }
  102. /// Asynchronous. Unary.
  103. internal func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  104. return try Echo_EchoGetCallBase(channel)
  105. .start(request: request, metadata: metadata, completion: completion)
  106. }
  107. /// Asynchronous. Server-streaming.
  108. /// Send the initial message.
  109. /// Use methods on the returned object to get streamed responses.
  110. internal func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  111. return try Echo_EchoExpandCallBase(channel)
  112. .start(request: request, metadata: metadata, completion: completion)
  113. }
  114. /// Asynchronous. Client-streaming.
  115. /// Use methods on the returned object to stream messages and
  116. /// to close the connection and wait for a final response.
  117. internal func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  118. return try Echo_EchoCollectCallBase(channel)
  119. .start(metadata: metadata, completion: completion)
  120. }
  121. /// Asynchronous. Bidirectional-streaming.
  122. /// Use methods on the returned object to stream messages,
  123. /// to wait for replies, and to close the connection.
  124. internal func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  125. return try Echo_EchoUpdateCallBase(channel)
  126. .start(metadata: metadata, completion: completion)
  127. }
  128. }
  129. class Echo_EchoServiceTestStub: ServiceClientTestStubBase, Echo_EchoService {
  130. var getRequests: [Echo_EchoRequest] = []
  131. var getResponses: [Echo_EchoResponse] = []
  132. func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
  133. getRequests.append(request)
  134. defer { getResponses.removeFirst() }
  135. return getResponses.first!
  136. }
  137. func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
  138. fatalError("not implemented")
  139. }
  140. var expandRequests: [Echo_EchoRequest] = []
  141. var expandCalls: [Echo_EchoExpandCall] = []
  142. func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall {
  143. expandRequests.append(request)
  144. defer { expandCalls.removeFirst() }
  145. return expandCalls.first!
  146. }
  147. var collectCalls: [Echo_EchoCollectCall] = []
  148. func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall {
  149. defer { collectCalls.removeFirst() }
  150. return collectCalls.first!
  151. }
  152. var updateCalls: [Echo_EchoUpdateCall] = []
  153. func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall {
  154. defer { updateCalls.removeFirst() }
  155. return updateCalls.first!
  156. }
  157. }
  158. /// To build a server, implement a class that conforms to this protocol.
  159. internal protocol Echo_EchoProvider {
  160. func get(request: Echo_EchoRequest, session: Echo_EchoGetSession) throws -> Echo_EchoResponse
  161. func expand(request: Echo_EchoRequest, session: Echo_EchoExpandSession) throws
  162. func collect(session: Echo_EchoCollectSession) throws
  163. func update(session: Echo_EchoUpdateSession) throws
  164. }
  165. internal protocol Echo_EchoGetSession: ServerSessionUnary {}
  166. fileprivate final class Echo_EchoGetSessionBase: ServerSessionUnaryBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoGetSession {}
  167. class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession {}
  168. internal protocol Echo_EchoExpandSession: ServerSessionServerStreaming {
  169. /// Send a message. Nonblocking.
  170. func send(_ response: Echo_EchoResponse, completion: ((Bool) -> Void)?) throws
  171. }
  172. fileprivate final class Echo_EchoExpandSessionBase: ServerSessionServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession {}
  173. class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession {}
  174. internal protocol Echo_EchoCollectSession: ServerSessionClientStreaming {
  175. /// Receive a message. Blocks until a message is received or the client closes the connection.
  176. func receive() throws -> Echo_EchoRequest
  177. /// Send a response and close the connection.
  178. func sendAndClose(_ response: Echo_EchoResponse) throws
  179. }
  180. fileprivate final class Echo_EchoCollectSessionBase: ServerSessionClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  181. class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}
  182. internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
  183. /// Receive a message. Blocks until a message is received or the client closes the connection.
  184. func receive() throws -> Echo_EchoRequest
  185. /// Send a message. Nonblocking.
  186. func send(_ response: Echo_EchoResponse, completion: ((Bool) -> Void)?) throws
  187. /// Close a connection. Blocks until the connection is closed.
  188. func close() throws
  189. }
  190. fileprivate final class Echo_EchoUpdateSessionBase: ServerSessionBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
  191. class Echo_EchoUpdateSessionTestStub: ServerSessionBidirectionalStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
  192. /// Main server for generated service
  193. internal final class Echo_EchoServer: ServiceServer {
  194. private let provider: Echo_EchoProvider
  195. internal init(address: String, provider: Echo_EchoProvider) {
  196. self.provider = provider
  197. super.init(address: address)
  198. }
  199. internal init?(address: String, certificateURL: URL, keyURL: URL, provider: Echo_EchoProvider) {
  200. self.provider = provider
  201. super.init(address: address, certificateURL: certificateURL, keyURL: keyURL)
  202. }
  203. /// Start the server.
  204. internal override func handleMethod(_ method: String, handler: Handler, queue: DispatchQueue) throws -> Bool {
  205. let provider = self.provider
  206. switch method {
  207. case "/echo.Echo/Get":
  208. try Echo_EchoGetSessionBase(
  209. handler: handler,
  210. providerBlock: { try provider.get(request: $0, session: $1 as! Echo_EchoGetSessionBase) })
  211. .run(queue: queue)
  212. return true
  213. case "/echo.Echo/Expand":
  214. try Echo_EchoExpandSessionBase(
  215. handler: handler,
  216. providerBlock: { try provider.expand(request: $0, session: $1 as! Echo_EchoExpandSessionBase) })
  217. .run(queue: queue)
  218. return true
  219. case "/echo.Echo/Collect":
  220. try Echo_EchoCollectSessionBase(
  221. handler: handler,
  222. providerBlock: { try provider.collect(session: $0 as! Echo_EchoCollectSessionBase) })
  223. .run(queue: queue)
  224. return true
  225. case "/echo.Echo/Update":
  226. try Echo_EchoUpdateSessionBase(
  227. handler: handler,
  228. providerBlock: { try provider.update(session: $0 as! Echo_EchoUpdateSessionBase) })
  229. .run(queue: queue)
  230. return true
  231. default:
  232. return false
  233. }
  234. }
  235. }