echo.client.pb.swift 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * DO NOT EDIT.
  3. *
  4. * Generated by the protocol buffer compiler.
  5. * Source: echo.proto
  6. *
  7. */
  8. /*
  9. *
  10. * Copyright 2016, Google Inc.
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are
  15. * met:
  16. *
  17. * * Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * * Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following disclaimer
  21. * in the documentation and/or other materials provided with the
  22. * distribution.
  23. * * Neither the name of Google Inc. nor the names of its
  24. * contributors may be used to endorse or promote products derived from
  25. * this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  35. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. import Foundation
  41. import gRPC
  42. /// Type for errors thrown from generated client code.
  43. public enum Echo_EchoClientError : Error {
  44. case endOfStream
  45. case invalidMessageReceived
  46. case error(c: CallResult)
  47. }
  48. // Get (Unary)
  49. public class Echo_EchoGetCall {
  50. private var call : Call
  51. /// Create a call.
  52. fileprivate init(_ channel: Channel) {
  53. self.call = channel.makeCall("/echo.Echo/Get")
  54. }
  55. /// Run the call. Blocks until the reply is received.
  56. fileprivate func run(request: Echo_EchoRequest,
  57. metadata: Metadata) throws -> Echo_EchoResponse {
  58. let done = NSCondition()
  59. var callResult : CallResult!
  60. var response : Echo_EchoResponse?
  61. let requestData = try request.serializeProtobuf()
  62. try call.start(.unary,
  63. metadata:metadata,
  64. message:requestData)
  65. {(_callResult) in
  66. callResult = _callResult
  67. if let responseData = callResult.resultData {
  68. response = try? Echo_EchoResponse(protobuf:responseData)
  69. }
  70. done.lock()
  71. done.signal()
  72. done.unlock()
  73. }
  74. done.lock()
  75. done.wait()
  76. done.unlock()
  77. if let response = response {
  78. return response
  79. } else {
  80. throw Echo_EchoClientError.error(c: callResult)
  81. }
  82. }
  83. }
  84. // Expand (Server Streaming)
  85. public class Echo_EchoExpandCall {
  86. private var call : Call
  87. /// Create a call.
  88. fileprivate init(_ channel: Channel) {
  89. self.call = channel.makeCall("/echo.Echo/Expand")
  90. }
  91. // Call this once with the message to send.
  92. fileprivate func run(request: Echo_EchoRequest, metadata: Metadata) throws -> Echo_EchoExpandCall {
  93. let requestData = try request.serializeProtobuf()
  94. let done = NSCondition()
  95. try call.start(.serverStreaming,
  96. metadata:metadata,
  97. message:requestData)
  98. {callResult in
  99. done.lock()
  100. done.signal()
  101. done.unlock()
  102. }
  103. done.lock()
  104. done.wait()
  105. done.unlock()
  106. return self
  107. }
  108. // Call this to wait for a result. Blocks.
  109. public func Receive() throws -> Echo_EchoResponse {
  110. var returnError : Echo_EchoClientError?
  111. var response : Echo_EchoResponse!
  112. let done = NSCondition()
  113. do {
  114. try call.receiveMessage() {(responseData) in
  115. if let responseData = responseData {
  116. response = try? Echo_EchoResponse(protobuf:responseData)
  117. if response == nil {
  118. returnError = Echo_EchoClientError.invalidMessageReceived
  119. }
  120. } else {
  121. returnError = Echo_EchoClientError.endOfStream
  122. }
  123. done.lock()
  124. done.signal()
  125. done.unlock()
  126. }
  127. done.lock()
  128. done.wait()
  129. done.unlock()
  130. }
  131. if let returnError = returnError {
  132. throw returnError
  133. }
  134. return response
  135. }
  136. }
  137. // Collect (Client Streaming)
  138. public class Echo_EchoCollectCall {
  139. private var call : Call
  140. /// Create a call.
  141. fileprivate init(_ channel: Channel) {
  142. self.call = channel.makeCall("/echo.Echo/Collect")
  143. }
  144. // Call this to start a call.
  145. fileprivate func run(metadata:Metadata) throws -> Echo_EchoCollectCall {
  146. let done = NSCondition()
  147. try self.call.start(.clientStreaming,
  148. metadata:metadata)
  149. {callResult in
  150. done.lock()
  151. done.signal()
  152. done.unlock()
  153. }
  154. done.lock()
  155. done.wait()
  156. done.unlock()
  157. return self
  158. }
  159. // Call this to send each message in the request stream.
  160. public func Send(_ message: Echo_EchoRequest) throws {
  161. let messageData = try message.serializeProtobuf()
  162. try call.sendMessage(data:messageData)
  163. }
  164. // Call this to close the connection and wait for a response. Blocks.
  165. public func CloseAndReceive() throws -> Echo_EchoResponse {
  166. var returnError : Echo_EchoClientError?
  167. var returnResponse : Echo_EchoResponse!
  168. let done = NSCondition()
  169. do {
  170. try call.receiveMessage() {(responseData) in
  171. if let responseData = responseData,
  172. let response = try? Echo_EchoResponse(protobuf:responseData) {
  173. returnResponse = response
  174. } else {
  175. returnError = Echo_EchoClientError.invalidMessageReceived
  176. }
  177. done.lock()
  178. done.signal()
  179. done.unlock()
  180. }
  181. try call.close(completion:{})
  182. done.lock()
  183. done.wait()
  184. done.unlock()
  185. } catch (let error) {
  186. throw error
  187. }
  188. if let returnError = returnError {
  189. throw returnError
  190. }
  191. return returnResponse
  192. }
  193. }
  194. // Update (Bidirectional Streaming)
  195. public class Echo_EchoUpdateCall {
  196. private var call : Call
  197. /// Create a call.
  198. fileprivate init(_ channel: Channel) {
  199. self.call = channel.makeCall("/echo.Echo/Update")
  200. }
  201. fileprivate func run(metadata:Metadata) throws -> Echo_EchoUpdateCall {
  202. let done = NSCondition()
  203. try self.call.start(.bidiStreaming,
  204. metadata:metadata)
  205. {callResult in
  206. done.lock()
  207. done.signal()
  208. done.unlock()
  209. }
  210. done.lock()
  211. done.wait()
  212. done.unlock()
  213. return self
  214. }
  215. public func Receive() throws -> Echo_EchoResponse {
  216. var returnError : Echo_EchoClientError?
  217. var returnMessage : Echo_EchoResponse!
  218. let done = NSCondition()
  219. do {
  220. try call.receiveMessage() {(data) in
  221. if let data = data {
  222. returnMessage = try? Echo_EchoResponse(protobuf:data)
  223. if returnMessage == nil {
  224. returnError = Echo_EchoClientError.invalidMessageReceived
  225. }
  226. } else {
  227. returnError = Echo_EchoClientError.endOfStream
  228. }
  229. done.lock()
  230. done.signal()
  231. done.unlock()
  232. }
  233. done.lock()
  234. done.wait()
  235. done.unlock()
  236. }
  237. if let returnError = returnError {
  238. throw returnError
  239. }
  240. return returnMessage
  241. }
  242. public func Send(_ message:Echo_EchoRequest) throws {
  243. let messageData = try message.serializeProtobuf()
  244. try call.sendMessage(data:messageData)
  245. }
  246. public func CloseSend() throws {
  247. let done = NSCondition()
  248. try call.close() {
  249. done.lock()
  250. done.signal()
  251. done.unlock()
  252. }
  253. done.lock()
  254. done.wait()
  255. done.unlock()
  256. }
  257. }
  258. // Call methods of this class to make API calls.
  259. public class Echo_EchoService {
  260. private var channel: Channel
  261. /// This metadata will be sent with all requests.
  262. public var metadata : Metadata
  263. /// This property allows the service host name to be overridden.
  264. /// For example, it can be used to make calls to "localhost:8080"
  265. /// appear to be to "example.com".
  266. public var host : String {
  267. get {
  268. return self.channel.host
  269. }
  270. set {
  271. self.channel.host = newValue
  272. }
  273. }
  274. /// Create a client that makes insecure connections.
  275. public init(address: String) {
  276. gRPC.initialize()
  277. channel = Channel(address:address)
  278. metadata = Metadata()
  279. }
  280. /// Create a client that makes secure connections.
  281. public init(address: String, certificates: String?, host: String?) {
  282. gRPC.initialize()
  283. channel = Channel(address:address, certificates:certificates, host:host)
  284. metadata = Metadata()
  285. }
  286. // Synchronous. Unary.
  287. public func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse {
  288. return try Echo_EchoGetCall(channel).run(request:request, metadata:metadata)
  289. }
  290. // Asynchronous. Server-streaming.
  291. // Send the initial message.
  292. // Use methods on the returned object to get streamed responses.
  293. public func expand(_ request: Echo_EchoRequest) throws -> Echo_EchoExpandCall {
  294. return try Echo_EchoExpandCall(channel).run(request:request, metadata:metadata)
  295. }
  296. // Asynchronous. Client-streaming.
  297. // Use methods on the returned object to stream messages and
  298. // to close the connection and wait for a final response.
  299. public func collect() throws -> Echo_EchoCollectCall {
  300. return try Echo_EchoCollectCall(channel).run(metadata:metadata)
  301. }
  302. // Asynchronous. Bidirectional-streaming.
  303. // Use methods on the returned object to stream messages,
  304. // to wait for replies, and to close the connection.
  305. public func update() throws -> Echo_EchoUpdateCall {
  306. return try Echo_EchoUpdateCall(channel).run(metadata:metadata)
  307. }
  308. }