Squashed 'third_party/flatbuffers/' changes from d6a8dbd26..338393f85
338393f85 Documentation updates for Optional Scalars (#6014) (#6270)
c27bc2d76 [C++] Add ParseJson(), Parser(Parser&&), update fuzzers (#6284)
bc518a512 Fixed FlexBufferBuilder asserting on duplicate keys
100c59054 Added a few more paths for auto labeler (#6281)
e58c18244 Add --require-explicit-ids to require explicit ids (#6277)
69a8b2a57 idl_gen_json_schema.cpp: Changed generation of array element types (#6253)
25eba6f35 fix typo (#6280)
e1f0f75ba Updated Ms build Action to fix build issue (#6279)
faeb04fbe Add type annotation to unspecified array (#6264)
537212afe [Swift] Adds a format file and reformats the swift project (#6250)
6764f25d9 Adds a fix for enum generation (#6263)
Change-Id: I716bd4d2521fb0a673e50a699cef761e042052b2
git-subtree-dir: third_party/flatbuffers
git-subtree-split: 338393f854eb5ba24761a22cd9316ff5cee4eab0
diff --git a/tests/FlatBuffers.GRPC.Swift/Sources/client/main.swift b/tests/FlatBuffers.GRPC.Swift/Sources/client/main.swift
index 74729e7..db3206c 100644
--- a/tests/FlatBuffers.GRPC.Swift/Sources/client/main.swift
+++ b/tests/FlatBuffers.GRPC.Swift/Sources/client/main.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2020, gRPC Authors All rights reserved.
+ * Copyright 2020 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,88 +14,91 @@
* limitations under the License.
*/
+import FlatBuffers
import GRPC
+import Logging
import Model
import NIO
-import Logging
-import FlatBuffers
// Quieten the logs.
LoggingSystem.bootstrap {
- var handler = StreamLogHandler.standardOutput(label: $0)
- handler.logLevel = .critical
- return handler
+ var handler = StreamLogHandler.standardOutput(label: $0)
+ handler.logLevel = .critical
+ return handler
}
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)
- builder.finish(offset: root)
-
- // Make the RPC call to the server.
- let sayHello = greeter.SayHello(Message<HelloRequest>(builder: &builder))
+ // 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)
+ builder.finish(offset: root)
- // wait() on the response to stop the program from exiting before the response is received.
- do {
- let response = try sayHello.response.wait()
- print("Greeter received: \(response.object.message)")
- } catch {
- print("Greeter failed: \(error)")
- }
+ // Make the RPC call to the server.
+ let sayHello = greeter.SayHello(Message<HelloRequest>(builder: &builder))
- let surname = builder.create(string: "Name")
- let manyRoot = ManyHellosRequest.createManyHellosRequest(&builder, offsetOfName: surname, numGreetings: 2)
- builder.finish(offset: manyRoot)
+ // wait() on the response to stop the program from exiting before the response is received.
+ do {
+ let response = try sayHello.response.wait()
+ print("Greeter received: \(response.object.message)")
+ } catch {
+ print("Greeter failed: \(error)")
+ }
- let call = greeter.SayManyHellos(Message(builder: &builder)) { message in
- print(message.object.message)
- }
+ let surname = builder.create(string: "Name")
+ let manyRoot = ManyHellosRequest.createManyHellosRequest(
+ &builder,
+ offsetOfName: surname,
+ numGreetings: 2)
+ builder.finish(offset: manyRoot)
- let status = try! call.status.recover { _ in .processingError }.wait()
- if status.code != .ok {
- print("RPC failed: \(status)")
- }
+ let call = greeter.SayManyHellos(Message(builder: &builder)) { message in
+ print(message.object.message)
+ }
+
+ let status = try! call.status.recover { _ in .processingError }.wait()
+ if status.code != .ok {
+ print("RPC failed: \(status)")
+ }
}
func main(args: [String]) {
- // arg0 (dropped) is the program name. We expect arg1 to be the port, and arg2 (optional) to be
- // the name sent in the request.
- let arg1 = args.dropFirst(1).first
- let arg2 = args.dropFirst(2).first
-
- switch (arg1.flatMap(Int.init), arg2) {
- case (.none, _):
- print("Usage: PORT [NAME]")
- exit(1)
-
- case let (.some(port), name):
- // Setup an `EventLoopGroup` for the connection to run on.
- //
- // See: https://github.com/apple/swift-nio#eventloops-and-eventloopgroups
- let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
-
- // Make sure the group is shutdown when we're done with it.
- defer {
- try! group.syncShutdownGracefully()
- }
-
- // Configure the channel, we're not using TLS so the connection is `insecure`.
- let channel = ClientConnection.insecure(group: group)
- .connect(host: "localhost", port: port)
+ // arg0 (dropped) is the program name. We expect arg1 to be the port, and arg2 (optional) to be
+ // the name sent in the request.
+ let arg1 = args.dropFirst(1).first
+ let arg2 = args.dropFirst(2).first
- // Close the connection when we're done with it.
- defer {
- try! channel.close().wait()
- }
+ switch (arg1.flatMap(Int.init), arg2) {
+ case (.none, _):
+ print("Usage: PORT [NAME]")
+ exit(1)
- // Provide the connection to the generated client.
- let greeter = GreeterServiceClient(channel: channel)
+ case let (.some(port), name):
+ // Setup an `EventLoopGroup` for the connection to run on.
+ //
+ // See: https://github.com/apple/swift-nio#eventloops-and-eventloopgroups
+ let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
- // Do the greeting.
- greet(name: name ?? "Hello FlatBuffers!", client: greeter)
+ // Make sure the group is shutdown when we're done with it.
+ defer {
+ try! group.syncShutdownGracefully()
}
+
+ // Configure the channel, we're not using TLS so the connection is `insecure`.
+ let channel = ClientConnection.insecure(group: group)
+ .connect(host: "localhost", port: port)
+
+ // Close the connection when we're done with it.
+ defer {
+ try! channel.close().wait()
+ }
+
+ // Provide the connection to the generated client.
+ let greeter = GreeterServiceClient(channel: channel)
+
+ // Do the greeting.
+ greet(name: name ?? "Hello FlatBuffers!", client: greeter)
+ }
}
main(args: CommandLine.arguments)