client.pb.swift 5.1 KB

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