client.pb.swift 4.9 KB

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