|
|
@@ -1,12 +1,5 @@
|
|
|
//-{% for service in file.services %}
|
|
|
|
|
|
-/// Type for errors thrown from generated client code.
|
|
|
-{{ access }} enum {{ .|clienterror:file,service }} : Error {
|
|
|
- case endOfStream
|
|
|
- case invalidMessageReceived
|
|
|
- case error(c: CallResult)
|
|
|
-}
|
|
|
-
|
|
|
//-{% for method in service.methods %}
|
|
|
//-{% if method|methodIsUnary %}
|
|
|
//-{% include "client-call-unary.swift" %}
|
|
|
@@ -42,29 +35,25 @@
|
|
|
/// Synchronous. Unary.
|
|
|
func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}) throws -> {{ method|output }}
|
|
|
/// Asynchronous. Unary.
|
|
|
- func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }},
|
|
|
- completion: @escaping ({{ method|output }}?, CallResult)->()) throws -> {{ .|call:file,service,method }}
|
|
|
+ func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: @escaping ({{ method|output }}?, CallResult) -> Void) throws -> {{ .|call:file,service,method }}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsServerStreaming %}
|
|
|
/// Asynchronous. Server-streaming.
|
|
|
/// Send the initial message.
|
|
|
/// Use methods on the returned object to get streamed responses.
|
|
|
- func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: ((CallResult)->())?)
|
|
|
- throws -> {{ .|call:file,service,method }}
|
|
|
+ func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsClientStreaming %}
|
|
|
/// Asynchronous. Client-streaming.
|
|
|
/// Use methods on the returned object to stream messages and
|
|
|
/// to close the connection and wait for a final response.
|
|
|
- func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult)->())?)
|
|
|
- throws -> {{ .|call:file,service,method }}
|
|
|
+ func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsBidiStreaming %}
|
|
|
/// Asynchronous. Bidirectional-streaming.
|
|
|
/// Use methods on the returned object to stream messages,
|
|
|
/// to wait for replies, and to close the connection.
|
|
|
- func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult)->())?)
|
|
|
- throws -> {{ .|call:file,service,method }}
|
|
|
+ func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }}
|
|
|
//-{% endif %}
|
|
|
|
|
|
//-{% endfor %}
|
|
|
@@ -76,21 +65,13 @@
|
|
|
{{ access }} var metadata : Metadata
|
|
|
|
|
|
{{ access }} var host : String {
|
|
|
- get {
|
|
|
- return self.channel.host
|
|
|
- }
|
|
|
- set {
|
|
|
- self.channel.host = newValue
|
|
|
- }
|
|
|
+ get { return self.channel.host }
|
|
|
+ set { self.channel.host = newValue }
|
|
|
}
|
|
|
|
|
|
{{ access }} var timeout : TimeInterval {
|
|
|
- get {
|
|
|
- return self.channel.timeout
|
|
|
- }
|
|
|
- set {
|
|
|
- self.channel.timeout = newValue
|
|
|
- }
|
|
|
+ get { return self.channel.timeout }
|
|
|
+ set { self.channel.timeout = newValue }
|
|
|
}
|
|
|
|
|
|
/// Create a client.
|
|
|
@@ -110,49 +91,42 @@
|
|
|
//-{% for method in service.methods %}
|
|
|
//-{% if method|methodIsUnary %}
|
|
|
/// Synchronous. Unary.
|
|
|
- {{ access }} func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }})
|
|
|
- throws
|
|
|
- -> {{ method|output }} {
|
|
|
- return try {{ .|call:file,service,method }}Impl(channel).run(request:request, metadata:metadata)
|
|
|
+ {{ access }} func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}) throws -> {{ method|output }} {
|
|
|
+ return try {{ .|call:file,service,method }}Impl(channel)
|
|
|
+ .run(request: request, metadata: metadata)
|
|
|
}
|
|
|
/// Asynchronous. Unary.
|
|
|
{{ access }} func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }},
|
|
|
- completion: @escaping ({{ method|output }}?, CallResult)->())
|
|
|
- throws
|
|
|
- -> {{ .|call:file,service,method }} {
|
|
|
- return try {{ .|call:file,service,method }}Impl(channel).start(request:request,
|
|
|
- metadata:metadata,
|
|
|
- completion:completion)
|
|
|
+ completion: @escaping ({{ method|output }}?, CallResult) -> Void) throws -> {{ .|call:file,service,method }} {
|
|
|
+ return try {{ .|call:file,service,method }}Impl(channel)
|
|
|
+ .start(request: request, metadata: metadata, completion: completion)
|
|
|
}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsServerStreaming %}
|
|
|
/// Asynchronous. Server-streaming.
|
|
|
/// Send the initial message.
|
|
|
/// Use methods on the returned object to get streamed responses.
|
|
|
- {{ access }} func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: ((CallResult)->())?)
|
|
|
- throws
|
|
|
- -> {{ .|call:file,service,method }} {
|
|
|
- return try {{ .|call:file,service,method }}Impl(channel).start(request:request, metadata:metadata, completion:completion)
|
|
|
+ {{ access }} func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
|
|
|
+ return try {{ .|call:file,service,method }}Impl(channel)
|
|
|
+ .start(request:request, metadata:metadata, completion:completion)
|
|
|
}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsClientStreaming %}
|
|
|
/// Asynchronous. Client-streaming.
|
|
|
/// Use methods on the returned object to stream messages and
|
|
|
/// to close the connection and wait for a final response.
|
|
|
- {{ access }} func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult)->())?)
|
|
|
- throws
|
|
|
- -> {{ .|call:file,service,method }} {
|
|
|
- return try {{ .|call:file,service,method }}Impl(channel).start(metadata:metadata, completion:completion)
|
|
|
+ {{ access }} func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
|
|
|
+ return try {{ .|call:file,service,method }}Impl(channel)
|
|
|
+ .start(metadata: metadata, completion: completion)
|
|
|
}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsBidiStreaming %}
|
|
|
/// Asynchronous. Bidirectional-streaming.
|
|
|
/// Use methods on the returned object to stream messages,
|
|
|
/// to wait for replies, and to close the connection.
|
|
|
- {{ access }} func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult)->())?)
|
|
|
- throws
|
|
|
- -> {{ .|call:file,service,method }} {
|
|
|
- return try {{ .|call:file,service,method }}Impl(channel).start(metadata:metadata, completion:completion)
|
|
|
+ {{ access }} func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
|
|
|
+ return try {{ .|call:file,service,method }}Impl(channel)
|
|
|
+ .start(metadata: metadata, completion: completion)
|
|
|
}
|
|
|
//-{% endif %}
|
|
|
|
|
|
@@ -178,35 +152,31 @@ class {{ .|serviceclass:file,service }}TestStub: {{ .|serviceclass:file,service
|
|
|
defer { {{ method|methodDescriptorName|lowercase }}Responses.removeFirst() }
|
|
|
return {{ method|methodDescriptorName|lowercase }}Responses.first!
|
|
|
}
|
|
|
- func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }},
|
|
|
- completion: @escaping ({{ method|output }}?, CallResult)->()) throws -> {{ .|call:file,service,method }} {
|
|
|
+ func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: @escaping ({{ method|output }}?, CallResult) -> Void) throws -> {{ .|call:file,service,method }} {
|
|
|
fatalError("not implemented")
|
|
|
}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsServerStreaming %}
|
|
|
var {{ method|methodDescriptorName|lowercase }}Requests: [{{ method|input }}] = []
|
|
|
var {{ method|methodDescriptorName|lowercase }}Calls: [{{ .|call:file,service,method }}] = []
|
|
|
- func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: ((CallResult)->())?)
|
|
|
- throws -> {{ .|call:file,service,method }} {
|
|
|
+ func {{ method|methodDescriptorName|lowercase }}(_ request: {{ method|input }}, completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
|
|
|
{{ method|methodDescriptorName|lowercase }}Requests.append(request)
|
|
|
- defer { {{ method|methodDescriptorName|lowercase }}Calls.removeFirst() }
|
|
|
- return {{ method|methodDescriptorName|lowercase }}Calls.first!
|
|
|
+ defer { {{ method|methodDescriptorName|lowercase }}Calls.removeFirst() }
|
|
|
+ return {{ method|methodDescriptorName|lowercase }}Calls.first!
|
|
|
}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsClientStreaming %}
|
|
|
var {{ method|methodDescriptorName|lowercase }}Calls: [{{ .|call:file,service,method }}] = []
|
|
|
- func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult)->())?)
|
|
|
- throws -> {{ .|call:file,service,method }} {
|
|
|
- defer { {{ method|methodDescriptorName|lowercase }}Calls.removeFirst() }
|
|
|
- return {{ method|methodDescriptorName|lowercase }}Calls.first!
|
|
|
+ func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
|
|
|
+ defer { {{ method|methodDescriptorName|lowercase }}Calls.removeFirst() }
|
|
|
+ return {{ method|methodDescriptorName|lowercase }}Calls.first!
|
|
|
}
|
|
|
//-{% endif %}
|
|
|
//-{% if method|methodIsBidiStreaming %}
|
|
|
var {{ method|methodDescriptorName|lowercase }}Calls: [{{ .|call:file,service,method }}] = []
|
|
|
- func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult)->())?)
|
|
|
- throws -> {{ .|call:file,service,method }} {
|
|
|
- defer { {{ method|methodDescriptorName|lowercase }}Calls.removeFirst() }
|
|
|
- return {{ method|methodDescriptorName|lowercase }}Calls.first!
|
|
|
+ func {{ method|methodDescriptorName|lowercase }}(completion: ((CallResult) -> Void)?) throws -> {{ .|call:file,service,method }} {
|
|
|
+ defer { {{ method|methodDescriptorName|lowercase }}Calls.removeFirst() }
|
|
|
+ return {{ method|methodDescriptorName|lowercase }}Calls.first!
|
|
|
}
|
|
|
//-{% endif %}
|
|
|
|