diff options
author | Dan Field <dnfield@google.com> | 2021-01-07 14:51:52 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-07 14:51:52 -0800 |
commit | 809fe49c7a35011547501be83c84b76a464684ac (patch) | |
tree | 6fd3786034141fc3801af9d71563728bb0dae3a1 /dart | |
parent | 41253e574e9064de556032b987e1b22d7283cc37 (diff) | |
download | flatbuffers-809fe49c7a35011547501be83c84b76a464684ac.tar.gz flatbuffers-809fe49c7a35011547501be83c84b76a464684ac.tar.bz2 flatbuffers-809fe49c7a35011547501be83c84b76a464684ac.zip |
Fix up scripts, fix generated enum value for strong mode, regenerate files (#6389)
* Fix up scripts, fix generated enum value for strong mode, regenerate files
* missing files
* GH action
* remove action
Diffstat (limited to 'dart')
-rw-r--r-- | dart/example/monster_my_game.sample_generated.dart | 14 | ||||
-rwxr-xr-x | dart/publish.sh | 19 | ||||
-rw-r--r-- | dart/test/flat_buffers_test.dart | 9 | ||||
-rw-r--r-- | dart/test/monster_test_my_game.example_generated.dart | 28 |
4 files changed, 50 insertions, 20 deletions
diff --git a/dart/example/monster_my_game.sample_generated.dart b/dart/example/monster_my_game.sample_generated.dart index 2c7c10d2..ced9b31b 100644 --- a/dart/example/monster_my_game.sample_generated.dart +++ b/dart/example/monster_my_game.sample_generated.dart @@ -1,5 +1,5 @@ // automatically generated by the FlatBuffers compiler, do not modify -// ignore_for_file: unused_import, non_constant_identifier_names +// ignore_for_file: unused_import, unused_field, unused_local_variable library my_game.sample; @@ -12,7 +12,7 @@ class Color { const Color._(this.value); factory Color.fromValue(int value) { - if (value == null) return null; + if (value == null) value = 0; if (!values.containsKey(value)) { throw new StateError('Invalid value $value for bit flag enum Color'); } @@ -26,7 +26,7 @@ class Color { static const Color Red = const Color._(0); static const Color Green = const Color._(1); static const Color Blue = const Color._(2); - static get values => {0: Red,1: Green,2: Blue,}; + static const Map<int,Color> values = {0: Red,1: Green,2: Blue,}; static const fb.Reader<Color> reader = const _ColorReader(); @@ -52,7 +52,7 @@ class EquipmentTypeId { const EquipmentTypeId._(this.value); factory EquipmentTypeId.fromValue(int value) { - if (value == null) return null; + if (value == null) value = 0; if (!values.containsKey(value)) { throw new StateError('Invalid value $value for bit flag enum EquipmentTypeId'); } @@ -65,7 +65,7 @@ class EquipmentTypeId { static const EquipmentTypeId NONE = const EquipmentTypeId._(0); static const EquipmentTypeId Weapon = const EquipmentTypeId._(1); - static get values => {0: NONE,1: Weapon,}; + static const Map<int,EquipmentTypeId> values = {0: NONE,1: Weapon,}; static const fb.Reader<EquipmentTypeId> reader = const _EquipmentTypeIdReader(); @@ -184,7 +184,7 @@ class Monster { List<int> get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 14, null); Color get color => new Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2)); List<Weapon> get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGet(_bc, _bcOffset, 18, null); - EquipmentTypeId get equippedType => new EquipmentTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 20, null)); + EquipmentTypeId get equippedType => new EquipmentTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 20, 0)); dynamic get equipped { switch (equippedType?.value) { case 1: return Weapon.reader.vTableGet(_bc, _bcOffset, 22, null); @@ -363,7 +363,7 @@ class Weapon { final int _bcOffset; String get name => const fb.StringReader().vTableGet(_bc, _bcOffset, 4, null); - int get damage => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, null); + int get damage => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 0); @override String toString() { diff --git a/dart/publish.sh b/dart/publish.sh index 167a4a34..7f031013 100755 --- a/dart/publish.sh +++ b/dart/publish.sh @@ -17,12 +17,25 @@ # Note to pub consumers: this file is used to assist with publishing the # pub package from the flatbuffers repository and is not meant for general use. # As pub does not currently provide a way to exclude files, it is included here. +set -e -command -v pub >/dev/null 2>&1 || { echo >&2 "Require `pub` but it's not installed. Aborting."; exit 1; } +command -v dart >/dev/null 2>&1 || { echo >&2 "Require `dart` but it's not installed. Aborting."; exit 1; } cp ../samples/monster.fbs example/ cp ../tests/monster_test.fbs test/ -pub publish +cp -r ../tests/include_test/*.fbs test/ +cp -r ../tests/include_test/sub test/ + +pushd example +../../flatc --dart ./monster.fbs +popd + +pushd test +../../flatc --dart ./monster_test.fbs +popd + +dart pub publish rm example/monster.fbs -rm test/monster_test.fbs
\ No newline at end of file +rm test/*.fbs +rm -rf test/sub diff --git a/dart/test/flat_buffers_test.dart b/dart/test/flat_buffers_test.dart index be500f28..3f854d87 100644 --- a/dart/test/flat_buffers_test.dart +++ b/dart/test/flat_buffers_test.dart @@ -81,7 +81,8 @@ class CheckOtherLangaugesData { 'nonOwningReference: 0, vectorOfNonOwningReferences: null, ' 'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, ' 'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, ' - 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}}, ' + 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' + 'testrequirednestedflatbuffer: null}, ' 'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], ' 'testarrayofstring: [test1, test2], testarrayoftables: null, ' 'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, ' @@ -101,7 +102,8 @@ class CheckOtherLangaugesData { 'nonOwningReference: 0, vectorOfNonOwningReferences: null, ' 'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, ' 'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, ' - 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}}, ' + 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' + 'testrequirednestedflatbuffer: null}, ' 'testnestedflatbuffer: null, testempty: null, testbool: true, ' 'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, ' 'testhashs64Fnv1: 7930699090847568257, ' @@ -121,7 +123,8 @@ class CheckOtherLangaugesData { 'vectorOfNonOwningReferences: null, ' 'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, ' 'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, ' - 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}}', + 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' + 'testrequirednestedflatbuffer: null}', ); } } diff --git a/dart/test/monster_test_my_game.example_generated.dart b/dart/test/monster_test_my_game.example_generated.dart index 79218923..f9305f7c 100644 --- a/dart/test/monster_test_my_game.example_generated.dart +++ b/dart/test/monster_test_my_game.example_generated.dart @@ -32,7 +32,7 @@ class Color { /// \brief color Blue (1u << 3) static const Color Blue = const Color._(8); - static const values = {1: Red,2: Green,8: Blue,}; + static const Map<int,Color> values = {1: Red,2: Green,8: Blue,}; static const fb.Reader<Color> reader = const _ColorReader(); @@ -73,7 +73,7 @@ class Race { static const Race Human = const Race._(0); static const Race Dwarf = const Race._(1); static const Race Elf = const Race._(2); - static const values = {-1: None,0: Human,1: Dwarf,2: Elf,}; + static const Map<int,Race> values = {-1: None,0: Human,1: Dwarf,2: Elf,}; static const fb.Reader<Race> reader = const _RaceReader(); @@ -114,7 +114,7 @@ class AnyTypeId { static const AnyTypeId Monster = const AnyTypeId._(1); static const AnyTypeId TestSimpleTableWithEnum = const AnyTypeId._(2); static const AnyTypeId MyGame_Example2_Monster = const AnyTypeId._(3); - static const values = {0: NONE,1: Monster,2: TestSimpleTableWithEnum,3: MyGame_Example2_Monster,}; + static const Map<int,AnyTypeId> values = {0: NONE,1: Monster,2: TestSimpleTableWithEnum,3: MyGame_Example2_Monster,}; static const fb.Reader<AnyTypeId> reader = const _AnyTypeIdReader(); @@ -155,7 +155,7 @@ class AnyUniqueAliasesTypeId { static const AnyUniqueAliasesTypeId M = const AnyUniqueAliasesTypeId._(1); static const AnyUniqueAliasesTypeId TS = const AnyUniqueAliasesTypeId._(2); static const AnyUniqueAliasesTypeId M2 = const AnyUniqueAliasesTypeId._(3); - static const values = {0: NONE,1: M,2: TS,3: M2,}; + static const Map<int,AnyUniqueAliasesTypeId> values = {0: NONE,1: M,2: TS,3: M2,}; static const fb.Reader<AnyUniqueAliasesTypeId> reader = const _AnyUniqueAliasesTypeIdReader(); @@ -196,7 +196,7 @@ class AnyAmbiguousAliasesTypeId { static const AnyAmbiguousAliasesTypeId M1 = const AnyAmbiguousAliasesTypeId._(1); static const AnyAmbiguousAliasesTypeId M2 = const AnyAmbiguousAliasesTypeId._(2); static const AnyAmbiguousAliasesTypeId M3 = const AnyAmbiguousAliasesTypeId._(3); - static const values = {0: NONE,1: M1,2: M2,3: M3,}; + static const Map<int,AnyAmbiguousAliasesTypeId> values = {0: NONE,1: M1,2: M2,3: M3,}; static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = const _AnyAmbiguousAliasesTypeIdReader(); @@ -801,10 +801,11 @@ class Monster { } List<Color> get vectorOfEnums => const fb.ListReader<Color>(Color.reader).vTableGet(_bc, _bcOffset, 98, null); Race get signedEnum => new Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1)); + List<int> get testrequirednestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 102, null); @override String toString() { - return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums, signedEnum: $signedEnum}'; + return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums, signedEnum: $signedEnum, testrequirednestedflatbuffer: $testrequirednestedflatbuffer}'; } } @@ -1019,6 +1020,10 @@ class MonsterBuilder { fbBuilder.addInt8(48, signedEnum?.value); return fbBuilder.offset; } + int addTestrequirednestedflatbufferOffset(int offset) { + fbBuilder.addOffset(49, offset); + return fbBuilder.offset; + } int finish() { return fbBuilder.endTable(); @@ -1074,6 +1079,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder { final dynamic _anyAmbiguous; final List<Color> _vectorOfEnums; final Race _signedEnum; + final List<int> _testrequirednestedflatbuffer; MonsterObjectBuilder({ Vec3ObjectBuilder pos, @@ -1124,6 +1130,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder { dynamic anyAmbiguous, List<Color> vectorOfEnums, Race signedEnum, + List<int> testrequirednestedflatbuffer, }) : _pos = pos, _mana = mana, @@ -1172,7 +1179,8 @@ class MonsterObjectBuilder extends fb.ObjectBuilder { _anyAmbiguousType = anyAmbiguousType, _anyAmbiguous = anyAmbiguous, _vectorOfEnums = vectorOfEnums, - _signedEnum = signedEnum; + _signedEnum = signedEnum, + _testrequirednestedflatbuffer = testrequirednestedflatbuffer; /// Finish building, and store into the [fbBuilder]. @override @@ -1240,6 +1248,9 @@ class MonsterObjectBuilder extends fb.ObjectBuilder { final int vectorOfEnumsOffset = _vectorOfEnums?.isNotEmpty == true ? fbBuilder.writeListUint8(_vectorOfEnums.map((f) => f.value)) : null; + final int testrequirednestedflatbufferOffset = _testrequirednestedflatbuffer?.isNotEmpty == true + ? fbBuilder.writeListUint8(_testrequirednestedflatbuffer) + : null; fbBuilder.startTable(); if (_pos != null) { @@ -1342,6 +1353,9 @@ class MonsterObjectBuilder extends fb.ObjectBuilder { fbBuilder.addOffset(47, vectorOfEnumsOffset); } fbBuilder.addInt8(48, _signedEnum?.value); + if (testrequirednestedflatbufferOffset != null) { + fbBuilder.addOffset(49, testrequirednestedflatbufferOffset); + } return fbBuilder.endTable(); } |