client.pb.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. public enum {{ .|clienterror:protoFile,service }} : Error {
  44. case endOfStream
  45. case invalidMessageReceived
  46. case error(c: CallResult)
  47. }
  48. //-{% for method in service.method %}
  49. //-{% if not method.clientStreaming and not method.serverStreaming %}
  50. //-{% include "client-call-unary.swift" %}
  51. //-{% endif %}
  52. //-{% if not method.clientStreaming and method.serverStreaming %}
  53. //-{% include "client-call-serverstreaming.swift" %}
  54. //-{% endif %}
  55. //-{% if method.clientStreaming and not method.serverStreaming %}
  56. //-{% include "client-call-clientstreaming.swift" %}
  57. //-{% endif %}
  58. //-{% if method.clientStreaming and method.serverStreaming %}
  59. //-{% include "client-call-bidistreaming.swift" %}
  60. //-{% endif %}
  61. //-{% endfor %}
  62. // Call methods of this class to make API calls.
  63. public class {{ protoFile.package|capitalize }}_{{ service.name }}Service {
  64. private var channel: Channel
  65. public var metadata : Metadata
  66. public var host : String {
  67. get {
  68. return self.channel.host
  69. }
  70. set {
  71. self.channel.host = newValue
  72. }
  73. }
  74. public init(address: String) {
  75. gRPC.initialize()
  76. channel = Channel(address:address)
  77. metadata = Metadata()
  78. }
  79. public init(address: String, certificates: String?, host: String?) {
  80. gRPC.initialize()
  81. channel = Channel(address:address, certificates:certificates, host:host)
  82. metadata = Metadata()
  83. }
  84. //-{% for method in service.method %}
  85. //-{% if not method.clientStreaming and not method.serverStreaming %}
  86. // Synchronous. Unary.
  87. public func {{ method.name|lowercase }}(_ request: {{ method|input }}) throws -> {{ method|output }} {
  88. return try {{ .|call:protoFile,service,method }}(channel).run(request:request, metadata:metadata)
  89. }
  90. //-{% endif %}
  91. //-{% if not method.clientStreaming and method.serverStreaming %}
  92. // Asynchronous. Server-streaming.
  93. // Send the initial message.
  94. // Use methods on the returned object to get streamed responses.
  95. public func {{ method.name|lowercase }}(_ request: {{ method|input }}) throws -> {{ .|call:protoFile,service,method }} {
  96. return try {{ .|call:protoFile,service,method }}(channel).run(request:request, metadata:metadata)
  97. }
  98. //-{% endif %}
  99. //-{% if method.clientStreaming and not method.serverStreaming %}
  100. // Asynchronous. Client-streaming.
  101. // Use methods on the returned object to stream messages and
  102. // to close the connection and wait for a final response.
  103. public func {{ method.name|lowercase }}() throws -> {{ .|call:protoFile,service,method }} {
  104. return try {{ .|call:protoFile,service,method }}(channel).run(metadata:metadata)
  105. }
  106. //-{% endif %}
  107. //-{% if method.clientStreaming and method.serverStreaming %}
  108. // Asynchronous. Bidirectional-streaming.
  109. // Use methods on the returned object to stream messages,
  110. // to wait for replies, and to close the connection.
  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. //-{% endfor %}
  116. }
  117. //-{% endfor %}