mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 06:30:02 +00:00
Fix union unpacking (#8748)
This commit is contained in:
@@ -276,7 +276,7 @@ class Table2 {
|
|||||||
|
|
||||||
Table2T unpack() => Table2T(
|
Table2T unpack() => Table2T(
|
||||||
typeType: typeType,
|
typeType: typeType,
|
||||||
type: type);
|
type: type?.unpack());
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, Table2T? object) {
|
static int pack(fb.Builder fbBuilder, Table2T? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
|
|||||||
@@ -1337,7 +1337,7 @@ class Monster {
|
|||||||
).vTableGetNullable(_bc, _bcOffset, 14),
|
).vTableGetNullable(_bc, _bcOffset, 14),
|
||||||
color: color,
|
color: color,
|
||||||
testType: testType,
|
testType: testType,
|
||||||
test: test,
|
test: test?.unpack(),
|
||||||
test4: test4?.map((e) => e.unpack()).toList(),
|
test4: test4?.map((e) => e.unpack()).toList(),
|
||||||
testarrayofstring: const fb.ListReader<String>(
|
testarrayofstring: const fb.ListReader<String>(
|
||||||
fb.StringReader(),
|
fb.StringReader(),
|
||||||
@@ -1405,9 +1405,9 @@ class Monster {
|
|||||||
lazy: false,
|
lazy: false,
|
||||||
).vTableGetNullable(_bc, _bcOffset, 88),
|
).vTableGetNullable(_bc, _bcOffset, 88),
|
||||||
anyUniqueType: anyUniqueType,
|
anyUniqueType: anyUniqueType,
|
||||||
anyUnique: anyUnique,
|
anyUnique: anyUnique?.unpack(),
|
||||||
anyAmbiguousType: anyAmbiguousType,
|
anyAmbiguousType: anyAmbiguousType,
|
||||||
anyAmbiguous: anyAmbiguous,
|
anyAmbiguous: anyAmbiguous?.unpack(),
|
||||||
vectorOfEnums: const fb.ListReader<Color>(
|
vectorOfEnums: const fb.ListReader<Color>(
|
||||||
Color.reader,
|
Color.reader,
|
||||||
lazy: false,
|
lazy: false,
|
||||||
|
|||||||
@@ -606,7 +606,8 @@ class DartGenerator : public BaseGenerator {
|
|||||||
std::string defaultValue = getDefaultValue(field.value);
|
std::string defaultValue = getDefaultValue(field.value);
|
||||||
bool isNullable = defaultValue.empty() && !struct_def.fixed;
|
bool isNullable = defaultValue.empty() && !struct_def.fixed;
|
||||||
std::string nullableValueAccessOperator = isNullable ? "?" : "";
|
std::string nullableValueAccessOperator = isNullable ? "?" : "";
|
||||||
if (type.base_type == BASE_TYPE_STRUCT) {
|
if (type.base_type == BASE_TYPE_STRUCT ||
|
||||||
|
type.base_type == BASE_TYPE_UNION) {
|
||||||
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) {
|
||||||
|
|||||||
@@ -1213,7 +1213,7 @@ class Monster {
|
|||||||
inventory: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 14),
|
inventory: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 14),
|
||||||
color: color,
|
color: color,
|
||||||
testType: testType,
|
testType: testType,
|
||||||
test: test,
|
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: const fb.ListReader<String>(fb.StringReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 24),
|
||||||
testarrayoftables: testarrayoftables?.map((e) => e.unpack()).toList(),
|
testarrayoftables: testarrayoftables?.map((e) => e.unpack()).toList(),
|
||||||
@@ -1249,9 +1249,9 @@ class Monster {
|
|||||||
nonOwningReference: nonOwningReference,
|
nonOwningReference: nonOwningReference,
|
||||||
vectorOfNonOwningReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 88),
|
vectorOfNonOwningReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 88),
|
||||||
anyUniqueType: anyUniqueType,
|
anyUniqueType: anyUniqueType,
|
||||||
anyUnique: anyUnique,
|
anyUnique: anyUnique?.unpack(),
|
||||||
anyAmbiguousType: anyAmbiguousType,
|
anyAmbiguousType: anyAmbiguousType,
|
||||||
anyAmbiguous: anyAmbiguous,
|
anyAmbiguous: anyAmbiguous?.unpack(),
|
||||||
vectorOfEnums: const fb.ListReader<Color>(Color.reader, lazy: false).vTableGetNullable(_bc, _bcOffset, 98),
|
vectorOfEnums: const fb.ListReader<Color>(Color.reader, lazy: false).vTableGetNullable(_bc, _bcOffset, 98),
|
||||||
signedEnum: signedEnum,
|
signedEnum: signedEnum,
|
||||||
testrequirednestedflatbuffer: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 102),
|
testrequirednestedflatbuffer: const fb.Uint8ListReader(lazy: false).vTableGetNullable(_bc, _bcOffset, 102),
|
||||||
|
|||||||
Reference in New Issue
Block a user