Upgraded swift implementation for grpc (#5843)

Updated version number
This commit is contained in:
mustiikhalil
2020-04-06 20:05:56 +03:00
committed by GitHub
parent fb96fadc20
commit 9655e12d6d
7 changed files with 20 additions and 26 deletions

View File

@@ -31,7 +31,7 @@ func greet(name: String, client greeter: GreeterServiceClient) {
// Form the request with the name, if one was provided.
var builder = FlatBufferBuilder()
let name = builder.create(string: name)
let root = HelloRequest.createHelloRequest(builder, offsetOfName: name)
let root = HelloRequest.createHelloRequest(&builder, offsetOfName: name)
builder.finish(offset: root)
// Make the RPC call to the server.
@@ -45,7 +45,7 @@ func greet(name: String, client greeter: GreeterServiceClient) {
}
let surname = builder.create(string: "Name")
let manyRoot = ManyHellosRequest.createManyHellosRequest(builder, offsetOfName: surname, numGreetings: 2)
let manyRoot = ManyHellosRequest.createManyHellosRequest(&builder, offsetOfName: surname, numGreetings: 2)
builder.finish(offset: manyRoot)
let call = greeter.SayManyHellos(Message(builder: &builder)) { message in
@@ -80,21 +80,15 @@ func main(args: [String]) {
try! group.syncShutdownGracefully()
}
// Provide some basic configuration for the connection, in this case we connect to an endpoint on
// localhost at the given port.
let configuration = ClientConnection.Configuration(
target: .hostAndPort("localhost", port),
eventLoopGroup: group
)
// Create a connection using the configuration.
let connection = ClientConnection(configuration: configuration)
// Configure the channel, we're not using TLS so the connection is `insecure`.
let channel = ClientConnection.insecure(group: group)
.connect(host: "localhost", port: port)
// Provide the connection to the generated client.
let greeter = GreeterServiceClient(connection: connection)
let greeter = GreeterServiceClient(channel: channel)
// Do the greeting.
greet(name: "Hello FlatBuffers!", client: greeter)
greet(name: name ?? "Hello FlatBuffers!", client: greeter)
}
}