mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
@@ -108,13 +108,13 @@ void GenerateClientClass(const grpc_generator::Service *service,
|
||||
printer->Print(vars,
|
||||
"$ACCESS$ final class $ServiceName$ServiceClient: GRPCClient, "
|
||||
"$ServiceName$Service {\n");
|
||||
printer->Print(vars, "\t$ACCESS$ let connection: ClientConnection\n");
|
||||
printer->Print(vars, "\t$ACCESS$ let channel: GRPCChannel\n");
|
||||
printer->Print(vars, "\t$ACCESS$ var defaultCallOptions: CallOptions\n");
|
||||
printer->Print("\n");
|
||||
printer->Print(vars,
|
||||
"\t$ACCESS$ init(connection: ClientConnection, "
|
||||
"\t$ACCESS$ init(channel: GRPCChannel, "
|
||||
"defaultCallOptions: CallOptions = CallOptions()) {\n");
|
||||
printer->Print("\t\tself.connection = connection\n");
|
||||
printer->Print("\t\tself.channel = channel\n");
|
||||
printer->Print("\t\tself.defaultCallOptions = defaultCallOptions\n");
|
||||
printer->Print("\t}");
|
||||
printer->Print("\n");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FlatBuffers'
|
||||
s.version = '0.2.0'
|
||||
s.version = '0.3.0'
|
||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||
|
||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||
|
||||
@@ -12,7 +12,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
// Main SwiftNIO package
|
||||
.package(path: "../../swift"),
|
||||
.package(url: "https://github.com/grpc/grpc-swift.git", .branch("nio"))
|
||||
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0-alpha.9")
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
|
||||
@@ -26,11 +26,11 @@ public protocol GreeterService {
|
||||
}
|
||||
|
||||
public final class GreeterServiceClient: GRPCClient, GreeterService {
|
||||
public let connection: ClientConnection
|
||||
public let channel: GRPCChannel
|
||||
public var defaultCallOptions: CallOptions
|
||||
|
||||
public init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) {
|
||||
self.connection = connection
|
||||
public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
|
||||
self.channel = channel
|
||||
self.defaultCallOptions = defaultCallOptions
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class Greeter: GreeterProvider {
|
||||
for name in names {
|
||||
var builder = FlatBufferBuilder()
|
||||
let off = builder.create(string: name)
|
||||
let root = HelloReply.createHelloReply(builder, offsetOfMessage: off)
|
||||
let root = HelloReply.createHelloReply(&builder, offsetOfMessage: off)
|
||||
builder.finish(offset: root)
|
||||
hellos.append(Message(builder: &builder))
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class Greeter: GreeterProvider {
|
||||
|
||||
var builder = FlatBufferBuilder()
|
||||
let off = builder.create(string: recipient)
|
||||
let root = HelloReply.createHelloReply(builder, offsetOfMessage: off)
|
||||
let root = HelloReply.createHelloReply(&builder, offsetOfMessage: off)
|
||||
builder.finish(offset: root)
|
||||
return context.eventLoop.makeSucceededFuture(Message<HelloReply>(builder: &builder))
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ public protocol MonsterStorageService {
|
||||
}
|
||||
|
||||
public final class MonsterStorageServiceClient: GRPCClient, MonsterStorageService {
|
||||
public let connection: ClientConnection
|
||||
public let channel: GRPCChannel
|
||||
public var defaultCallOptions: CallOptions
|
||||
|
||||
public init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) {
|
||||
self.connection = connection
|
||||
public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
|
||||
self.channel = channel
|
||||
self.defaultCallOptions = defaultCallOptions
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user