mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-22 01:28:27 +00:00
Dart object API (#6682)
* dart test scripts - generate with `--gen-object-api` * Dart object API, pack and unpack methods (WIP) * Dart flatc - extract Builder code to separate functions to reuse it in Pack() * Dart flatc - use builder field-building implementation in pack() * Dart flatc - add pack() as an intance method of the "T" class * Dart object API - make inner fields unpacked as well * Dart object API - use pack() when collecting field offsets * Dart object API - use packOnce() for fields that are structs or vectors of structs * Dart object API - remove obsolete union support TODO * Dart object API - minor review changes, test and fixes * Dart object API - revert packOnce() - not supported by other object API implementations * Dart object API - update docs * update dart generated code in tests/ to fix CI failure on ./scripts/check-generated-code.sh * Dart flatc - fix compilation for old MSVC and c++0x
This commit is contained in:
@@ -35,6 +35,58 @@ class TableInFirstNS {
|
||||
String toString() {
|
||||
return 'TableInFirstNS{fooTable: $fooTable, fooEnum: $fooEnum, fooUnionType: $fooUnionType, fooUnion: $fooUnion, fooStruct: $fooStruct}';
|
||||
}
|
||||
|
||||
TableInFirstNST unpack() => TableInFirstNST(
|
||||
fooTable: fooTable?.unpack(),
|
||||
fooEnum: fooEnum,
|
||||
fooUnionType: fooUnionType,
|
||||
fooUnion: fooUnion,
|
||||
fooStruct: fooStruct?.unpack());
|
||||
|
||||
static int pack(fb.Builder fbBuilder, TableInFirstNST object) {
|
||||
if (object == null) return 0;
|
||||
return object.pack(fbBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
class TableInFirstNST {
|
||||
namespace_a_namespace_b.TableInNestedNST fooTable;
|
||||
EnumInNestedNS fooEnum;
|
||||
UnionInNestedNSTypeId fooUnionType;
|
||||
dynamic fooUnion;
|
||||
namespace_a_namespace_b.StructInNestedNST fooStruct;
|
||||
|
||||
TableInFirstNST({
|
||||
this.fooTable,
|
||||
this.fooEnum,
|
||||
this.fooUnionType,
|
||||
this.fooUnion,
|
||||
this.fooStruct});
|
||||
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
assert(fbBuilder != null);
|
||||
final int fooTableOffset = fooTable?.pack(fbBuilder);
|
||||
final int fooUnionOffset = fooUnion?.pack(fbBuilder);
|
||||
|
||||
fbBuilder.startTable();
|
||||
if (fooTableOffset != null) {
|
||||
fbBuilder.addOffset(0, fooTableOffset);
|
||||
}
|
||||
fbBuilder.addInt8(1, fooEnum?.value);
|
||||
fbBuilder.addUint8(2, fooUnionType?.value);
|
||||
if (fooUnionOffset != null) {
|
||||
fbBuilder.addOffset(3, fooUnionOffset);
|
||||
}
|
||||
if (fooStruct != null) {
|
||||
fbBuilder.addStruct(4, fooStruct.pack(fbBuilder));
|
||||
}
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TableInFirstNST{fooTable: $fooTable, fooEnum: $fooEnum, fooUnionType: $fooUnionType, fooUnion: $fooUnion, fooStruct: $fooStruct}';
|
||||
}
|
||||
}
|
||||
|
||||
class _TableInFirstNSReader extends fb.TableReader<TableInFirstNS> {
|
||||
@@ -151,6 +203,37 @@ class SecondTableInA {
|
||||
String toString() {
|
||||
return 'SecondTableInA{referToC: $referToC}';
|
||||
}
|
||||
|
||||
SecondTableInAT unpack() => SecondTableInAT(
|
||||
referToC: referToC?.unpack());
|
||||
|
||||
static int pack(fb.Builder fbBuilder, SecondTableInAT object) {
|
||||
if (object == null) return 0;
|
||||
return object.pack(fbBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
class SecondTableInAT {
|
||||
namespace_c.TableInCT referToC;
|
||||
|
||||
SecondTableInAT({
|
||||
this.referToC});
|
||||
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
assert(fbBuilder != null);
|
||||
final int referToCOffset = referToC?.pack(fbBuilder);
|
||||
|
||||
fbBuilder.startTable();
|
||||
if (referToCOffset != null) {
|
||||
fbBuilder.addOffset(0, referToCOffset);
|
||||
}
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SecondTableInAT{referToC: $referToC}';
|
||||
}
|
||||
}
|
||||
|
||||
class _SecondTableInAReader extends fb.TableReader<SecondTableInA> {
|
||||
|
||||
Reference in New Issue
Block a user