mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Moves VTs from enums to structs to prevent empty enum generation, which would usually cause a compilation error.
253 lines
9.1 KiB
Swift
253 lines
9.1 KiB
Swift
// automatically generated by the FlatBuffers compiler, do not modify
|
|
// swiftlint:disable all
|
|
// swiftformat:disable all
|
|
|
|
public struct BytesCount: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
|
|
|
|
static func validateVersion() { FlatBuffersVersion_25_12_19() }
|
|
|
|
private var _x: Int64
|
|
|
|
public init(_ bb: ByteBuffer, o: Int32) {
|
|
self = bb.read(def: Self.self, position: Int(o))
|
|
}
|
|
|
|
public init(x: Int64) {
|
|
_x = x
|
|
}
|
|
|
|
public init() {
|
|
_x = 0
|
|
}
|
|
|
|
public init(_ _t: borrowing BytesCount_Mutable) {
|
|
_x = _t.x
|
|
}
|
|
|
|
public var x: Int64 { _x }
|
|
|
|
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
|
try verifier.inBuffer(position: position, of: BytesCount.self)
|
|
}
|
|
}
|
|
|
|
extension BytesCount: Encodable {
|
|
enum CodingKeys: String, CodingKey {
|
|
case x = "x"
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
if x != 0 {
|
|
try container.encodeIfPresent(x, forKey: .x)
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct BytesCount_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
|
|
|
|
static func validateVersion() { FlatBuffersVersion_25_12_19() }
|
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
|
private var _accessor: Struct
|
|
|
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) }
|
|
|
|
public var x: Int64 { return _accessor.readBuffer(of: Int64.self, at: 0) }
|
|
@discardableResult public func mutate(x: Int64) -> Bool { return _accessor.mutate(x, index: 0) }
|
|
|
|
public func unpack() -> BytesCount {
|
|
return BytesCount(self)
|
|
}
|
|
public static func pack(_ builder: inout FlatBufferBuilder, obj: inout BytesCount?) -> Offset {
|
|
guard var obj = obj else { return Offset() }
|
|
return pack(&builder, obj: &obj)
|
|
}
|
|
|
|
public static func pack(_ builder: inout FlatBufferBuilder, obj: inout BytesCount) -> Offset {
|
|
return builder.create(struct: obj)
|
|
}
|
|
}
|
|
|
|
public struct InternalMessage: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
|
|
|
|
static func validateVersion() { FlatBuffersVersion_25_12_19() }
|
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
|
private var _accessor: Table
|
|
|
|
private init(_ t: Table) { _accessor = t }
|
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
|
|
|
private struct VT {
|
|
static let str: VOffset = 4
|
|
}
|
|
|
|
public var str: String? { let o = _accessor.offset(VT.str); return o == 0 ? nil : _accessor.string(at: o) }
|
|
public var strSegmentArray: [UInt8]? { return _accessor.getVector(at: VT.str) }
|
|
public static func startInternalMessage(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
|
|
public static func add(str: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: str, at: VT.str) }
|
|
public static func endInternalMessage(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
|
|
public static func createInternalMessage(
|
|
_ fbb: inout FlatBufferBuilder,
|
|
strOffset str: Offset = Offset()
|
|
) -> Offset {
|
|
let __start = InternalMessage.startInternalMessage(&fbb)
|
|
InternalMessage.add(str: str, &fbb)
|
|
return InternalMessage.endInternalMessage(&fbb, start: __start)
|
|
}
|
|
|
|
public func unpack() -> InternalMessageT {
|
|
return InternalMessageT(self)
|
|
}
|
|
public static func pack(_ builder: inout FlatBufferBuilder, obj: inout InternalMessageT?) -> Offset {
|
|
guard var obj = obj else { return Offset() }
|
|
return pack(&builder, obj: &obj)
|
|
}
|
|
|
|
public static func pack(_ builder: inout FlatBufferBuilder, obj: inout InternalMessageT) -> Offset {
|
|
let __str: Offset
|
|
if let s = obj.str {
|
|
__str = builder.create(string: s)
|
|
} else {
|
|
__str = Offset()
|
|
}
|
|
|
|
let __root = InternalMessage.startInternalMessage(&builder)
|
|
InternalMessage.add(str: __str, &builder)
|
|
return InternalMessage.endInternalMessage(&builder, start: __root)
|
|
}
|
|
|
|
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
|
var _v = try verifier.visitTable(at: position)
|
|
try _v.visit(field: VT.str, fieldName: "str", required: false, type: ForwardOffset<String>.self)
|
|
_v.finish()
|
|
}
|
|
}
|
|
|
|
extension InternalMessage: Encodable {
|
|
enum CodingKeys: String, CodingKey {
|
|
case str = "str"
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encodeIfPresent(str, forKey: .str)
|
|
}
|
|
}
|
|
|
|
public class InternalMessageT: NativeObject {
|
|
|
|
public var str: String?
|
|
|
|
public init(_ _t: borrowing InternalMessage) {
|
|
str = _t.str
|
|
}
|
|
|
|
public init() {
|
|
}
|
|
|
|
public func serialize() -> ByteBuffer { return serialize(type: InternalMessage.self) }
|
|
|
|
}
|
|
public struct Message: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
|
|
|
|
static func validateVersion() { FlatBuffersVersion_25_12_19() }
|
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
|
private var _accessor: Table
|
|
|
|
private init(_ t: Table) { _accessor = t }
|
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
|
|
|
private struct VT {
|
|
static let id: VOffset = 4
|
|
static let position: VOffset = 6
|
|
static let pointer: VOffset = 8
|
|
}
|
|
|
|
public var id: Int64 { let o = _accessor.offset(VT.id); return o == 0 ? 0 : _accessor.readBuffer(of: Int64.self, at: o) }
|
|
@discardableResult public func mutate(id: Int64) -> Bool {let o = _accessor.offset(VT.id); return _accessor.mutate(id, index: o) }
|
|
public var position: BytesCount! { let o = _accessor.offset(VT.position); return _accessor.readBuffer(of: BytesCount.self, at: o) }
|
|
public var mutablePosition: BytesCount_Mutable! { let o = _accessor.offset(VT.position); return BytesCount_Mutable(_accessor.bb, o: o + _accessor.position) }
|
|
public var pointer: InternalMessage! { let o = _accessor.offset(VT.pointer); return InternalMessage(_accessor.bb, o: _accessor.indirect(o + _accessor.position)) }
|
|
public static func startMessage(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 3) }
|
|
public static func add(id: Int64, _ fbb: inout FlatBufferBuilder) { fbb.add(element: id, def: 0, at: VT.id) }
|
|
public static func add(position: BytesCount?, _ fbb: inout FlatBufferBuilder) { guard let position = position else { return }; fbb.create(struct: position, position: VT.position) }
|
|
public static func add(pointer: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: pointer, at: VT.pointer) }
|
|
public static func endMessage(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); fbb.require(table: end, fields: [6, 8]); return end }
|
|
public static func createMessage(
|
|
_ fbb: inout FlatBufferBuilder,
|
|
id: Int64 = 0,
|
|
position: BytesCount,
|
|
pointerOffset pointer: Offset
|
|
) -> Offset {
|
|
let __start = Message.startMessage(&fbb)
|
|
Message.add(id: id, &fbb)
|
|
Message.add(position: position, &fbb)
|
|
Message.add(pointer: pointer, &fbb)
|
|
return Message.endMessage(&fbb, start: __start)
|
|
}
|
|
|
|
public func unpack() -> MessageT {
|
|
return MessageT(self)
|
|
}
|
|
public static func pack(_ builder: inout FlatBufferBuilder, obj: inout MessageT?) -> Offset {
|
|
guard var obj = obj else { return Offset() }
|
|
return pack(&builder, obj: &obj)
|
|
}
|
|
|
|
public static func pack(_ builder: inout FlatBufferBuilder, obj: inout MessageT) -> Offset {
|
|
let __pointer = InternalMessage.pack(&builder, obj: &obj.pointer)
|
|
let __root = Message.startMessage(&builder)
|
|
Message.add(id: obj.id, &builder)
|
|
Message.add(position: obj.position, &builder)
|
|
Message.add(pointer: __pointer, &builder)
|
|
return Message.endMessage(&builder, start: __root)
|
|
}
|
|
|
|
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
|
var _v = try verifier.visitTable(at: position)
|
|
try _v.visit(field: VT.id, fieldName: "id", required: false, type: Int64.self)
|
|
try _v.visit(field: VT.position, fieldName: "position", required: true, type: BytesCount.self)
|
|
try _v.visit(field: VT.pointer, fieldName: "pointer", required: true, type: ForwardOffset<InternalMessage>.self)
|
|
_v.finish()
|
|
}
|
|
}
|
|
|
|
extension Message: Encodable {
|
|
enum CodingKeys: String, CodingKey {
|
|
case id = "id"
|
|
case position = "position"
|
|
case pointer = "pointer"
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
if id != 0 {
|
|
try container.encodeIfPresent(id, forKey: .id)
|
|
}
|
|
try container.encodeIfPresent(position, forKey: .position)
|
|
try container.encodeIfPresent(pointer, forKey: .pointer)
|
|
}
|
|
}
|
|
|
|
public class MessageT: NativeObject {
|
|
|
|
public var id: Int64
|
|
public var position: BytesCount
|
|
public var pointer: InternalMessageT
|
|
|
|
public init(_ _t: borrowing Message) {
|
|
id = _t.id
|
|
position = _t.position
|
|
pointer = _t.pointer!.unpack()
|
|
}
|
|
|
|
public init() {
|
|
id = 0
|
|
position = BytesCount()
|
|
pointer = InternalMessageT()
|
|
}
|
|
|
|
public func serialize() -> ByteBuffer { return serialize(type: Message.self) }
|
|
|
|
}
|