client.pb.swift 4.8 KB

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