mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 15:15:46 +00:00
[Swift] Optional Scalars Preparation (#6028)
* Perpares swift to take optional scalars + adds optional string helper method + disables linters in generated code * Small fix for generated code * Update grpc support to alpha 17 for swift
This commit is contained in:
@@ -11,7 +11,7 @@ let package = Package(
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../../swift/"),
|
||||
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0-alpha.12")
|
||||
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0-alpha.17")
|
||||
],
|
||||
targets: [
|
||||
.target(name: "SwiftFlatBuffers"),
|
||||
|
||||
@@ -59,6 +59,27 @@ final class FlatBuffersTests: XCTestCase {
|
||||
XCTAssertEqual(c.nameVector, [78, 111, 114, 119, 97, 121])
|
||||
XCTAssertEqual(c.name, country)
|
||||
}
|
||||
|
||||
func testWriteOptionalValues() {
|
||||
var b = FlatBufferBuilder()
|
||||
let offset = b.create(string: nil)
|
||||
createOptionalTable(b: &b, v: nil, off: offset)
|
||||
let unitArray = b.sizedByteArray
|
||||
// TODO: - Test function should be adjusted when the generation of optional scalars code is complete
|
||||
let bb = ByteBuffer(bytes: unitArray)
|
||||
let table = Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))
|
||||
XCTAssertEqual(unitArray, [8, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0])
|
||||
XCTAssertEqual(table.offset(4) == 0, true)
|
||||
XCTAssertEqual(table.offset(6) == 0, true)
|
||||
}
|
||||
|
||||
func createOptionalTable(b: inout FlatBufferBuilder, v: Int?, off: Offset<String>) {
|
||||
let start = b.startTable(with: 2)
|
||||
b.add(offset: off, at: 6)
|
||||
b.add(element: v, at: 4)
|
||||
let root = Offset<UOffset>(offset: b.endTable(at: start))
|
||||
b.finish(offset: root)
|
||||
}
|
||||
}
|
||||
|
||||
class Country {
|
||||
|
||||
@@ -65,23 +65,23 @@ public extension MonsterStorageProvider {
|
||||
func handleMethod(_ methodName: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
|
||||
switch methodName {
|
||||
case "Store":
|
||||
return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in
|
||||
return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in
|
||||
return { request in
|
||||
self.Store(request, context: context)
|
||||
}
|
||||
}
|
||||
case "Retrieve":
|
||||
return ServerStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
|
||||
return CallHandlerFactory.makeServerStreaming(callHandlerContext: callHandlerContext) { context in
|
||||
return { request in
|
||||
self.Retrieve(request: request, context: context)
|
||||
}
|
||||
}
|
||||
case "GetMaxHitPoint":
|
||||
return ClientStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
|
||||
return CallHandlerFactory.makeClientStreaming(callHandlerContext: callHandlerContext) { context in
|
||||
self.GetMaxHitPoint(context: context)
|
||||
}
|
||||
case "GetMinMaxHitPoints":
|
||||
return BidirectionalStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
|
||||
return CallHandlerFactory.makeBidirectionalStreaming(callHandlerContext: callHandlerContext) { context in
|
||||
self.GetMinMaxHitPoints(context: context)
|
||||
}
|
||||
default: return nil;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// swiftlint:disable all
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// swiftlint:disable all
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user