client.pb.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * DO NOT EDIT.
  3. *
  4. * Generated by the protocol buffer compiler.
  5. * Source: {{ protoFile.name }}
  6. *
  7. */
  8. /*
  9. *
  10. * Copyright 2017, 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 Dispatch
  42. import gRPC
  43. //-{% for service in protoFile.service %}
  44. /// Type for errors thrown from generated client code.
  45. public enum {{ .|clienterror:protoFile,service }} : Error {
  46. case endOfStream
  47. case invalidMessageReceived
  48. case error(c: CallResult)
  49. }
  50. //-{% for method in service.method %}
  51. //-{% if not method.clientStreaming and not method.serverStreaming %}
  52. //-{% include "client-call-unary.swift" %}
  53. //-{% endif %}
  54. //-{% if not method.clientStreaming and method.serverStreaming %}
  55. //-{% include "client-call-serverstreaming.swift" %}
  56. //-{% endif %}
  57. //-{% if method.clientStreaming and not method.serverStreaming %}
  58. //-{% include "client-call-clientstreaming.swift" %}
  59. //-{% endif %}
  60. //-{% if method.clientStreaming and method.serverStreaming %}
  61. //-{% include "client-call-bidistreaming.swift" %}
  62. //-{% endif %}
  63. //-{% endfor %}
  64. // Call methods of this class to make API calls.
  65. public class {{ .|serviceclass:protoFile,service }} {
  66. private var channel: Channel
  67. /// This metadata will be sent with all requests.
  68. public var metadata : Metadata
  69. /// This property allows the service host name to be overridden.
  70. /// For example, it can be used to make calls to "localhost:8080"
  71. /// appear to be to "example.com".
  72. public var host : String {
  73. get {
  74. return self.channel.host
  75. }
  76. set {
  77. self.channel.host = newValue
  78. }
  79. }
  80. /// Create a client that makes insecure connections.
  81. public init(address: String) {
  82. gRPC.initialize()
  83. channel = Channel(address:address)
  84. metadata = Metadata()
  85. }
  86. /// Create a client that makes secure connections.
  87. public init(address: String, certificates: String?, host: String?) {
  88. gRPC.initialize()
  89. channel = Channel(address:address, certificates:certificates, host:host)
  90. metadata = Metadata()
  91. }
  92. //-{% for method in service.method %}
  93. //-{% if not method.clientStreaming and not method.serverStreaming %}
  94. // Synchronous. Unary.
  95. public func {{ method.name|lowercase }}(_ request: {{ method|input }}) throws -> {{ method|output }} {
  96. return try {{ .|call:protoFile,service,method }}(channel).run(request:request, metadata:metadata)
  97. }
  98. //-{% endif %}
  99. //-{% if not method.clientStreaming and method.serverStreaming %}
  100. // Asynchronous. Server-streaming.
  101. // Send the initial message.
  102. // Use methods on the returned object to get streamed responses.
  103. public func {{ method.name|lowercase }}(_ request: {{ method|input }}) throws -> {{ .|call:protoFile,service,method }} {
  104. return try {{ .|call:protoFile,service,method }}(channel).run(request:request, metadata:metadata)
  105. }
  106. //-{% endif %}
  107. //-{% if method.clientStreaming and not method.serverStreaming %}
  108. // Asynchronous. Client-streaming.
  109. // Use methods on the returned object to stream messages and
  110. // to close the connection and wait for a final response.
  111. public func {{ method.name|lowercase }}() throws -> {{ .|call:protoFile,service,method }} {
  112. return try {{ .|call:protoFile,service,method }}(channel).run(metadata:metadata)
  113. }
  114. //-{% endif %}
  115. //-{% if method.clientStreaming and method.serverStreaming %}
  116. // Asynchronous. Bidirectional-streaming.
  117. // Use methods on the returned object to stream messages,
  118. // to wait for replies, and to close the connection.
  119. public func {{ method.name|lowercase }}() throws -> {{ .|call:protoFile,service,method }} {
  120. return try {{ .|call:protoFile,service,method }}(channel).run(metadata:metadata)
  121. }
  122. //-{% endif %}
  123. //-{% endfor %}
  124. }
  125. //-{% endfor %}