-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds implementation flag for swift (#7202)
* Adds implementation flag for swift Forces internal flag when using @_implementationOnly in swift Fixes access type for verifier functions & encoder functions Updates generated code * Addresses PR comments & adds a code gen dir within the swift tests * Adds test case for no-include * Fixes code gen script Removes prefix
- Loading branch information
1 parent
1461569
commit 832c618
Showing
10 changed files
with
234 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/FlatBuffers.Test.Swift/CodeGenerationTests/test_import.fbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
table Message { | ||
internal_message: string; | ||
} |
91 changes: 91 additions & 0 deletions
91
tests/FlatBuffers.Test.Swift/CodeGenerationTests/test_import_generated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// automatically generated by the FlatBuffers compiler, do not modify | ||
// swiftlint:disable all | ||
// swiftformat:disable all | ||
|
||
@_implementationOnly import FlatBuffers | ||
|
||
internal struct Message: FlatBufferObject, Verifiable, ObjectAPIPacker { | ||
|
||
static func validateVersion() { FlatBuffersVersion_2_0_0() } | ||
internal var __buffer: ByteBuffer! { return _accessor.bb } | ||
private var _accessor: Table | ||
|
||
internal static func getRootAsMessage(bb: ByteBuffer) -> Message { return Message(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } | ||
|
||
private init(_ t: Table) { _accessor = t } | ||
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } | ||
|
||
private enum VTOFFSET: VOffset { | ||
case internalMessage = 4 | ||
var v: Int32 { Int32(self.rawValue) } | ||
var p: VOffset { self.rawValue } | ||
} | ||
|
||
internal var internalMessage: String? { let o = _accessor.offset(VTOFFSET.internalMessage.v); return o == 0 ? nil : _accessor.string(at: o) } | ||
internal var internalMessageSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.internalMessage.v) } | ||
internal static func startMessage(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } | ||
internal static func add(internalMessage: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: internalMessage, at: VTOFFSET.internalMessage.p) } | ||
internal static func endMessage(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end } | ||
internal static func createMessage( | ||
_ fbb: inout FlatBufferBuilder, | ||
internalMessageOffset internalMessage: Offset = Offset() | ||
) -> Offset { | ||
let __start = Message.startMessage(&fbb) | ||
Message.add(internalMessage: internalMessage, &fbb) | ||
return Message.endMessage(&fbb, start: __start) | ||
} | ||
|
||
|
||
internal mutating func unpack() -> MessageT { | ||
return MessageT(&self) | ||
} | ||
internal static func pack(_ builder: inout FlatBufferBuilder, obj: inout MessageT?) -> Offset { | ||
guard var obj = obj else { return Offset() } | ||
return pack(&builder, obj: &obj) | ||
} | ||
|
||
internal static func pack(_ builder: inout FlatBufferBuilder, obj: inout MessageT) -> Offset { | ||
let __internalMessage: Offset | ||
if let s = obj.internalMessage { | ||
__internalMessage = builder.create(string: s) | ||
} else { | ||
__internalMessage = Offset() | ||
} | ||
|
||
let __root = Message.startMessage(&builder) | ||
Message.add(internalMessage: __internalMessage, &builder) | ||
return Message.endMessage(&builder, start: __root) | ||
} | ||
|
||
internal 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: VTOFFSET.internalMessage.p, fieldName: "internalMessage", required: false, type: ForwardOffset<String>.self) | ||
_v.finish() | ||
} | ||
} | ||
|
||
extension Message: Encodable { | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case internalMessage = "internal_message" | ||
} | ||
internal func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encodeIfPresent(internalMessage, forKey: .internalMessage) | ||
} | ||
} | ||
|
||
internal class MessageT: NativeObject { | ||
|
||
internal var internalMessage: String? | ||
|
||
internal init(_ _t: inout Message) { | ||
internalMessage = _t.internalMessage | ||
} | ||
|
||
internal init() { | ||
} | ||
|
||
internal func serialize() -> ByteBuffer { return serialize(type: Message.self) } | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
tests/FlatBuffers.Test.Swift/CodeGenerationTests/test_no_include.fbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
table Message { | ||
internal_message: string; | ||
} |
89 changes: 89 additions & 0 deletions
89
tests/FlatBuffers.Test.Swift/CodeGenerationTests/test_no_include_generated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// automatically generated by the FlatBuffers compiler, do not modify | ||
// swiftlint:disable all | ||
// swiftformat:disable all | ||
|
||
public struct Message: FlatBufferObject, Verifiable, ObjectAPIPacker { | ||
|
||
static func validateVersion() { FlatBuffersVersion_2_0_0() } | ||
public var __buffer: ByteBuffer! { return _accessor.bb } | ||
private var _accessor: Table | ||
|
||
public static func getRootAsMessage(bb: ByteBuffer) -> Message { return Message(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } | ||
|
||
private init(_ t: Table) { _accessor = t } | ||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } | ||
|
||
private enum VTOFFSET: VOffset { | ||
case internalMessage = 4 | ||
var v: Int32 { Int32(self.rawValue) } | ||
var p: VOffset { self.rawValue } | ||
} | ||
|
||
public var internalMessage: String? { let o = _accessor.offset(VTOFFSET.internalMessage.v); return o == 0 ? nil : _accessor.string(at: o) } | ||
public var internalMessageSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.internalMessage.v) } | ||
public static func startMessage(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } | ||
public static func add(internalMessage: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: internalMessage, at: VTOFFSET.internalMessage.p) } | ||
public static func endMessage(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end } | ||
public static func createMessage( | ||
_ fbb: inout FlatBufferBuilder, | ||
internalMessageOffset internalMessage: Offset = Offset() | ||
) -> Offset { | ||
let __start = Message.startMessage(&fbb) | ||
Message.add(internalMessage: internalMessage, &fbb) | ||
return Message.endMessage(&fbb, start: __start) | ||
} | ||
|
||
|
||
public mutating 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 __internalMessage: Offset | ||
if let s = obj.internalMessage { | ||
__internalMessage = builder.create(string: s) | ||
} else { | ||
__internalMessage = Offset() | ||
} | ||
|
||
let __root = Message.startMessage(&builder) | ||
Message.add(internalMessage: __internalMessage, &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: VTOFFSET.internalMessage.p, fieldName: "internalMessage", required: false, type: ForwardOffset<String>.self) | ||
_v.finish() | ||
} | ||
} | ||
|
||
extension Message: Encodable { | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case internalMessage = "internal_message" | ||
} | ||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encodeIfPresent(internalMessage, forKey: .internalMessage) | ||
} | ||
} | ||
|
||
public class MessageT: NativeObject { | ||
|
||
public var internalMessage: String? | ||
|
||
public init(_ _t: inout Message) { | ||
internalMessage = _t.internalMessage | ||
} | ||
|
||
public init() { | ||
} | ||
|
||
public func serialize() -> ByteBuffer { return serialize(type: Message.self) } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters