Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,24 @@ let package = Package(
extension Array where Element == Package.Dependency {
static var dependencies: [Package.Dependency] {
#if os(Windows)
[]
[]
#else
// Test only Dependency
[.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.4.1")]
// Test only Dependency
[.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.4.1")]
#endif
}
}

extension Array where Element == PackageDescription.Target.Dependency {
static var dependencies: [PackageDescription.Target.Dependency] {
#if os(Windows)
["FlatBuffers"]
["FlatBuffers"]
#else
// Test only Dependency
[
.product(name: "GRPC", package: "grpc-swift"),
"FlatBuffers",
]
// Test only Dependency
[
.product(name: "GRPC", package: "grpc-swift"),
"FlatBuffers",
]
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ let benchmarks = {

Benchmark(
"Allocating ByteBuffer 1GB",
configuration: singleConfiguration
) { benchmark in
configuration: singleConfiguration)
{ benchmark in
let memory = UnsafeMutableRawPointer.allocate(
byteCount: 1_024_000_000,
alignment: 1)
Expand Down Expand Up @@ -165,8 +165,8 @@ let benchmarks = {

Benchmark(
"FlatBufferBuilder Add",
configuration: kiloConfiguration
) { benchmark in
configuration: kiloConfiguration)
{ benchmark in
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
Expand All @@ -182,8 +182,8 @@ let benchmarks = {

Benchmark(
"FlatBufferBuilder Start table",
configuration: kiloConfiguration
) { benchmark in
configuration: kiloConfiguration)
{ benchmark in
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/swift/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import PackageDescription
let package = Package(
name: "benchmarks",
platforms: [
.macOS(.v13)
.macOS(.v13),
],
dependencies: [
.package(path: "../.."),
Expand All @@ -37,6 +37,6 @@ let package = Package(
],
path: "Benchmarks/FlatbuffersBenchmarks",
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
])
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
]),
])
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Common

import FlatBuffers

public struct models_HelloReply: FlatBufferObject, Verifiable {
public struct models_HelloReply: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {

static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
Expand Down Expand Up @@ -55,7 +55,7 @@ extension models_HelloReply: Encodable {
}
}

public struct models_HelloRequest: FlatBufferObject, Verifiable {
public struct models_HelloRequest: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {

static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
Expand Down
2 changes: 1 addition & 1 deletion grpc/examples/swift/Greeter/Sources/client/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func greet(name: String, client greeter: models_GreeterServiceClient) {
// Make the RPC call to the server.
let sayHello =
greeter
.SayHello(Message<models_HelloRequest>(builder: &builder))
.SayHello(Message<models_HelloRequest>(builder: &builder))

// wait() on the response to stop the program from exiting before the response is received.
do {
Expand Down
8 changes: 3 additions & 5 deletions grpc/examples/swift/Greeter/Sources/server/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class Greeter: models_GreeterProvider {

func SayHello(
request: Message<models_HelloRequest>,
context: StatusOnlyCallContext
)
context: StatusOnlyCallContext)
-> EventLoopFuture<Message<models_HelloReply>>
{
let recipient = request.object.name ?? "Stranger"
Expand All @@ -48,15 +47,14 @@ class Greeter: models_GreeterProvider {

func SayManyHellos(
request: Message<models_HelloRequest>,
context: StreamingResponseCallContext<Message<models_HelloReply>>
)
context: StreamingResponseCallContext<Message<models_HelloReply>>)
-> EventLoopFuture<GRPCStatus>
{
for name in greetings {
var builder = FlatBufferBuilder()
let off =
builder
.create(string: "\(name) \(request.object.name ?? "Unknown")")
.create(string: "\(name) \(request.object.name ?? "Unknown")")
let root = models_HelloReply.createHelloReply(
&builder,
messageOffset: off)
Expand Down
71 changes: 22 additions & 49 deletions samples/monster_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Common

import FlatBuffers

public enum MyGame_Sample_Color: Int8, Enum, Verifiable {
public enum MyGame_Sample_Color: Int8, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue }
Expand All @@ -31,7 +31,7 @@ extension MyGame_Sample_Color: Encodable {
}
}

public enum MyGame_Sample_Equipment: UInt8, UnionEnum {
public enum MyGame_Sample_Equipment: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8

public init?(value: T) {
Expand Down Expand Up @@ -73,7 +73,7 @@ public struct MyGame_Sample_EquipmentUnion {
}
}
}
public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Sample_Vec3: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {

static func validateVersion() { FlatBuffersVersion_25_9_23() }

Expand Down Expand Up @@ -136,7 +136,7 @@ extension MyGame_Sample_Vec3: Encodable {
}
}

public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
public struct MyGame_Sample_Vec3_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {

static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
Expand Down Expand Up @@ -165,7 +165,7 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
}
}

public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Sample_Monster: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {

static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
Expand Down Expand Up @@ -197,24 +197,17 @@ public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable, ObjectAPIPack
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
public var hasInventory: Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? false : true }
public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func inventory(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
public var inventory: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.inventory.v, byteSize: 1) }
public func mutate(inventory: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return _accessor.directMutate(inventory, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
public func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
public var color: MyGame_Sample_Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : MyGame_Sample_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? .blue }
@discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
public var hasWeapons: Bool { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? false : true }
public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func weapons(at index: Int32) -> MyGame_Sample_Weapon? { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? nil : MyGame_Sample_Weapon(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public var weapons: FlatbufferVector<MyGame_Sample_Weapon> { return _accessor.vector(at: VTOFFSET.weapons.v, byteSize: 4) }
public var equippedType: MyGame_Sample_Equipment { let o = _accessor.offset(VTOFFSET.equippedType.v); return o == 0 ? .none_ : MyGame_Sample_Equipment(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
public var hasPath: Bool { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? false : true }
public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func path(at index: Int32) -> MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Sample_Vec3.self, offset: _accessor.vector(at: o) + index * 12) }
public func mutablePath(at index: Int32) -> MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 12) }
public func withUnsafePointerToPath<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.path.v, body: body) }
public var path: FlatbufferVector<MyGame_Sample_Vec3> { return _accessor.vector(at: VTOFFSET.path.v, byteSize: 12) }
public var mutablePath: FlatbufferVector<MyGame_Sample_Vec3_Mutable> { return _accessor.vector(at: VTOFFSET.path.v, byteSize: 12) }
public func withUnsafePointerToPath<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.path.v, body: body) }
public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 11) }
public static func add(pos: MyGame_Sample_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p) }
Expand Down Expand Up @@ -282,9 +275,8 @@ public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable, ObjectAPIPack
let __weapons = builder.createVector(ofOffsets: __weapons__)
let __equipped = obj.equipped?.pack(builder: &builder) ?? Offset()
MyGame_Sample_Monster.startVectorOfPath(obj.path.count, in: &builder)
for i in obj.path {
guard let _o = i else { continue }
builder.create(struct: _o)
for val in obj.path {
builder.create(struct: val)
}
let __path = builder.endVector(len: obj.path.count)
let __root = MyGame_Sample_Monster.startMonster(&builder)
Expand Down Expand Up @@ -350,19 +342,11 @@ extension MyGame_Sample_Monster: Encodable {
try container.encodeIfPresent(hp, forKey: .hp)
}
try container.encodeIfPresent(name, forKey: .name)
if inventoryCount > 0 {
try container.encodeIfPresent(inventory, forKey: .inventory)
}
try container.encodeIfPresent(inventory, forKey: .inventory)
if color != .blue {
try container.encodeIfPresent(color, forKey: .color)
}
if weaponsCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .weapons)
for index in 0..<weaponsCount {
guard let type = weapons(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(weapons, forKey: .weapons)
if equippedType != .none_ {
try container.encodeIfPresent(equippedType, forKey: .equippedType)
}
Expand All @@ -372,13 +356,7 @@ extension MyGame_Sample_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .equipped)
default: break;
}
if pathCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .path)
for index in 0..<pathCount {
guard let type = path(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(path, forKey: .path)
}
}

Expand All @@ -392,22 +370,19 @@ public class MyGame_Sample_MonsterT: NativeObject {
public var color: MyGame_Sample_Color
public var weapons: [MyGame_Sample_WeaponT?]
public var equipped: MyGame_Sample_EquipmentUnion?
public var path: [MyGame_Sample_Vec3?]
public var path: [MyGame_Sample_Vec3]

public init(_ _t: inout MyGame_Sample_Monster) {
pos = _t.pos
mana = _t.mana
hp = _t.hp
name = _t.name
inventory = []
for index in 0..<_t.inventoryCount {
inventory.append(_t.inventory(at: index))
}
inventory.append(contentsOf: _t.inventory)
color = _t.color
weapons = []
for index in 0..<_t.weaponsCount {
var __v_ = _t.weapons(at: index)
weapons.append(__v_?.unpack())
for var val in _t.weapons{
weapons.append(val.unpack())
}
switch _t.equippedType {
case .weapon:
Expand All @@ -416,9 +391,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
default: break
}
path = []
for index in 0..<_t.pathCount {
path.append(_t.path(at: index))
}
path.append(contentsOf: _t.path)
}

public init() {
Expand All @@ -434,7 +407,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Sample_Monster.self) }

}
public struct MyGame_Sample_Weapon: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Sample_Weapon: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {

static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
Expand Down
Loading
Loading