dart: use enhanced enums (#8313)

* dart: rename enums.fbs

* feat: use dart enhanced enums

* generate code

---------

Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
Ivan Dlugos
2024-11-18 18:31:19 +01:00
committed by GitHub
parent 5f453ef738
commit a9df44828d
19 changed files with 297 additions and 512 deletions

View File

@@ -5,7 +5,7 @@ homepage: https://github.com/google/flatbuffers
documentation: https://google.github.io/flatbuffers/index.html documentation: https://google.github.io/flatbuffers/index.html
environment: environment:
sdk: '>=2.12.0 <4.0.0' sdk: '>=2.17.0 <4.0.0'
dev_dependencies: dev_dependencies:
test: ^1.17.7 test: ^1.17.7

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
import 'dart:typed_data' show Uint8List; import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb; import 'package:flat_buffers/flat_buffers.dart' as fb;

View File

@@ -1,20 +1,25 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
import 'dart:typed_data' show Uint8List; import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb; import 'package:flat_buffers/flat_buffers.dart' as fb;
class OptionsEnum { enum OptionsEnum {
A(1),
B(2),
C(3);
final int value; final int value;
const OptionsEnum._(this.value); const OptionsEnum(this.value);
factory OptionsEnum.fromValue(int value) { factory OptionsEnum.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 1: return OptionsEnum.A;
throw StateError('Invalid value $value for bit flag enum OptionsEnum'); case 2: return OptionsEnum.B;
case 3: return OptionsEnum.C;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static OptionsEnum? _createOrNull(int? value) => static OptionsEnum? _createOrNull(int? value) =>
@@ -22,22 +27,7 @@ class OptionsEnum {
static const int minValue = 1; static const int minValue = 1;
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value);
static const OptionsEnum A = OptionsEnum._(1);
static const OptionsEnum B = OptionsEnum._(2);
static const OptionsEnum C = OptionsEnum._(3);
static const Map<int, OptionsEnum> values = {
1: A,
2: B,
3: C};
static const fb.Reader<OptionsEnum> reader = _OptionsEnumReader(); static const fb.Reader<OptionsEnum> reader = _OptionsEnumReader();
@override
String toString() {
return 'OptionsEnum{value: $value}';
}
} }
class _OptionsEnumReader extends fb.Reader<OptionsEnum> { class _OptionsEnumReader extends fb.Reader<OptionsEnum> {

View File

@@ -9,7 +9,7 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
import './monster_test_my_game.example_generated.dart' as example; import './monster_test_my_game.example_generated.dart' as example;
import './monster_test_my_game.example2_generated.dart' as example2; import './monster_test_my_game.example2_generated.dart' as example2;
import './list_of_enums_generated.dart' as example3; import 'enums_generated.dart' as example3;
import './bool_structs_generated.dart' as example4; import './bool_structs_generated.dart' as example4;
main() { main() {
@@ -63,11 +63,11 @@ class CheckOtherLangaugesData {
expect( expect(
mon.toString(), mon.toString(),
'Monster{' 'Monster{'
'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, ' 'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color.Green, test3: Test{a: 5, b: 6}}, '
'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], ' 'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], '
'color: Color{value: 8}, testType: AnyTypeId{value: 1}, ' 'color: Color.Blue, testType: AnyTypeId.Monster, '
'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, ' 'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
'inventory: null, color: Color{value: 8}, testType: null, ' 'inventory: null, color: Color.Blue, testType: null, '
'test: null, test4: null, testarrayofstring: null, ' 'test: null, test4: null, testarrayofstring: null, '
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, ' 'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
'testempty: null, testbool: false, testhashs32Fnv1: 0, ' 'testempty: null, testbool: false, testhashs32Fnv1: 0, '
@@ -82,18 +82,18 @@ class CheckOtherLangaugesData {
'coOwningReference: 0, vectorOfCoOwningReferences: null, ' 'coOwningReference: 0, vectorOfCoOwningReferences: null, '
'nonOwningReference: 0, vectorOfNonOwningReferences: null, ' 'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, ' 'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, ' 'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
'nativeInline: null, ' 'nativeInline: null, '
'longEnumNonEnumDefault: LongEnum{value: 0}, ' 'longEnumNonEnumDefault: LongEnum._default, '
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' 'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, ' '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], ' 'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
'testarrayofstring: [test1, test2], testarrayoftables: null, ' 'testarrayofstring: [test1, test2], testarrayoftables: null, '
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, ' 'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
'inventory: null, color: Color{value: 8}, testType: null, ' 'inventory: null, color: Color.Blue, testType: null, '
'test: null, test4: null, testarrayofstring: null, ' 'test: null, test4: null, testarrayofstring: null, '
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, ' 'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
'testempty: null, testbool: false, testhashs32Fnv1: 0, ' 'testempty: null, testbool: false, testhashs32Fnv1: 0, '
@@ -108,11 +108,11 @@ class CheckOtherLangaugesData {
'coOwningReference: 0, vectorOfCoOwningReferences: null, ' 'coOwningReference: 0, vectorOfCoOwningReferences: null, '
'nonOwningReference: 0, vectorOfNonOwningReferences: null, ' 'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, ' 'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, ' 'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
'nativeInline: null, ' 'nativeInline: null, '
'longEnumNonEnumDefault: LongEnum{value: 0}, ' 'longEnumNonEnumDefault: LongEnum._default, '
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' 'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, ' '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
@@ -137,12 +137,12 @@ class CheckOtherLangaugesData {
'vectorOfNonOwningReferences: null, ' 'vectorOfNonOwningReferences: null, '
'anyUniqueType: null, anyUnique: null, ' 'anyUniqueType: null, anyUnique: null, '
'anyAmbiguousType: null, ' 'anyAmbiguousType: null, '
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: ' 'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: '
'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], ' 'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], '
'nativeInline: Test{a: 1, b: 2}, ' 'nativeInline: Test{a: 1, b: 2}, '
'longEnumNonEnumDefault: LongEnum{value: 0}, ' 'longEnumNonEnumDefault: LongEnum._default, '
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' 'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}'); '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}');

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
import 'dart:typed_data' show Uint8List; import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb; import 'package:flat_buffers/flat_buffers.dart' as fb;

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game.other_name_space; library my_game.other_name_space;
@@ -9,16 +9,17 @@ import 'package:flat_buffers/flat_buffers.dart' as fb;
import './include_test1_generated.dart'; import './include_test1_generated.dart';
class FromInclude { enum FromInclude {
IncludeVal(0);
final int value; final int value;
const FromInclude._(this.value); const FromInclude(this.value);
factory FromInclude.fromValue(int value) { factory FromInclude.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return FromInclude.IncludeVal;
throw StateError('Invalid value $value for bit flag enum FromInclude'); default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static FromInclude? _createOrNull(int? value) => static FromInclude? _createOrNull(int? value) =>
@@ -26,18 +27,7 @@ class FromInclude {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 0; static const int maxValue = 0;
static bool containsValue(int value) => values.containsKey(value);
static const FromInclude IncludeVal = FromInclude._(0);
static const Map<int, FromInclude> values = {
0: IncludeVal};
static const fb.Reader<FromInclude> reader = _FromIncludeReader(); static const fb.Reader<FromInclude> reader = _FromIncludeReader();
@override
String toString() {
return 'FromInclude{value: $value}';
}
} }
class _FromIncludeReader extends fb.Reader<FromInclude> { class _FromIncludeReader extends fb.Reader<FromInclude> {

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library keyword_test; library keyword_test;
@@ -7,16 +7,21 @@ import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb; import 'package:flat_buffers/flat_buffers.dart' as fb;
class Abc { enum Abc {
$void(0),
where(1),
stackalloc(2);
final int value; final int value;
const Abc._(this.value); const Abc(this.value);
factory Abc.fromValue(int value) { factory Abc.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return Abc.$void;
throw StateError('Invalid value $value for bit flag enum Abc'); case 1: return Abc.where;
case 2: return Abc.stackalloc;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static Abc? _createOrNull(int? value) => static Abc? _createOrNull(int? value) =>
@@ -24,22 +29,7 @@ class Abc {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 2; static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value);
static const Abc $void = Abc._(0);
static const Abc where = Abc._(1);
static const Abc stackalloc = Abc._(2);
static const Map<int, Abc> values = {
0: $void,
1: where,
2: stackalloc};
static const fb.Reader<Abc> reader = _AbcReader(); static const fb.Reader<Abc> reader = _AbcReader();
@override
String toString() {
return 'Abc{value: $value}';
}
} }
class _AbcReader extends fb.Reader<Abc> { class _AbcReader extends fb.Reader<Abc> {
@@ -53,16 +43,17 @@ class _AbcReader extends fb.Reader<Abc> {
Abc.fromValue(const fb.Int32Reader().read(bc, offset)); Abc.fromValue(const fb.Int32Reader().read(bc, offset));
} }
class Public { enum Public {
NONE(0);
final int value; final int value;
const Public._(this.value); const Public(this.value);
factory Public.fromValue(int value) { factory Public.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return Public.NONE;
throw StateError('Invalid value $value for bit flag enum Public'); default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static Public? _createOrNull(int? value) => static Public? _createOrNull(int? value) =>
@@ -70,18 +61,7 @@ class Public {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 0; static const int maxValue = 0;
static bool containsValue(int value) => values.containsKey(value);
static const Public NONE = Public._(0);
static const Map<int, Public> values = {
0: NONE};
static const fb.Reader<Public> reader = _PublicReader(); static const fb.Reader<Public> reader = _PublicReader();
@override
String toString() {
return 'Public{value: $value}';
}
} }
class _PublicReader extends fb.Reader<Public> { class _PublicReader extends fb.Reader<Public> {
@@ -95,16 +75,21 @@ class _PublicReader extends fb.Reader<Public> {
Public.fromValue(const fb.Int32Reader().read(bc, offset)); Public.fromValue(const fb.Int32Reader().read(bc, offset));
} }
class KeywordsInUnionTypeId { enum KeywordsInUnionTypeId {
NONE(0),
$static(1),
internal(2);
final int value; final int value;
const KeywordsInUnionTypeId._(this.value); const KeywordsInUnionTypeId(this.value);
factory KeywordsInUnionTypeId.fromValue(int value) { factory KeywordsInUnionTypeId.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return KeywordsInUnionTypeId.NONE;
throw StateError('Invalid value $value for bit flag enum KeywordsInUnionTypeId'); case 1: return KeywordsInUnionTypeId.$static;
case 2: return KeywordsInUnionTypeId.internal;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static KeywordsInUnionTypeId? _createOrNull(int? value) => static KeywordsInUnionTypeId? _createOrNull(int? value) =>
@@ -112,22 +97,7 @@ class KeywordsInUnionTypeId {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 2; static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value);
static const KeywordsInUnionTypeId NONE = KeywordsInUnionTypeId._(0);
static const KeywordsInUnionTypeId $static = KeywordsInUnionTypeId._(1);
static const KeywordsInUnionTypeId internal = KeywordsInUnionTypeId._(2);
static const Map<int, KeywordsInUnionTypeId> values = {
0: NONE,
1: $static,
2: internal};
static const fb.Reader<KeywordsInUnionTypeId> reader = _KeywordsInUnionTypeIdReader(); static const fb.Reader<KeywordsInUnionTypeId> reader = _KeywordsInUnionTypeIdReader();
@override
String toString() {
return 'KeywordsInUnionTypeId{value: $value}';
}
} }
class _KeywordsInUnionTypeIdReader extends fb.Reader<KeywordsInUnionTypeId> { class _KeywordsInUnionTypeIdReader extends fb.Reader<KeywordsInUnionTypeId> {

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game.example2; library my_game.example2;

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game.example; library my_game.example;
@@ -12,46 +12,29 @@ import './monster_test_my_game.example2_generated.dart' as my_game_example2;
import './include_test1_generated.dart'; import './include_test1_generated.dart';
/// Composite components of Monster color. /// Composite components of Monster color.
class Color { enum Color {
Red(1),
Green(2),
Blue(8),
_default(0);
final int value; final int value;
const Color._(this.value); const Color(this.value);
factory Color.fromValue(int value) { factory Color.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 1: return Color.Red;
if (value == 0) { case 2: return Color.Green;
return Color._(0); case 8: return Color.Blue;
} else { case 0: return Color._default;
throw StateError('Invalid value $value for bit flag enum Color'); default: throw StateError('Invalid value $value for bit flag enum');
}
} }
return result;
} }
static Color? _createOrNull(int? value) => static Color? _createOrNull(int? value) =>
value == null ? null : Color.fromValue(value); value == null ? null : Color.fromValue(value);
static bool containsValue(int value) => values.containsKey(value);
static const Color Red = Color._(1);
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
static const Color Green = Color._(2);
/// \brief color Blue (1u << 3)
static const Color Blue = Color._(8);
static const Map<int, Color> values = {
1: Red,
2: Green,
8: Blue};
static const fb.Reader<Color> reader = _ColorReader(); static const fb.Reader<Color> reader = _ColorReader();
@override
String toString() {
return 'Color{value: $value}';
}
} }
class _ColorReader extends fb.Reader<Color> { class _ColorReader extends fb.Reader<Color> {
@@ -65,16 +48,23 @@ class _ColorReader extends fb.Reader<Color> {
Color.fromValue(const fb.Uint8Reader().read(bc, offset)); Color.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class Race { enum Race {
None(-1),
Human(0),
Dwarf(1),
Elf(2);
final int value; final int value;
const Race._(this.value); const Race(this.value);
factory Race.fromValue(int value) { factory Race.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case -1: return Race.None;
throw StateError('Invalid value $value for bit flag enum Race'); case 0: return Race.Human;
case 1: return Race.Dwarf;
case 2: return Race.Elf;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static Race? _createOrNull(int? value) => static Race? _createOrNull(int? value) =>
@@ -82,24 +72,7 @@ class Race {
static const int minValue = -1; static const int minValue = -1;
static const int maxValue = 2; static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value);
static const Race None = Race._(-1);
static const Race Human = Race._(0);
static const Race Dwarf = Race._(1);
static const Race Elf = Race._(2);
static const Map<int, Race> values = {
-1: None,
0: Human,
1: Dwarf,
2: Elf};
static const fb.Reader<Race> reader = _RaceReader(); static const fb.Reader<Race> reader = _RaceReader();
@override
String toString() {
return 'Race{value: $value}';
}
} }
class _RaceReader extends fb.Reader<Race> { class _RaceReader extends fb.Reader<Race> {
@@ -113,41 +86,29 @@ class _RaceReader extends fb.Reader<Race> {
Race.fromValue(const fb.Int8Reader().read(bc, offset)); Race.fromValue(const fb.Int8Reader().read(bc, offset));
} }
class LongEnum { enum LongEnum {
LongOne(2),
LongTwo(4),
LongBig(1099511627776),
_default(0);
final int value; final int value;
const LongEnum._(this.value); const LongEnum(this.value);
factory LongEnum.fromValue(int value) { factory LongEnum.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 2: return LongEnum.LongOne;
if (value == 0) { case 4: return LongEnum.LongTwo;
return LongEnum._(0); case 1099511627776: return LongEnum.LongBig;
} else { case 0: return LongEnum._default;
throw StateError('Invalid value $value for bit flag enum LongEnum'); default: throw StateError('Invalid value $value for bit flag enum');
}
} }
return result;
} }
static LongEnum? _createOrNull(int? value) => static LongEnum? _createOrNull(int? value) =>
value == null ? null : LongEnum.fromValue(value); value == null ? null : LongEnum.fromValue(value);
static bool containsValue(int value) => values.containsKey(value);
static const LongEnum LongOne = LongEnum._(2);
static const LongEnum LongTwo = LongEnum._(4);
static const LongEnum LongBig = LongEnum._(1099511627776);
static const Map<int, LongEnum> values = {
2: LongOne,
4: LongTwo,
1099511627776: LongBig};
static const fb.Reader<LongEnum> reader = _LongEnumReader(); static const fb.Reader<LongEnum> reader = _LongEnumReader();
@override
String toString() {
return 'LongEnum{value: $value}';
}
} }
class _LongEnumReader extends fb.Reader<LongEnum> { class _LongEnumReader extends fb.Reader<LongEnum> {
@@ -161,16 +122,23 @@ class _LongEnumReader extends fb.Reader<LongEnum> {
LongEnum.fromValue(const fb.Uint64Reader().read(bc, offset)); LongEnum.fromValue(const fb.Uint64Reader().read(bc, offset));
} }
class AnyTypeId { enum AnyTypeId {
NONE(0),
Monster(1),
TestSimpleTableWithEnum(2),
MyGame_Example2_Monster(3);
final int value; final int value;
const AnyTypeId._(this.value); const AnyTypeId(this.value);
factory AnyTypeId.fromValue(int value) { factory AnyTypeId.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return AnyTypeId.NONE;
throw StateError('Invalid value $value for bit flag enum AnyTypeId'); case 1: return AnyTypeId.Monster;
case 2: return AnyTypeId.TestSimpleTableWithEnum;
case 3: return AnyTypeId.MyGame_Example2_Monster;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static AnyTypeId? _createOrNull(int? value) => static AnyTypeId? _createOrNull(int? value) =>
@@ -178,24 +146,7 @@ class AnyTypeId {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value);
static const AnyTypeId NONE = AnyTypeId._(0);
static const AnyTypeId Monster = AnyTypeId._(1);
static const AnyTypeId TestSimpleTableWithEnum = AnyTypeId._(2);
static const AnyTypeId MyGame_Example2_Monster = AnyTypeId._(3);
static const Map<int, AnyTypeId> values = {
0: NONE,
1: Monster,
2: TestSimpleTableWithEnum,
3: MyGame_Example2_Monster};
static const fb.Reader<AnyTypeId> reader = _AnyTypeIdReader(); static const fb.Reader<AnyTypeId> reader = _AnyTypeIdReader();
@override
String toString() {
return 'AnyTypeId{value: $value}';
}
} }
class _AnyTypeIdReader extends fb.Reader<AnyTypeId> { class _AnyTypeIdReader extends fb.Reader<AnyTypeId> {
@@ -209,16 +160,23 @@ class _AnyTypeIdReader extends fb.Reader<AnyTypeId> {
AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class AnyUniqueAliasesTypeId { enum AnyUniqueAliasesTypeId {
NONE(0),
M(1),
TS(2),
M2(3);
final int value; final int value;
const AnyUniqueAliasesTypeId._(this.value); const AnyUniqueAliasesTypeId(this.value);
factory AnyUniqueAliasesTypeId.fromValue(int value) { factory AnyUniqueAliasesTypeId.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return AnyUniqueAliasesTypeId.NONE;
throw StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId'); case 1: return AnyUniqueAliasesTypeId.M;
case 2: return AnyUniqueAliasesTypeId.TS;
case 3: return AnyUniqueAliasesTypeId.M2;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static AnyUniqueAliasesTypeId? _createOrNull(int? value) => static AnyUniqueAliasesTypeId? _createOrNull(int? value) =>
@@ -226,24 +184,7 @@ class AnyUniqueAliasesTypeId {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value);
static const AnyUniqueAliasesTypeId NONE = AnyUniqueAliasesTypeId._(0);
static const AnyUniqueAliasesTypeId M = AnyUniqueAliasesTypeId._(1);
static const AnyUniqueAliasesTypeId TS = AnyUniqueAliasesTypeId._(2);
static const AnyUniqueAliasesTypeId M2 = AnyUniqueAliasesTypeId._(3);
static const Map<int, AnyUniqueAliasesTypeId> values = {
0: NONE,
1: M,
2: TS,
3: M2};
static const fb.Reader<AnyUniqueAliasesTypeId> reader = _AnyUniqueAliasesTypeIdReader(); static const fb.Reader<AnyUniqueAliasesTypeId> reader = _AnyUniqueAliasesTypeIdReader();
@override
String toString() {
return 'AnyUniqueAliasesTypeId{value: $value}';
}
} }
class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> { class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> {
@@ -257,16 +198,23 @@ class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> {
AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class AnyAmbiguousAliasesTypeId { enum AnyAmbiguousAliasesTypeId {
NONE(0),
M1(1),
M2(2),
M3(3);
final int value; final int value;
const AnyAmbiguousAliasesTypeId._(this.value); const AnyAmbiguousAliasesTypeId(this.value);
factory AnyAmbiguousAliasesTypeId.fromValue(int value) { factory AnyAmbiguousAliasesTypeId.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return AnyAmbiguousAliasesTypeId.NONE;
throw StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId'); case 1: return AnyAmbiguousAliasesTypeId.M1;
case 2: return AnyAmbiguousAliasesTypeId.M2;
case 3: return AnyAmbiguousAliasesTypeId.M3;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static AnyAmbiguousAliasesTypeId? _createOrNull(int? value) => static AnyAmbiguousAliasesTypeId? _createOrNull(int? value) =>
@@ -274,24 +222,7 @@ class AnyAmbiguousAliasesTypeId {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value);
static const AnyAmbiguousAliasesTypeId NONE = AnyAmbiguousAliasesTypeId._(0);
static const AnyAmbiguousAliasesTypeId M1 = AnyAmbiguousAliasesTypeId._(1);
static const AnyAmbiguousAliasesTypeId M2 = AnyAmbiguousAliasesTypeId._(2);
static const AnyAmbiguousAliasesTypeId M3 = AnyAmbiguousAliasesTypeId._(3);
static const Map<int, AnyAmbiguousAliasesTypeId> values = {
0: NONE,
1: M1,
2: M2,
3: M3};
static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = _AnyAmbiguousAliasesTypeIdReader(); static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = _AnyAmbiguousAliasesTypeIdReader();
@override
String toString() {
return 'AnyAmbiguousAliasesTypeId{value: $value}';
}
} }
class _AnyAmbiguousAliasesTypeIdReader extends fb.Reader<AnyAmbiguousAliasesTypeId> { class _AnyAmbiguousAliasesTypeIdReader extends fb.Reader<AnyAmbiguousAliasesTypeId> {
@@ -1461,7 +1392,7 @@ class MonsterT implements fb.Packable {
this.testrequirednestedflatbuffer, this.testrequirednestedflatbuffer,
this.scalarKeySortedTables, this.scalarKeySortedTables,
this.nativeInline, this.nativeInline,
this.longEnumNonEnumDefault = const LongEnum._(0), this.longEnumNonEnumDefault = LongEnum._default,
this.longEnumNormalDefault = LongEnum.LongOne, this.longEnumNormalDefault = LongEnum.LongOne,
this.nanDefault = double.nan, this.nanDefault = double.nan,
this.infDefault = double.infinity, this.infDefault = double.infinity,

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game; library my_game;

View File

@@ -135,7 +135,7 @@ class DartGenerator : public BaseGenerator {
code = code + "// " + FlatBuffersGeneratedWarning() + "\n"; code = code + "// " + FlatBuffersGeneratedWarning() + "\n";
code = code + code = code +
"// ignore_for_file: unused_import, unused_field, unused_element, " "// ignore_for_file: unused_import, unused_field, unused_element, "
"unused_local_variable\n\n"; "unused_local_variable, constant_identifier_names\n\n";
if (!kv->first.empty()) { code += "library " + kv->first + ";\n\n"; } if (!kv->first.empty()) { code += "library " + kv->first + ";\n\n"; }
@@ -215,36 +215,45 @@ class DartGenerator : public BaseGenerator {
namer_.Type(enum_def) + (enum_def.is_union ? "TypeId" : ""); namer_.Type(enum_def) + (enum_def.is_union ? "TypeId" : "");
const bool is_bit_flags = const bool is_bit_flags =
enum_def.attributes.Lookup("bit_flags") != nullptr; enum_def.attributes.Lookup("bit_flags") != nullptr;
// The flatbuffer schema language allows bit flag enums to potentially have // The flatbuffer schema language allows bit flag enums to potentially have
// a default value of zero, even if it's not a valid enum value... // a default value of zero, even if it's not a valid enum value...
const bool permit_zero = is_bit_flags; const bool auto_default = is_bit_flags && !enum_def.FindByValue("0");
code += "class " + enum_type + " {\n"; code += "enum " + enum_type + " {\n";
code += " final int value;\n"; for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
code += " const " + enum_type + "._(this.value);\n\n"; auto &ev = **it;
code += " factory " + enum_type + ".fromValue(int value) {\n"; const auto enum_var = namer_.Variant(ev);
code += " final result = values[value];\n"; if (it != enum_def.Vals().begin()) code += ",\n";
code += " if (result == null) {\n"; code += " " + enum_var + "(" + enum_def.ToString(ev) + ")";
if (permit_zero) {
code += " if (value == 0) {\n";
code += " return " + enum_type + "._(0);\n";
code += " } else {\n";
} }
code += " throw StateError('Invalid value $value for bit flag enum "; if (auto_default) { code += ",\n _default(0)"; }
code += enum_type + "');\n"; code += ";\n\n";
if (permit_zero) { code += " }\n"; }
code += " }\n";
code += " return result;\n"; code += " final int value;\n";
code += " const " + enum_type + "(this.value);\n\n";
code += " factory " + enum_type + ".fromValue(int value) {\n";
code += " switch (value) {\n";
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
auto &ev = **it;
const auto enum_var = namer_.Variant(ev);
code += " case " + enum_def.ToString(ev) + ":";
code += " return " + enum_type + "." + enum_var + ";\n";
}
if (auto_default) {
code += " case 0: return " + enum_type + "._default;\n";
}
code += " default: throw StateError(";
code += "'Invalid value $value for bit flag enum');\n";
code += " }\n";
code += " }\n\n"; code += " }\n\n";
code += " static " + enum_type + "? _createOrNull(int? value) => \n"; code += " static " + enum_type + "? _createOrNull(int? value) =>\n";
code += code +=
" value == null ? null : " + enum_type + ".fromValue(value);\n\n"; " value == null ? null : " + enum_type + ".fromValue(value);\n\n";
// this is meaningless for bit_flags // This is meaningless for bit_flags, however, note that unlike "regular"
// however, note that unlike "regular" dart enums this enum can still have // dart enums this enum can still have holes.
// holes.
if (!is_bit_flags) { if (!is_bit_flags) {
code += " static const int minValue = " + code += " static const int minValue = " +
enum_def.ToString(*enum_def.MinValue()) + ";\n"; enum_def.ToString(*enum_def.MinValue()) + ";\n";
@@ -252,37 +261,8 @@ class DartGenerator : public BaseGenerator {
enum_def.ToString(*enum_def.MaxValue()) + ";\n"; enum_def.ToString(*enum_def.MaxValue()) + ";\n";
} }
code +=
" static bool containsValue(int value) =>"
" values.containsKey(value);\n\n";
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
auto &ev = **it;
const auto enum_var = namer_.Variant(ev);
if (!ev.doc_comment.empty()) {
if (it != enum_def.Vals().begin()) { code += '\n'; }
GenDocComment(ev.doc_comment, " ", code);
}
code += " static const " + enum_type + " " + enum_var + " = " +
enum_type + "._(" + enum_def.ToString(ev) + ");\n";
}
code += " static const Map<int, " + enum_type + "> values = {\n";
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
auto &ev = **it;
const auto enum_var = namer_.Variant(ev);
if (it != enum_def.Vals().begin()) code += ",\n";
code += " " + enum_def.ToString(ev) + ": " + enum_var;
}
code += "};\n\n";
code += " static const " + _kFb + ".Reader<" + enum_type + "> reader = _" + code += " static const " + _kFb + ".Reader<" + enum_type + "> reader = _" +
enum_type + "Reader();\n\n"; enum_type + "Reader();\n";
code += " @override\n";
code += " String toString() {\n";
code += " return '" + enum_type + "{value: $value}';\n";
code += " }\n";
code += "}\n\n"; code += "}\n\n";
GenEnumReader(enum_def, enum_type, code); GenEnumReader(enum_def, enum_type, code);
@@ -552,8 +532,7 @@ class DartGenerator : public BaseGenerator {
if (auto val = enum_def.FindByValue(defaultValue)) { if (auto val = enum_def.FindByValue(defaultValue)) {
constructor_args += " = " + namer_.EnumVariant(enum_def, *val); constructor_args += " = " + namer_.EnumVariant(enum_def, *val);
} else { } else {
constructor_args += " = const " + namer_.Type(enum_def) + "._(" + constructor_args += " = " + namer_.Type(enum_def) + "._default";
defaultValue + ")";
} }
} else { } else {
constructor_args += " = " + defaultValue; constructor_args += " = " + defaultValue;

View File

@@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
set -euo pipefail
# #
# Copyright 2016 Google Inc. All rights reserved. # Copyright 2016 Google Inc. All rights reserved.
# #
@@ -16,7 +17,10 @@
pushd "$(dirname $0)" >/dev/null pushd "$(dirname $0)" >/dev/null
command -v dart >/dev/null 2>&1 || { echo >&2 "Dart tests require dart to be in path but it's not installed. Aborting."; exit 1; } command -v dart >/dev/null 2>&1 || {
echo >&2 "Dart tests require dart to be in path but it's not installed. Aborting."
exit 1
}
# output required files to the dart folder so that pub will be able to # output required files to the dart folder so that pub will be able to
# distribute them and more people can more easily run the dart tests # distribute them and more people can more easily run the dart tests
../flatc --dart --gen-object-api -I include_test -o ../dart/test monster_test.fbs ../flatc --dart --gen-object-api -I include_test -o ../dart/test monster_test.fbs
@@ -28,7 +32,7 @@ cp monster_test.fbs ../dart/test
cd ../dart cd ../dart
../flatc --dart --gen-object-api -o ./test ./test/list_of_enums.fbs ../flatc --dart --gen-object-api -o ./test ./test/enums.fbs
../flatc --dart --gen-object-api -o ./test ./test/bool_structs.fbs ../flatc --dart --gen-object-api -o ./test ./test/bool_structs.fbs
# update packages # update packages

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
import 'dart:typed_data' show Uint8List; import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb; import 'package:flat_buffers/flat_buffers.dart' as fb;

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game.other_name_space; library my_game.other_name_space;
@@ -9,16 +9,17 @@ import 'package:flat_buffers/flat_buffers.dart' as fb;
import './include_test1_generated.dart'; import './include_test1_generated.dart';
class FromInclude { enum FromInclude {
IncludeVal(0);
final int value; final int value;
const FromInclude._(this.value); const FromInclude(this.value);
factory FromInclude.fromValue(int value) { factory FromInclude.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return FromInclude.IncludeVal;
throw StateError('Invalid value $value for bit flag enum FromInclude'); default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static FromInclude? _createOrNull(int? value) => static FromInclude? _createOrNull(int? value) =>
@@ -26,18 +27,7 @@ class FromInclude {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 0; static const int maxValue = 0;
static bool containsValue(int value) => values.containsKey(value);
static const FromInclude IncludeVal = FromInclude._(0);
static const Map<int, FromInclude> values = {
0: IncludeVal};
static const fb.Reader<FromInclude> reader = _FromIncludeReader(); static const fb.Reader<FromInclude> reader = _FromIncludeReader();
@override
String toString() {
return 'FromInclude{value: $value}';
}
} }
class _FromIncludeReader extends fb.Reader<FromInclude> { class _FromIncludeReader extends fb.Reader<FromInclude> {

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game; library my_game;

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game.example2; library my_game.example2;

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game.example; library my_game.example;
@@ -12,46 +12,29 @@ import './monster_test_my_game.example2_generated.dart' as my_game_example2;
import './include_test1_generated.dart'; import './include_test1_generated.dart';
/// Composite components of Monster color. /// Composite components of Monster color.
class Color { enum Color {
Red(1),
Green(2),
Blue(8),
_default(0);
final int value; final int value;
const Color._(this.value); const Color(this.value);
factory Color.fromValue(int value) { factory Color.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 1: return Color.Red;
if (value == 0) { case 2: return Color.Green;
return Color._(0); case 8: return Color.Blue;
} else { case 0: return Color._default;
throw StateError('Invalid value $value for bit flag enum Color'); default: throw StateError('Invalid value $value for bit flag enum');
}
} }
return result;
} }
static Color? _createOrNull(int? value) => static Color? _createOrNull(int? value) =>
value == null ? null : Color.fromValue(value); value == null ? null : Color.fromValue(value);
static bool containsValue(int value) => values.containsKey(value);
static const Color Red = Color._(1);
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
static const Color Green = Color._(2);
/// \brief color Blue (1u << 3)
static const Color Blue = Color._(8);
static const Map<int, Color> values = {
1: Red,
2: Green,
8: Blue};
static const fb.Reader<Color> reader = _ColorReader(); static const fb.Reader<Color> reader = _ColorReader();
@override
String toString() {
return 'Color{value: $value}';
}
} }
class _ColorReader extends fb.Reader<Color> { class _ColorReader extends fb.Reader<Color> {
@@ -65,16 +48,23 @@ class _ColorReader extends fb.Reader<Color> {
Color.fromValue(const fb.Uint8Reader().read(bc, offset)); Color.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class Race { enum Race {
None(-1),
Human(0),
Dwarf(1),
Elf(2);
final int value; final int value;
const Race._(this.value); const Race(this.value);
factory Race.fromValue(int value) { factory Race.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case -1: return Race.None;
throw StateError('Invalid value $value for bit flag enum Race'); case 0: return Race.Human;
case 1: return Race.Dwarf;
case 2: return Race.Elf;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static Race? _createOrNull(int? value) => static Race? _createOrNull(int? value) =>
@@ -82,24 +72,7 @@ class Race {
static const int minValue = -1; static const int minValue = -1;
static const int maxValue = 2; static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value);
static const Race None = Race._(-1);
static const Race Human = Race._(0);
static const Race Dwarf = Race._(1);
static const Race Elf = Race._(2);
static const Map<int, Race> values = {
-1: None,
0: Human,
1: Dwarf,
2: Elf};
static const fb.Reader<Race> reader = _RaceReader(); static const fb.Reader<Race> reader = _RaceReader();
@override
String toString() {
return 'Race{value: $value}';
}
} }
class _RaceReader extends fb.Reader<Race> { class _RaceReader extends fb.Reader<Race> {
@@ -113,41 +86,29 @@ class _RaceReader extends fb.Reader<Race> {
Race.fromValue(const fb.Int8Reader().read(bc, offset)); Race.fromValue(const fb.Int8Reader().read(bc, offset));
} }
class LongEnum { enum LongEnum {
LongOne(2),
LongTwo(4),
LongBig(1099511627776),
_default(0);
final int value; final int value;
const LongEnum._(this.value); const LongEnum(this.value);
factory LongEnum.fromValue(int value) { factory LongEnum.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 2: return LongEnum.LongOne;
if (value == 0) { case 4: return LongEnum.LongTwo;
return LongEnum._(0); case 1099511627776: return LongEnum.LongBig;
} else { case 0: return LongEnum._default;
throw StateError('Invalid value $value for bit flag enum LongEnum'); default: throw StateError('Invalid value $value for bit flag enum');
}
} }
return result;
} }
static LongEnum? _createOrNull(int? value) => static LongEnum? _createOrNull(int? value) =>
value == null ? null : LongEnum.fromValue(value); value == null ? null : LongEnum.fromValue(value);
static bool containsValue(int value) => values.containsKey(value);
static const LongEnum LongOne = LongEnum._(2);
static const LongEnum LongTwo = LongEnum._(4);
static const LongEnum LongBig = LongEnum._(1099511627776);
static const Map<int, LongEnum> values = {
2: LongOne,
4: LongTwo,
1099511627776: LongBig};
static const fb.Reader<LongEnum> reader = _LongEnumReader(); static const fb.Reader<LongEnum> reader = _LongEnumReader();
@override
String toString() {
return 'LongEnum{value: $value}';
}
} }
class _LongEnumReader extends fb.Reader<LongEnum> { class _LongEnumReader extends fb.Reader<LongEnum> {
@@ -161,16 +122,23 @@ class _LongEnumReader extends fb.Reader<LongEnum> {
LongEnum.fromValue(const fb.Uint64Reader().read(bc, offset)); LongEnum.fromValue(const fb.Uint64Reader().read(bc, offset));
} }
class AnyTypeId { enum AnyTypeId {
NONE(0),
Monster(1),
TestSimpleTableWithEnum(2),
MyGame_Example2_Monster(3);
final int value; final int value;
const AnyTypeId._(this.value); const AnyTypeId(this.value);
factory AnyTypeId.fromValue(int value) { factory AnyTypeId.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return AnyTypeId.NONE;
throw StateError('Invalid value $value for bit flag enum AnyTypeId'); case 1: return AnyTypeId.Monster;
case 2: return AnyTypeId.TestSimpleTableWithEnum;
case 3: return AnyTypeId.MyGame_Example2_Monster;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static AnyTypeId? _createOrNull(int? value) => static AnyTypeId? _createOrNull(int? value) =>
@@ -178,24 +146,7 @@ class AnyTypeId {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value);
static const AnyTypeId NONE = AnyTypeId._(0);
static const AnyTypeId Monster = AnyTypeId._(1);
static const AnyTypeId TestSimpleTableWithEnum = AnyTypeId._(2);
static const AnyTypeId MyGame_Example2_Monster = AnyTypeId._(3);
static const Map<int, AnyTypeId> values = {
0: NONE,
1: Monster,
2: TestSimpleTableWithEnum,
3: MyGame_Example2_Monster};
static const fb.Reader<AnyTypeId> reader = _AnyTypeIdReader(); static const fb.Reader<AnyTypeId> reader = _AnyTypeIdReader();
@override
String toString() {
return 'AnyTypeId{value: $value}';
}
} }
class _AnyTypeIdReader extends fb.Reader<AnyTypeId> { class _AnyTypeIdReader extends fb.Reader<AnyTypeId> {
@@ -209,16 +160,23 @@ class _AnyTypeIdReader extends fb.Reader<AnyTypeId> {
AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class AnyUniqueAliasesTypeId { enum AnyUniqueAliasesTypeId {
NONE(0),
M(1),
TS(2),
M2(3);
final int value; final int value;
const AnyUniqueAliasesTypeId._(this.value); const AnyUniqueAliasesTypeId(this.value);
factory AnyUniqueAliasesTypeId.fromValue(int value) { factory AnyUniqueAliasesTypeId.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return AnyUniqueAliasesTypeId.NONE;
throw StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId'); case 1: return AnyUniqueAliasesTypeId.M;
case 2: return AnyUniqueAliasesTypeId.TS;
case 3: return AnyUniqueAliasesTypeId.M2;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static AnyUniqueAliasesTypeId? _createOrNull(int? value) => static AnyUniqueAliasesTypeId? _createOrNull(int? value) =>
@@ -226,24 +184,7 @@ class AnyUniqueAliasesTypeId {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value);
static const AnyUniqueAliasesTypeId NONE = AnyUniqueAliasesTypeId._(0);
static const AnyUniqueAliasesTypeId M = AnyUniqueAliasesTypeId._(1);
static const AnyUniqueAliasesTypeId TS = AnyUniqueAliasesTypeId._(2);
static const AnyUniqueAliasesTypeId M2 = AnyUniqueAliasesTypeId._(3);
static const Map<int, AnyUniqueAliasesTypeId> values = {
0: NONE,
1: M,
2: TS,
3: M2};
static const fb.Reader<AnyUniqueAliasesTypeId> reader = _AnyUniqueAliasesTypeIdReader(); static const fb.Reader<AnyUniqueAliasesTypeId> reader = _AnyUniqueAliasesTypeIdReader();
@override
String toString() {
return 'AnyUniqueAliasesTypeId{value: $value}';
}
} }
class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> { class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> {
@@ -257,16 +198,23 @@ class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> {
AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class AnyAmbiguousAliasesTypeId { enum AnyAmbiguousAliasesTypeId {
NONE(0),
M1(1),
M2(2),
M3(3);
final int value; final int value;
const AnyAmbiguousAliasesTypeId._(this.value); const AnyAmbiguousAliasesTypeId(this.value);
factory AnyAmbiguousAliasesTypeId.fromValue(int value) { factory AnyAmbiguousAliasesTypeId.fromValue(int value) {
final result = values[value]; switch (value) {
if (result == null) { case 0: return AnyAmbiguousAliasesTypeId.NONE;
throw StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId'); case 1: return AnyAmbiguousAliasesTypeId.M1;
case 2: return AnyAmbiguousAliasesTypeId.M2;
case 3: return AnyAmbiguousAliasesTypeId.M3;
default: throw StateError('Invalid value $value for bit flag enum');
} }
return result;
} }
static AnyAmbiguousAliasesTypeId? _createOrNull(int? value) => static AnyAmbiguousAliasesTypeId? _createOrNull(int? value) =>
@@ -274,24 +222,7 @@ class AnyAmbiguousAliasesTypeId {
static const int minValue = 0; static const int minValue = 0;
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value);
static const AnyAmbiguousAliasesTypeId NONE = AnyAmbiguousAliasesTypeId._(0);
static const AnyAmbiguousAliasesTypeId M1 = AnyAmbiguousAliasesTypeId._(1);
static const AnyAmbiguousAliasesTypeId M2 = AnyAmbiguousAliasesTypeId._(2);
static const AnyAmbiguousAliasesTypeId M3 = AnyAmbiguousAliasesTypeId._(3);
static const Map<int, AnyAmbiguousAliasesTypeId> values = {
0: NONE,
1: M1,
2: M2,
3: M3};
static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = _AnyAmbiguousAliasesTypeIdReader(); static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = _AnyAmbiguousAliasesTypeIdReader();
@override
String toString() {
return 'AnyAmbiguousAliasesTypeId{value: $value}';
}
} }
class _AnyAmbiguousAliasesTypeIdReader extends fb.Reader<AnyAmbiguousAliasesTypeId> { class _AnyAmbiguousAliasesTypeIdReader extends fb.Reader<AnyAmbiguousAliasesTypeId> {
@@ -1461,7 +1392,7 @@ class MonsterT implements fb.Packable {
this.testrequirednestedflatbuffer, this.testrequirednestedflatbuffer,
this.scalarKeySortedTables, this.scalarKeySortedTables,
this.nativeInline, this.nativeInline,
this.longEnumNonEnumDefault = const LongEnum._(0), this.longEnumNonEnumDefault = LongEnum._default,
this.longEnumNormalDefault = LongEnum.LongOne, this.longEnumNormalDefault = LongEnum.LongOne,
this.nanDefault = double.nan, this.nanDefault = double.nan,
this.infDefault = double.infinity, this.infDefault = double.infinity,

View File

@@ -1,5 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable // ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
library my_game; library my_game;