mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 14:53:56 +00:00
@@ -108,13 +108,13 @@ void GenerateClientClass(const grpc_generator::Service *service,
|
|||||||
printer->Print(vars,
|
printer->Print(vars,
|
||||||
"$ACCESS$ final class $ServiceName$ServiceClient: GRPCClient, "
|
"$ACCESS$ final class $ServiceName$ServiceClient: GRPCClient, "
|
||||||
"$ServiceName$Service {\n");
|
"$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(vars, "\t$ACCESS$ var defaultCallOptions: CallOptions\n");
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
printer->Print(vars,
|
printer->Print(vars,
|
||||||
"\t$ACCESS$ init(connection: ClientConnection, "
|
"\t$ACCESS$ init(channel: GRPCChannel, "
|
||||||
"defaultCallOptions: CallOptions = CallOptions()) {\n");
|
"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\tself.defaultCallOptions = defaultCallOptions\n");
|
||||||
printer->Print("\t}");
|
printer->Print("\t}");
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'FlatBuffers'
|
s.name = 'FlatBuffers'
|
||||||
s.version = '0.2.0'
|
s.version = '0.3.0'
|
||||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||||
|
|
||||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ let package = Package(
|
|||||||
dependencies: [
|
dependencies: [
|
||||||
// Main SwiftNIO package
|
// Main SwiftNIO package
|
||||||
.package(path: "../../swift"),
|
.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: [
|
||||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
// 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 final class GreeterServiceClient: GRPCClient, GreeterService {
|
||||||
public let connection: ClientConnection
|
public let channel: GRPCChannel
|
||||||
public var defaultCallOptions: CallOptions
|
public var defaultCallOptions: CallOptions
|
||||||
|
|
||||||
public init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) {
|
public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
|
||||||
self.connection = connection
|
self.channel = channel
|
||||||
self.defaultCallOptions = defaultCallOptions
|
self.defaultCallOptions = defaultCallOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func greet(name: String, client greeter: GreeterServiceClient) {
|
|||||||
// Form the request with the name, if one was provided.
|
// Form the request with the name, if one was provided.
|
||||||
var builder = FlatBufferBuilder()
|
var builder = FlatBufferBuilder()
|
||||||
let name = builder.create(string: name)
|
let name = builder.create(string: name)
|
||||||
let root = HelloRequest.createHelloRequest(builder, offsetOfName: name)
|
let root = HelloRequest.createHelloRequest(&builder, offsetOfName: name)
|
||||||
builder.finish(offset: root)
|
builder.finish(offset: root)
|
||||||
|
|
||||||
// Make the RPC call to the server.
|
// 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 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)
|
builder.finish(offset: manyRoot)
|
||||||
|
|
||||||
let call = greeter.SayManyHellos(Message(builder: &builder)) { message in
|
let call = greeter.SayManyHellos(Message(builder: &builder)) { message in
|
||||||
@@ -80,21 +80,15 @@ func main(args: [String]) {
|
|||||||
try! group.syncShutdownGracefully()
|
try! group.syncShutdownGracefully()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide some basic configuration for the connection, in this case we connect to an endpoint on
|
// Configure the channel, we're not using TLS so the connection is `insecure`.
|
||||||
// localhost at the given port.
|
let channel = ClientConnection.insecure(group: group)
|
||||||
let configuration = ClientConnection.Configuration(
|
.connect(host: "localhost", port: port)
|
||||||
target: .hostAndPort("localhost", port),
|
|
||||||
eventLoopGroup: group
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create a connection using the configuration.
|
|
||||||
let connection = ClientConnection(configuration: configuration)
|
|
||||||
|
|
||||||
// Provide the connection to the generated client.
|
// Provide the connection to the generated client.
|
||||||
let greeter = GreeterServiceClient(connection: connection)
|
let greeter = GreeterServiceClient(channel: channel)
|
||||||
|
|
||||||
// Do the greeting.
|
// 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 {
|
for name in names {
|
||||||
var builder = FlatBufferBuilder()
|
var builder = FlatBufferBuilder()
|
||||||
let off = builder.create(string: name)
|
let off = builder.create(string: name)
|
||||||
let root = HelloReply.createHelloReply(builder, offsetOfMessage: off)
|
let root = HelloReply.createHelloReply(&builder, offsetOfMessage: off)
|
||||||
builder.finish(offset: root)
|
builder.finish(offset: root)
|
||||||
hellos.append(Message(builder: &builder))
|
hellos.append(Message(builder: &builder))
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ class Greeter: GreeterProvider {
|
|||||||
|
|
||||||
var builder = FlatBufferBuilder()
|
var builder = FlatBufferBuilder()
|
||||||
let off = builder.create(string: recipient)
|
let off = builder.create(string: recipient)
|
||||||
let root = HelloReply.createHelloReply(builder, offsetOfMessage: off)
|
let root = HelloReply.createHelloReply(&builder, offsetOfMessage: off)
|
||||||
builder.finish(offset: root)
|
builder.finish(offset: root)
|
||||||
return context.eventLoop.makeSucceededFuture(Message<HelloReply>(builder: &builder))
|
return context.eventLoop.makeSucceededFuture(Message<HelloReply>(builder: &builder))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ public protocol MonsterStorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class MonsterStorageServiceClient: GRPCClient, MonsterStorageService {
|
public final class MonsterStorageServiceClient: GRPCClient, MonsterStorageService {
|
||||||
public let connection: ClientConnection
|
public let channel: GRPCChannel
|
||||||
public var defaultCallOptions: CallOptions
|
public var defaultCallOptions: CallOptions
|
||||||
|
|
||||||
public init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) {
|
public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
|
||||||
self.connection = connection
|
self.channel = channel
|
||||||
self.defaultCallOptions = defaultCallOptions
|
self.defaultCallOptions = defaultCallOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user