forked from BigfootDev/flatbuffers
Refactor lazy list unpacking (#8746)
Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
@@ -1332,22 +1332,15 @@ class Monster {
|
|||||||
mana: mana,
|
mana: mana,
|
||||||
hp: hp,
|
hp: hp,
|
||||||
name: name,
|
name: name,
|
||||||
inventory: const fb.Uint8ListReader(
|
inventory: inventory?.toList(),
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 14),
|
|
||||||
color: color,
|
color: color,
|
||||||
testType: testType,
|
testType: testType,
|
||||||
test: test?.unpack(),
|
test: test?.unpack(),
|
||||||
test4: test4?.map((e) => e.unpack()).toList(),
|
test4: test4?.map((e) => e.unpack()).toList(),
|
||||||
testarrayofstring: const fb.ListReader<String>(
|
testarrayofstring: testarrayofstring?.toList(),
|
||||||
fb.StringReader(),
|
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 24),
|
|
||||||
testarrayoftables: testarrayoftables?.map((e) => e.unpack()).toList(),
|
testarrayoftables: testarrayoftables?.map((e) => e.unpack()).toList(),
|
||||||
enemy: enemy?.unpack(),
|
enemy: enemy?.unpack(),
|
||||||
testnestedflatbuffer: const fb.Uint8ListReader(
|
testnestedflatbuffer: testnestedflatbuffer?.toList(),
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 30),
|
|
||||||
testempty: testempty?.unpack(),
|
testempty: testempty?.unpack(),
|
||||||
testbool: testbool,
|
testbool: testbool,
|
||||||
testhashs32Fnv1: testhashs32Fnv1,
|
testhashs32Fnv1: testhashs32Fnv1,
|
||||||
@@ -1358,67 +1351,33 @@ class Monster {
|
|||||||
testhashu32Fnv1a: testhashu32Fnv1a,
|
testhashu32Fnv1a: testhashu32Fnv1a,
|
||||||
testhashs64Fnv1a: testhashs64Fnv1a,
|
testhashs64Fnv1a: testhashs64Fnv1a,
|
||||||
testhashu64Fnv1a: testhashu64Fnv1a,
|
testhashu64Fnv1a: testhashu64Fnv1a,
|
||||||
testarrayofbools: const fb.ListReader<bool>(
|
testarrayofbools: testarrayofbools?.toList(),
|
||||||
fb.BoolReader(),
|
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 52),
|
|
||||||
testf: testf,
|
testf: testf,
|
||||||
testf2: testf2,
|
testf2: testf2,
|
||||||
testf3: testf3,
|
testf3: testf3,
|
||||||
testarrayofstring2: const fb.ListReader<String>(
|
testarrayofstring2: testarrayofstring2?.toList(),
|
||||||
fb.StringReader(),
|
testarrayofsortedstruct: testarrayofsortedstruct?.map((e) => e.unpack()).toList(),
|
||||||
lazy: false,
|
flex: flex?.toList(),
|
||||||
).vTableGetNullable(_bc, _bcOffset, 60),
|
|
||||||
testarrayofsortedstruct: testarrayofsortedstruct
|
|
||||||
?.map((e) => e.unpack())
|
|
||||||
.toList(),
|
|
||||||
flex: const fb.Uint8ListReader(
|
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 64),
|
|
||||||
test5: test5?.map((e) => e.unpack()).toList(),
|
test5: test5?.map((e) => e.unpack()).toList(),
|
||||||
vectorOfLongs: const fb.ListReader<int>(
|
vectorOfLongs: vectorOfLongs?.toList(),
|
||||||
fb.Int64Reader(),
|
vectorOfDoubles: vectorOfDoubles?.toList(),
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 68),
|
|
||||||
vectorOfDoubles: const fb.ListReader<double>(
|
|
||||||
fb.Float64Reader(),
|
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 70),
|
|
||||||
parentNamespaceTest: parentNamespaceTest?.unpack(),
|
parentNamespaceTest: parentNamespaceTest?.unpack(),
|
||||||
vectorOfReferrables: vectorOfReferrables?.map((e) => e.unpack()).toList(),
|
vectorOfReferrables: vectorOfReferrables?.map((e) => e.unpack()).toList(),
|
||||||
singleWeakReference: singleWeakReference,
|
singleWeakReference: singleWeakReference,
|
||||||
vectorOfWeakReferences: const fb.ListReader<int>(
|
vectorOfWeakReferences: vectorOfWeakReferences?.toList(),
|
||||||
fb.Uint64Reader(),
|
vectorOfStrongReferrables: vectorOfStrongReferrables?.map((e) => e.unpack()).toList(),
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 78),
|
|
||||||
vectorOfStrongReferrables: vectorOfStrongReferrables
|
|
||||||
?.map((e) => e.unpack())
|
|
||||||
.toList(),
|
|
||||||
coOwningReference: coOwningReference,
|
coOwningReference: coOwningReference,
|
||||||
vectorOfCoOwningReferences: const fb.ListReader<int>(
|
vectorOfCoOwningReferences: vectorOfCoOwningReferences?.toList(),
|
||||||
fb.Uint64Reader(),
|
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 84),
|
|
||||||
nonOwningReference: nonOwningReference,
|
nonOwningReference: nonOwningReference,
|
||||||
vectorOfNonOwningReferences: const fb.ListReader<int>(
|
vectorOfNonOwningReferences: vectorOfNonOwningReferences?.toList(),
|
||||||
fb.Uint64Reader(),
|
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 88),
|
|
||||||
anyUniqueType: anyUniqueType,
|
anyUniqueType: anyUniqueType,
|
||||||
anyUnique: anyUnique?.unpack(),
|
anyUnique: anyUnique?.unpack(),
|
||||||
anyAmbiguousType: anyAmbiguousType,
|
anyAmbiguousType: anyAmbiguousType,
|
||||||
anyAmbiguous: anyAmbiguous?.unpack(),
|
anyAmbiguous: anyAmbiguous?.unpack(),
|
||||||
vectorOfEnums: const fb.ListReader<Color>(
|
vectorOfEnums: vectorOfEnums?.toList(),
|
||||||
Color.reader,
|
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 98),
|
|
||||||
signedEnum: signedEnum,
|
signedEnum: signedEnum,
|
||||||
testrequirednestedflatbuffer: const fb.Uint8ListReader(
|
testrequirednestedflatbuffer: testrequirednestedflatbuffer?.toList(),
|
||||||
lazy: false,
|
scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList(),
|
||||||
).vTableGetNullable(_bc, _bcOffset, 102),
|
|
||||||
scalarKeySortedTables: scalarKeySortedTables
|
|
||||||
?.map((e) => e.unpack())
|
|
||||||
.toList(),
|
|
||||||
nativeInline: nativeInline?.unpack(),
|
nativeInline: nativeInline?.unpack(),
|
||||||
longEnumNonEnumDefault: longEnumNonEnumDefault,
|
longEnumNonEnumDefault: longEnumNonEnumDefault,
|
||||||
longEnumNormalDefault: longEnumNormalDefault,
|
longEnumNormalDefault: longEnumNormalDefault,
|
||||||
@@ -2478,13 +2437,8 @@ class TypeAliases {
|
|||||||
u64: u64,
|
u64: u64,
|
||||||
f32: f32,
|
f32: f32,
|
||||||
f64: f64,
|
f64: f64,
|
||||||
v8: const fb.Int8ListReader(
|
v8: v8?.toList(),
|
||||||
lazy: false,
|
vf64: vf64?.toList(),
|
||||||
).vTableGetNullable(_bc, _bcOffset, 24),
|
|
||||||
vf64: const fb.ListReader<double>(
|
|
||||||
fb.Float64Reader(),
|
|
||||||
lazy: false,
|
|
||||||
).vTableGetNullable(_bc, _bcOffset, 26),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, TypeAliasesT? object) {
|
static int pack(fb.Builder fbBuilder, TypeAliasesT? object) {
|
||||||
|
|||||||
@@ -611,20 +611,11 @@ class DartGenerator : public BaseGenerator {
|
|||||||
constructor_args +=
|
constructor_args +=
|
||||||
field_name + nullableValueAccessOperator + ".unpack()";
|
field_name + nullableValueAccessOperator + ".unpack()";
|
||||||
} else if (type.base_type == BASE_TYPE_VECTOR) {
|
} else if (type.base_type == BASE_TYPE_VECTOR) {
|
||||||
|
constructor_args += field_name + nullableValueAccessOperator;
|
||||||
if (type.VectorType().base_type == BASE_TYPE_STRUCT) {
|
if (type.VectorType().base_type == BASE_TYPE_STRUCT) {
|
||||||
constructor_args += field_name + nullableValueAccessOperator +
|
constructor_args += ".map((e) => e.unpack())";
|
||||||
".map((e) => e.unpack()).toList()";
|
|
||||||
} else {
|
|
||||||
constructor_args +=
|
|
||||||
GenReaderTypeName(field.value.type, struct_def.defined_namespace,
|
|
||||||
field, false, false);
|
|
||||||
constructor_args += ".vTableGet";
|
|
||||||
std::string offset = NumToString(field.value.offset);
|
|
||||||
constructor_args +=
|
|
||||||
isNullable
|
|
||||||
? "Nullable(_bc, _bcOffset, " + offset + ")"
|
|
||||||
: "(_bc, _bcOffset, " + offset + ", " + defaultValue + ")";
|
|
||||||
}
|
}
|
||||||
|
constructor_args += ".toList()";
|
||||||
} else {
|
} else {
|
||||||
constructor_args += field_name;
|
constructor_args += field_name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ class MonsterExtra {
|
|||||||
f1: f1,
|
f1: f1,
|
||||||
f2: f2,
|
f2: f2,
|
||||||
f3: f3,
|
f3: f3,
|
||||||
dvec: const fb.ListReader<double>(fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 20),
|
dvec: dvec?.toList(),
|
||||||
fvec: const fb.ListReader<double>(fb.Float32Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 22));
|
fvec: fvec?.toList());
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, MonsterExtraT? object) {
|
static int pack(fb.Builder fbBuilder, MonsterExtraT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
|
|||||||
@@ -1210,15 +1210,15 @@ class Monster {
|
|||||||
mana: mana,
|
mana: mana,
|
||||||
hp: hp,
|
hp: hp,
|
||||||
name: name,
|
name: name,
|
||||||
inventory: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 14),
|
inventory: inventory?.toList(),
|
||||||
color: color,
|
color: color,
|
||||||
testType: testType,
|
testType: testType,
|
||||||
test: test?.unpack(),
|
test: test?.unpack(),
|
||||||
test4: test4?.map((e) => e.unpack()).toList(),
|
test4: test4?.map((e) => e.unpack()).toList(),
|
||||||
testarrayofstring: const fb.ListReader<String>(fb.StringReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 24),
|
testarrayofstring: testarrayofstring?.toList(),
|
||||||
testarrayoftables: testarrayoftables?.map((e) => e.unpack()).toList(),
|
testarrayoftables: testarrayoftables?.map((e) => e.unpack()).toList(),
|
||||||
enemy: enemy?.unpack(),
|
enemy: enemy?.unpack(),
|
||||||
testnestedflatbuffer: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 30),
|
testnestedflatbuffer: testnestedflatbuffer?.toList(),
|
||||||
testempty: testempty?.unpack(),
|
testempty: testempty?.unpack(),
|
||||||
testbool: testbool,
|
testbool: testbool,
|
||||||
testhashs32Fnv1: testhashs32Fnv1,
|
testhashs32Fnv1: testhashs32Fnv1,
|
||||||
@@ -1229,32 +1229,32 @@ class Monster {
|
|||||||
testhashu32Fnv1a: testhashu32Fnv1a,
|
testhashu32Fnv1a: testhashu32Fnv1a,
|
||||||
testhashs64Fnv1a: testhashs64Fnv1a,
|
testhashs64Fnv1a: testhashs64Fnv1a,
|
||||||
testhashu64Fnv1a: testhashu64Fnv1a,
|
testhashu64Fnv1a: testhashu64Fnv1a,
|
||||||
testarrayofbools: const fb.ListReader<bool>(fb.BoolReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 52),
|
testarrayofbools: testarrayofbools?.toList(),
|
||||||
testf: testf,
|
testf: testf,
|
||||||
testf2: testf2,
|
testf2: testf2,
|
||||||
testf3: testf3,
|
testf3: testf3,
|
||||||
testarrayofstring2: const fb.ListReader<String>(fb.StringReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 60),
|
testarrayofstring2: testarrayofstring2?.toList(),
|
||||||
testarrayofsortedstruct: testarrayofsortedstruct?.map((e) => e.unpack()).toList(),
|
testarrayofsortedstruct: testarrayofsortedstruct?.map((e) => e.unpack()).toList(),
|
||||||
flex: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 64),
|
flex: flex?.toList(),
|
||||||
test5: test5?.map((e) => e.unpack()).toList(),
|
test5: test5?.map((e) => e.unpack()).toList(),
|
||||||
vectorOfLongs: const fb.ListReader<int>(fb.Int64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 68),
|
vectorOfLongs: vectorOfLongs?.toList(),
|
||||||
vectorOfDoubles: const fb.ListReader<double>(fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 70),
|
vectorOfDoubles: vectorOfDoubles?.toList(),
|
||||||
parentNamespaceTest: parentNamespaceTest?.unpack(),
|
parentNamespaceTest: parentNamespaceTest?.unpack(),
|
||||||
vectorOfReferrables: vectorOfReferrables?.map((e) => e.unpack()).toList(),
|
vectorOfReferrables: vectorOfReferrables?.map((e) => e.unpack()).toList(),
|
||||||
singleWeakReference: singleWeakReference,
|
singleWeakReference: singleWeakReference,
|
||||||
vectorOfWeakReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 78),
|
vectorOfWeakReferences: vectorOfWeakReferences?.toList(),
|
||||||
vectorOfStrongReferrables: vectorOfStrongReferrables?.map((e) => e.unpack()).toList(),
|
vectorOfStrongReferrables: vectorOfStrongReferrables?.map((e) => e.unpack()).toList(),
|
||||||
coOwningReference: coOwningReference,
|
coOwningReference: coOwningReference,
|
||||||
vectorOfCoOwningReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 84),
|
vectorOfCoOwningReferences: vectorOfCoOwningReferences?.toList(),
|
||||||
nonOwningReference: nonOwningReference,
|
nonOwningReference: nonOwningReference,
|
||||||
vectorOfNonOwningReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 88),
|
vectorOfNonOwningReferences: vectorOfNonOwningReferences?.toList(),
|
||||||
anyUniqueType: anyUniqueType,
|
anyUniqueType: anyUniqueType,
|
||||||
anyUnique: anyUnique?.unpack(),
|
anyUnique: anyUnique?.unpack(),
|
||||||
anyAmbiguousType: anyAmbiguousType,
|
anyAmbiguousType: anyAmbiguousType,
|
||||||
anyAmbiguous: anyAmbiguous?.unpack(),
|
anyAmbiguous: anyAmbiguous?.unpack(),
|
||||||
vectorOfEnums: const fb.ListReader<Color>(Color.reader, lazy: false).vTableGetNullable(_bc, _bcOffset, 98),
|
vectorOfEnums: vectorOfEnums?.toList(),
|
||||||
signedEnum: signedEnum,
|
signedEnum: signedEnum,
|
||||||
testrequirednestedflatbuffer: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 102),
|
testrequirednestedflatbuffer: testrequirednestedflatbuffer?.toList(),
|
||||||
scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList(),
|
scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList(),
|
||||||
nativeInline: nativeInline?.unpack(),
|
nativeInline: nativeInline?.unpack(),
|
||||||
longEnumNonEnumDefault: longEnumNonEnumDefault,
|
longEnumNonEnumDefault: longEnumNonEnumDefault,
|
||||||
@@ -2161,8 +2161,8 @@ class TypeAliases {
|
|||||||
u64: u64,
|
u64: u64,
|
||||||
f32: f32,
|
f32: f32,
|
||||||
f64: f64,
|
f64: f64,
|
||||||
v8: const fb.Int8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 24),
|
v8: v8?.toList(),
|
||||||
vf64: const fb.ListReader<double>(fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 26));
|
vf64: vf64?.toList());
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, TypeAliasesT? object) {
|
static int pack(fb.Builder fbBuilder, TypeAliasesT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user