Dart lints (#6808)

* Dart - add analysis options with the recommended lints

* Dart - generate code without linter issues

* Dart - remove linter issues in example and test code

* Dart - remove linter issues in lib code

* Dart - update generate code in /tests/
This commit is contained in:
Ivan Dlugos
2021-08-30 21:54:59 +02:00
committed by GitHub
parent 4b9123baff
commit e3c76a5cde
20 changed files with 560 additions and 581 deletions

View File

@@ -0,0 +1 @@
include: package:lints/recommended.yaml

View File

@@ -15,7 +15,7 @@
*/ */
import 'package:flat_buffers/flat_buffers.dart' as fb; import 'package:flat_buffers/flat_buffers.dart' as fb;
import './monster_my_game.sample_generated.dart' as myGame; import './monster_my_game.sample_generated.dart' as my_game;
// Example how to use FlatBuffers to create and read binary buffers. // Example how to use FlatBuffers to create and read binary buffers.
@@ -25,20 +25,20 @@ void main() {
} }
void builderTest() { void builderTest() {
final builder = new fb.Builder(initialSize: 1024); final builder = fb.Builder(initialSize: 1024);
final int? weaponOneName = builder.writeString("Sword"); final int? weaponOneName = builder.writeString("Sword");
final int weaponOneDamage = 3; final int weaponOneDamage = 3;
final int? weaponTwoName = builder.writeString("Axe"); final int? weaponTwoName = builder.writeString("Axe");
final int weaponTwoDamage = 5; final int weaponTwoDamage = 5;
final swordBuilder = new myGame.WeaponBuilder(builder) final swordBuilder = my_game.WeaponBuilder(builder)
..begin() ..begin()
..addNameOffset(weaponOneName) ..addNameOffset(weaponOneName)
..addDamage(weaponOneDamage); ..addDamage(weaponOneDamage);
final int sword = swordBuilder.finish(); final int sword = swordBuilder.finish();
final axeBuilder = new myGame.WeaponBuilder(builder) final axeBuilder = my_game.WeaponBuilder(builder)
..begin() ..begin()
..addNameOffset(weaponTwoName) ..addNameOffset(weaponTwoName)
..addDamage(weaponTwoDamage); ..addDamage(weaponTwoDamage);
@@ -54,7 +54,7 @@ void builderTest() {
final weapons = builder.writeList([sword, axe]); final weapons = builder.writeList([sword, axe]);
// Struct builders are very easy to reuse. // Struct builders are very easy to reuse.
final vec3Builder = new myGame.Vec3Builder(builder); final vec3Builder = my_game.Vec3Builder(builder);
vec3Builder.finish(4.0, 5.0, 6.0); vec3Builder.finish(4.0, 5.0, 6.0);
vec3Builder.finish(1.0, 2.0, 3.0); vec3Builder.finish(1.0, 2.0, 3.0);
@@ -62,17 +62,17 @@ void builderTest() {
final int hp = 300; final int hp = 300;
final int mana = 150; final int mana = 150;
final monster = new myGame.MonsterBuilder(builder) final monster = my_game.MonsterBuilder(builder)
..begin() ..begin()
..addNameOffset(name) ..addNameOffset(name)
..addInventoryOffset(inventory) ..addInventoryOffset(inventory)
..addWeaponsOffset(weapons) ..addWeaponsOffset(weapons)
..addEquippedType(myGame.EquipmentTypeId.Weapon) ..addEquippedType(my_game.EquipmentTypeId.Weapon)
..addEquippedOffset(axe) ..addEquippedOffset(axe)
..addHp(hp) ..addHp(hp)
..addMana(mana) ..addMana(mana)
..addPos(vec3Builder.finish(1.0, 2.0, 3.0)) ..addPos(vec3Builder.finish(1.0, 2.0, 3.0))
..addColor(myGame.Color.Red); ..addColor(my_game.Color.Red);
final int monsteroff = monster.finish(); final int monsteroff = monster.finish();
builder.finish(monsteroff); builder.finish(monsteroff);
@@ -85,17 +85,17 @@ void builderTest() {
void objectBuilderTest() { void objectBuilderTest() {
// Create the builder here so we can use it for both weapons and equipped // Create the builder here so we can use it for both weapons and equipped
// the actual data will only be written to the buffer once. // the actual data will only be written to the buffer once.
var axe = new myGame.WeaponObjectBuilder(name: 'Axe', damage: 5); var axe = my_game.WeaponObjectBuilder(name: 'Axe', damage: 5);
var monsterBuilder = new myGame.MonsterObjectBuilder( var monsterBuilder = my_game.MonsterObjectBuilder(
pos: new myGame.Vec3ObjectBuilder(x: 1.0, y: 2.0, z: 3.0), pos: my_game.Vec3ObjectBuilder(x: 1.0, y: 2.0, z: 3.0),
mana: 150, mana: 150,
hp: 300, hp: 300,
name: 'Orc', name: 'Orc',
inventory: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], inventory: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
color: myGame.Color.Red, color: my_game.Color.Red,
weapons: [new myGame.WeaponObjectBuilder(name: 'Sword', damage: 3), axe], weapons: [my_game.WeaponObjectBuilder(name: 'Sword', damage: 3), axe],
equippedType: myGame.EquipmentTypeId.Weapon, equippedType: my_game.EquipmentTypeId.Weapon,
equipped: axe, equipped: axe,
); );
@@ -114,7 +114,7 @@ void objectBuilderTest() {
bool verify(List<int> buffer) { bool verify(List<int> buffer) {
// Get access to the root: // Get access to the root:
var monster = new myGame.Monster(buffer); var monster = my_game.Monster(buffer);
// Get and test some scalar types from the FlatBuffer. // Get and test some scalar types from the FlatBuffer.
assert(monster.hp == 80); assert(monster.hp == 80);
@@ -131,20 +131,20 @@ bool verify(List<int> buffer) {
assert(inv[9] == 9); assert(inv[9] == 9);
// Get and test the `weapons` FlatBuffers's `vector`. // Get and test the `weapons` FlatBuffers's `vector`.
var expected_weapon_names = ["Sword", "Axe"]; var expectedWeaponNames = ["Sword", "Axe"];
var expected_weapon_damages = [3, 5]; var expectedWeaponDamages = [3, 5];
var weps = monster.weapons!; var weps = monster.weapons!;
for (int i = 0; i < weps.length; i++) { for (int i = 0; i < weps.length; i++) {
assert(weps[i].name == expected_weapon_names[i]); assert(weps[i].name == expectedWeaponNames[i]);
assert(weps[i].damage == expected_weapon_damages[i]); assert(weps[i].damage == expectedWeaponDamages[i]);
} }
// Get and test the `Equipment` union (`equipped` field). // Get and test the `Equipment` union (`equipped` field).
assert(monster.equippedType!.value == myGame.EquipmentTypeId.Weapon.value); assert(monster.equippedType!.value == my_game.EquipmentTypeId.Weapon.value);
assert(monster.equippedType == myGame.EquipmentTypeId.Weapon); assert(monster.equippedType == my_game.EquipmentTypeId.Weapon);
assert(monster.equipped is myGame.Weapon); assert(monster.equipped is my_game.Weapon);
var equipped = monster.equipped as myGame.Weapon; var equipped = monster.equipped as my_game.Weapon;
assert(equipped.name == "Axe"); assert(equipped.name == "Axe");
assert(equipped.damage == 5); assert(equipped.damage == 5);

View File

@@ -14,7 +14,7 @@ class Color {
factory Color.fromValue(int value) { factory Color.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum Color'); throw StateError('Invalid value $value for bit flag enum Color');
} }
return result; return result;
} }
@@ -26,15 +26,15 @@ class Color {
static const int maxValue = 2; static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const Color Red = const Color._(0); static const Color Red = Color._(0);
static const Color Green = const Color._(1); static const Color Green = Color._(1);
static const Color Blue = const Color._(2); static const Color Blue = Color._(2);
static const Map<int, Color> values = { static const Map<int, Color> values = {
0: Red, 0: Red,
1: Green, 1: Green,
2: Blue}; 2: Blue};
static const fb.Reader<Color> reader = const _ColorReader(); static const fb.Reader<Color> reader = _ColorReader();
@override @override
String toString() { String toString() {
@@ -50,7 +50,7 @@ class _ColorReader extends fb.Reader<Color> {
@override @override
Color read(fb.BufferContext bc, int offset) => Color read(fb.BufferContext bc, int offset) =>
new Color.fromValue(const fb.Int8Reader().read(bc, offset)); Color.fromValue(const fb.Int8Reader().read(bc, offset));
} }
class EquipmentTypeId { class EquipmentTypeId {
@@ -60,7 +60,7 @@ class EquipmentTypeId {
factory EquipmentTypeId.fromValue(int value) { factory EquipmentTypeId.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum EquipmentTypeId'); throw StateError('Invalid value $value for bit flag enum EquipmentTypeId');
} }
return result; return result;
} }
@@ -72,13 +72,13 @@ class EquipmentTypeId {
static const int maxValue = 1; static const int maxValue = 1;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const EquipmentTypeId NONE = const EquipmentTypeId._(0); static const EquipmentTypeId NONE = EquipmentTypeId._(0);
static const EquipmentTypeId Weapon = const EquipmentTypeId._(1); static const EquipmentTypeId Weapon = EquipmentTypeId._(1);
static const Map<int, EquipmentTypeId> values = { static const Map<int, EquipmentTypeId> values = {
0: NONE, 0: NONE,
1: Weapon}; 1: Weapon};
static const fb.Reader<EquipmentTypeId> reader = const _EquipmentTypeIdReader(); static const fb.Reader<EquipmentTypeId> reader = _EquipmentTypeIdReader();
@override @override
String toString() { String toString() {
@@ -94,13 +94,13 @@ class _EquipmentTypeIdReader extends fb.Reader<EquipmentTypeId> {
@override @override
EquipmentTypeId read(fb.BufferContext bc, int offset) => EquipmentTypeId read(fb.BufferContext bc, int offset) =>
new EquipmentTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); EquipmentTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class Vec3 { class Vec3 {
Vec3._(this._bc, this._bcOffset); Vec3._(this._bc, this._bcOffset);
static const fb.Reader<Vec3> reader = const _Vec3Reader(); static const fb.Reader<Vec3> reader = _Vec3Reader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -123,11 +123,11 @@ class _Vec3Reader extends fb.StructReader<Vec3> {
@override @override
Vec3 createObject(fb.BufferContext bc, int offset) => Vec3 createObject(fb.BufferContext bc, int offset) =>
new Vec3._(bc, offset); Vec3._(bc, offset);
} }
class Vec3Builder { class Vec3Builder {
Vec3Builder(this.fbBuilder) {} Vec3Builder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -166,20 +166,19 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Monster { class Monster {
Monster._(this._bc, this._bcOffset); Monster._(this._bc, this._bcOffset);
factory Monster(List<int> bytes) { factory Monster(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Monster> reader = const _MonsterReader(); static const fb.Reader<Monster> reader = _MonsterReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -188,11 +187,11 @@ class Monster {
int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150); int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150);
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100); int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10); String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
List<int>? get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 14); List<int>? get inventory => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 14);
Color get color => Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2)); Color get color => Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
List<Weapon>? get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGetNullable(_bc, _bcOffset, 18); List<Weapon>? get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGetNullable(_bc, _bcOffset, 18);
EquipmentTypeId? get equippedType => EquipmentTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 20)); EquipmentTypeId? get equippedType => EquipmentTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 20));
dynamic? get equipped { dynamic get equipped {
switch (equippedType?.value) { switch (equippedType?.value) {
case 1: return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22); case 1: return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22);
default: return null; default: return null;
@@ -211,11 +210,11 @@ class _MonsterReader extends fb.TableReader<Monster> {
@override @override
Monster createObject(fb.BufferContext bc, int offset) => Monster createObject(fb.BufferContext bc, int offset) =>
new Monster._(bc, offset); Monster._(bc, offset);
} }
class MonsterBuilder { class MonsterBuilder {
MonsterBuilder(this.fbBuilder) {} MonsterBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -278,7 +277,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
final Color? _color; final Color? _color;
final List<WeaponObjectBuilder>? _weapons; final List<WeaponObjectBuilder>? _weapons;
final EquipmentTypeId? _equippedType; final EquipmentTypeId? _equippedType;
final dynamic? _equipped; final dynamic _equipped;
final List<Vec3ObjectBuilder>? _path; final List<Vec3ObjectBuilder>? _path;
MonsterObjectBuilder({ MonsterObjectBuilder({
@@ -290,7 +289,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
Color? color, Color? color,
List<WeaponObjectBuilder>? weapons, List<WeaponObjectBuilder>? weapons,
EquipmentTypeId? equippedType, EquipmentTypeId? equippedType,
dynamic? equipped, dynamic equipped,
List<Vec3ObjectBuilder>? path, List<Vec3ObjectBuilder>? path,
}) })
: _pos = pos, : _pos = pos,
@@ -335,20 +334,19 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Weapon { class Weapon {
Weapon._(this._bc, this._bcOffset); Weapon._(this._bc, this._bcOffset);
factory Weapon(List<int> bytes) { factory Weapon(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Weapon> reader = const _WeaponReader(); static const fb.Reader<Weapon> reader = _WeaponReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -367,11 +365,11 @@ class _WeaponReader extends fb.TableReader<Weapon> {
@override @override
Weapon createObject(fb.BufferContext bc, int offset) => Weapon createObject(fb.BufferContext bc, int offset) =>
new Weapon._(bc, offset); Weapon._(bc, offset);
} }
class WeaponBuilder { class WeaponBuilder {
WeaponBuilder(this.fbBuilder) {} WeaponBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -418,9 +416,8 @@ class WeaponObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -22,7 +22,7 @@ const int _sizeofFloat64 = 8;
/// ///
/// This callback is used by other struct's `finish` methods to write the nested /// This callback is used by other struct's `finish` methods to write the nested
/// struct's fields inline. /// struct's fields inline.
typedef void StructBuilder(); typedef StructBuilder = void Function();
/// Buffer with data and some context about it. /// Buffer with data and some context about it.
class BufferContext { class BufferContext {
@@ -143,7 +143,7 @@ class Builder {
/// true, will cause [writeString] to pool strings in the buffer so that /// true, will cause [writeString] to pool strings in the buffer so that
/// identical strings will always use the same offset in tables. /// identical strings will always use the same offset in tables.
Builder({ Builder({
this.initialSize: 1024, this.initialSize = 1024,
bool internStrings = false, bool internStrings = false,
Allocator allocator = const DefaultAllocator(), Allocator allocator = const DefaultAllocator(),
this.deduplicateTables = true, this.deduplicateTables = true,
@@ -155,8 +155,7 @@ class Builder {
} }
} }
/// Calculate the finished buffer size (aligned). /// Calculate the finished buffer size (aligned).@pragma('vm:prefer-inline')
@pragma('vm:prefer-inline')
int size() => _tail + ((-_tail) & (_maxAlign - 1)); int size() => _tail + ((-_tail) & (_maxAlign - 1));
/// Add the [field] with the given boolean [value]. The field is not added if /// Add the [field] with the given boolean [value]. The field is not added if
@@ -750,7 +749,9 @@ class Builder {
/// Zero-pads the buffer, which may be required for some struct layouts. /// Zero-pads the buffer, which may be required for some struct layouts.
@pragma('vm:prefer-inline') @pragma('vm:prefer-inline')
void pad(int howManyBytes) { void pad(int howManyBytes) {
for (int i = 0; i < howManyBytes; i++) putUint8(0); for (int i = 0; i < howManyBytes; i++) {
putUint8(0);
}
} }
/// Prepare for writing the given `count` of scalars of the given `size`. /// Prepare for writing the given `count` of scalars of the given `size`.
@@ -875,7 +876,7 @@ class Float64ListReader extends Reader<List<double>> {
@override @override
@pragma('vm:prefer-inline') @pragma('vm:prefer-inline')
List<double> read(BufferContext bc, int offset) => List<double> read(BufferContext bc, int offset) =>
new _FbFloat64List(bc, bc.derefObject(offset)); _FbFloat64List(bc, bc.derefObject(offset));
} }
class Float32ListReader extends Reader<List<double>> { class Float32ListReader extends Reader<List<double>> {
@@ -888,7 +889,7 @@ class Float32ListReader extends Reader<List<double>> {
@override @override
@pragma('vm:prefer-inline') @pragma('vm:prefer-inline')
List<double> read(BufferContext bc, int offset) => List<double> read(BufferContext bc, int offset) =>
new _FbFloat32List(bc, bc.derefObject(offset)); _FbFloat32List(bc, bc.derefObject(offset));
} }
class Float64Reader extends Reader<double> { class Float64Reader extends Reader<double> {
@@ -1034,6 +1035,7 @@ abstract class Reader<T> {
/// The reader of string values. /// The reader of string values.
class StringReader extends Reader<String> { class StringReader extends Reader<String> {
final bool asciiOptimization; final bool asciiOptimization;
const StringReader({this.asciiOptimization = false}) : super(); const StringReader({this.asciiOptimization = false}) : super();
@override @override
@@ -1071,8 +1073,9 @@ abstract class StructReader<T> extends Reader<T> {
/// Return the object at `offset`. /// Return the object at `offset`.
T createObject(BufferContext bc, int offset); T createObject(BufferContext bc, int offset);
T read(BufferContext bp, int offset) { @override
return createObject(bp, offset); T read(BufferContext bc, int offset) {
return createObject(bc, offset);
} }
} }
@@ -1088,9 +1091,9 @@ abstract class TableReader<T> extends Reader<T> {
T createObject(BufferContext bc, int offset); T createObject(BufferContext bc, int offset);
@override @override
T read(BufferContext bp, int offset) { T read(BufferContext bc, int offset) {
int objectOffset = bp.derefObject(offset); int objectOffset = bc.derefObject(offset);
return createObject(bp, objectOffset); return createObject(bc, objectOffset);
} }
} }
@@ -1249,12 +1252,11 @@ abstract class _FbList<E> extends Object with ListMixin<E> implements List<E> {
int get length => _length ??= bc._getUint32(offset); int get length => _length ??= bc._getUint32(offset);
@override @override
void set length(int i) => set length(int i) => throw StateError('Attempt to modify immutable list');
throw new StateError('Attempt to modify immutable list');
@override @override
void operator []=(int i, E e) => void operator []=(int i, E e) =>
throw new StateError('Attempt to modify immutable list'); throw StateError('Attempt to modify immutable list');
} }
/// List backed by 32-bit unsigned integers. /// List backed by 32-bit unsigned integers.
@@ -1416,7 +1418,7 @@ class DefaultAllocator extends Allocator {
ByteData allocate(int size) => ByteData(size); ByteData allocate(int size) => ByteData(size);
@override @override
void deallocate(ByteData _) { void deallocate(ByteData data) {
// nothing to do, it's garbage-collected // nothing to do, it's garbage-collected
} }
} }

View File

@@ -5,22 +5,22 @@ import 'types.dart';
/// The main builder class for creation of a FlexBuffer. /// The main builder class for creation of a FlexBuffer.
class Builder { class Builder {
ByteData _buffer; final ByteData _buffer;
List<_StackValue> _stack = []; List<_StackValue> _stack = [];
List<_StackPointer> _stackPointers = []; List<_StackPointer> _stackPointers = [];
int _offset = 0; int _offset = 0;
bool _finished = false; bool _finished = false;
Map<String, _StackValue> _stringCache = {}; final Map<String, _StackValue> _stringCache = {};
Map<String, _StackValue> _keyCache = {}; final Map<String, _StackValue> _keyCache = {};
Map<_KeysHash, _StackValue> _keyVectorCache = {}; final Map<_KeysHash, _StackValue> _keyVectorCache = {};
Map<int, _StackValue> _indirectIntCache = {}; final Map<int, _StackValue> _indirectIntCache = {};
Map<double, _StackValue> _indirectDoubleCache = {}; final Map<double, _StackValue> _indirectDoubleCache = {};
/// Instantiate the builder if you intent to gradually build up the buffer by calling /// Instantiate the builder if you intent to gradually build up the buffer by calling
/// add... methods and calling [finish] to receive the the resulting byte array. /// add... methods and calling [finish] to receive the the resulting byte array.
/// ///
/// The default size of internal buffer is set to 2048. Provide a different value in order to avoid buffer copies. /// The default size of internal buffer is set to 2048. Provide a different value in order to avoid buffer copies.
Builder({int size = 2048}) : _buffer = ByteData(size) {} Builder({int size = 2048}) : _buffer = ByteData(size);
/// Use this method in order to turn an object into a FlexBuffer directly. /// Use this method in order to turn an object into a FlexBuffer directly.
/// ///
@@ -70,25 +70,25 @@ class Builder {
/// Specifically useful when building up a vector where values can be null. /// Specifically useful when building up a vector where values can be null.
void addNull() { void addNull() {
_integrityCheckOnValueAddition(); _integrityCheckOnValueAddition();
_stack.add(_StackValue.WithNull()); _stack.add(_StackValue.withNull());
} }
/// Adds a string value. /// Adds a string value.
void addInt(int value) { void addInt(int value) {
_integrityCheckOnValueAddition(); _integrityCheckOnValueAddition();
_stack.add(_StackValue.WithInt(value)); _stack.add(_StackValue.withInt(value));
} }
/// Adds a bool value. /// Adds a bool value.
void addBool(bool value) { void addBool(bool value) {
_integrityCheckOnValueAddition(); _integrityCheckOnValueAddition();
_stack.add(_StackValue.WithBool(value)); _stack.add(_StackValue.withBool(value));
} }
/// Adds a double value. /// Adds a double value.
void addDouble(double value) { void addDouble(double value) {
_integrityCheckOnValueAddition(); _integrityCheckOnValueAddition();
_stack.add(_StackValue.WithDouble(value)); _stack.add(_StackValue.withDouble(value));
} }
/// Adds a string value. /// Adds a string value.
@@ -108,7 +108,7 @@ class Builder {
_pushBuffer(utf8String); _pushBuffer(utf8String);
_offset = newOffset; _offset = newOffset;
final stackValue = final stackValue =
_StackValue.WithOffset(stringOffset, ValueType.String, bitWidth); _StackValue.withOffset(stringOffset, ValueType.String, bitWidth);
_stack.add(stackValue); _stack.add(stackValue);
_stringCache[value] = stackValue; _stringCache[value] = stackValue;
} }
@@ -129,7 +129,7 @@ class Builder {
_pushBuffer(utf8String); _pushBuffer(utf8String);
_offset = newOffset; _offset = newOffset;
final stackValue = final stackValue =
_StackValue.WithOffset(keyOffset, ValueType.Key, BitWidth.width8); _StackValue.withOffset(keyOffset, ValueType.Key, BitWidth.width8);
_stack.add(stackValue); _stack.add(stackValue);
_keyCache[value] = stackValue; _keyCache[value] = stackValue;
} }
@@ -148,7 +148,7 @@ class Builder {
_pushBuffer(value.asUint8List()); _pushBuffer(value.asUint8List());
_offset = newOffset; _offset = newOffset;
final stackValue = final stackValue =
_StackValue.WithOffset(blobOffset, ValueType.Blob, bitWidth); _StackValue.withOffset(blobOffset, ValueType.Blob, bitWidth);
_stack.add(stackValue); _stack.add(stackValue);
} }
@@ -164,12 +164,12 @@ class Builder {
_stack.add(_indirectIntCache[value]!); _stack.add(_indirectIntCache[value]!);
return; return;
} }
final stackValue = _StackValue.WithInt(value); final stackValue = _StackValue.withInt(value);
final byteWidth = _align(stackValue.width); final byteWidth = _align(stackValue.width);
final newOffset = _newOffset(byteWidth); final newOffset = _newOffset(byteWidth);
final valueOffset = _offset; final valueOffset = _offset;
_pushBuffer(stackValue.asU8List(stackValue.width)); _pushBuffer(stackValue.asU8List(stackValue.width));
final stackOffset = _StackValue.WithOffset( final stackOffset = _StackValue.withOffset(
valueOffset, ValueType.IndirectInt, stackValue.width); valueOffset, ValueType.IndirectInt, stackValue.width);
_stack.add(stackOffset); _stack.add(stackOffset);
_offset = newOffset; _offset = newOffset;
@@ -189,12 +189,12 @@ class Builder {
_stack.add(_indirectDoubleCache[value]!); _stack.add(_indirectDoubleCache[value]!);
return; return;
} }
final stackValue = _StackValue.WithDouble(value); final stackValue = _StackValue.withDouble(value);
final byteWidth = _align(stackValue.width); final byteWidth = _align(stackValue.width);
final newOffset = _newOffset(byteWidth); final newOffset = _newOffset(byteWidth);
final valueOffset = _offset; final valueOffset = _offset;
_pushBuffer(stackValue.asU8List(stackValue.width)); _pushBuffer(stackValue.asU8List(stackValue.width));
final stackOffset = _StackValue.WithOffset( final stackOffset = _StackValue.withOffset(
valueOffset, ValueType.IndirectFloat, stackValue.width); valueOffset, ValueType.IndirectFloat, stackValue.width);
_stack.add(stackOffset); _stack.add(stackOffset);
_offset = newOffset; _offset = newOffset;
@@ -346,14 +346,14 @@ class Builder {
} }
} }
if (keys != null) { if (keys != null) {
return _StackValue.WithOffset(vecOffset, ValueType.Map, bitWidth); return _StackValue.withOffset(vecOffset, ValueType.Map, bitWidth);
} }
if (typed) { if (typed) {
final vType = final vType =
ValueTypeUtils.toTypedVector(vectorType, fix ? vecLength : 0); ValueTypeUtils.toTypedVector(vectorType, fix ? vecLength : 0);
return _StackValue.WithOffset(vecOffset, vType, bitWidth); return _StackValue.withOffset(vecOffset, vType, bitWidth);
} }
return _StackValue.WithOffset(vecOffset, ValueType.Vector, bitWidth); return _StackValue.withOffset(vecOffset, ValueType.Vector, bitWidth);
} }
void _endVector(_StackPointer pointer) { void _endVector(_StackPointer pointer) {
@@ -405,7 +405,7 @@ class Builder {
offsets.add(_stack[i].offset!); offsets.add(_stack[i].offset!);
} }
final keysHash = _KeysHash(offsets); final keysHash = _KeysHash(offsets);
var keysStackValue; _StackValue? keysStackValue;
if (_keyVectorCache.containsKey(keysHash)) { if (_keyVectorCache.containsKey(keysHash)) {
keysStackValue = _keyVectorCache[keysHash]; keysStackValue = _keyVectorCache[keysHash];
} else { } else {
@@ -424,7 +424,7 @@ class Builder {
'Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.'); 'Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.');
} }
var c1, c2; late int c1, c2;
var index = 0; var index = 0;
do { do {
c1 = _buffer.getUint8(v1.offset! + index); c1 = _buffer.getUint8(v1.offset! + index);
@@ -520,32 +520,32 @@ class Builder {
class _StackValue { class _StackValue {
late Object _value; late Object _value;
int? _offset; int? _offset;
ValueType _type; final ValueType _type;
BitWidth _width; final BitWidth _width;
_StackValue.WithNull() _StackValue.withNull()
: _type = ValueType.Null, : _type = ValueType.Null,
_width = BitWidth.width8 {} _width = BitWidth.width8;
_StackValue.WithInt(int value) _StackValue.withInt(int value)
: _type = ValueType.Int, : _type = ValueType.Int,
_width = BitWidthUtil.width(value), _width = BitWidthUtil.width(value),
_value = value {} _value = value;
_StackValue.WithBool(bool value) _StackValue.withBool(bool value)
: _type = ValueType.Bool, : _type = ValueType.Bool,
_width = BitWidth.width8, _width = BitWidth.width8,
_value = value {} _value = value;
_StackValue.WithDouble(double value) _StackValue.withDouble(double value)
: _type = ValueType.Float, : _type = ValueType.Float,
_width = BitWidthUtil.width(value), _width = BitWidthUtil.width(value),
_value = value {} _value = value;
_StackValue.WithOffset(int value, ValueType type, BitWidth width) _StackValue.withOffset(int value, ValueType type, BitWidth width)
: _offset = value, : _offset = value,
_type = type, _type = type,
_width = width {} _width = width;
BitWidth storedWidth({BitWidth width = BitWidth.width8}) { BitWidth storedWidth({BitWidth width = BitWidth.width8}) {
return ValueTypeUtils.isInline(_type) return ValueTypeUtils.isInline(_type)

View File

@@ -19,7 +19,7 @@ class Reference {
this._buffer, this._offset, this._parentWidth, int packedType, this._path, this._buffer, this._offset, this._parentWidth, int packedType, this._path,
[int? byteWidth, ValueType? valueType]) [int? byteWidth, ValueType? valueType])
: _byteWidth = byteWidth ?? 1 << (packedType & 3), : _byteWidth = byteWidth ?? 1 << (packedType & 3),
_valueType = valueType ?? ValueTypeUtils.fromInt(packedType >> 2) {} _valueType = valueType ?? ValueTypeUtils.fromInt(packedType >> 2);
/// Use this method to access the root value of a FlexBuffer. /// Use this method to access the root value of a FlexBuffer.
static Reference fromBuffer(ByteBuffer buffer) { static Reference fromBuffer(ByteBuffer buffer) {
@@ -218,13 +218,13 @@ class Reference {
_length = 0; _length = 0;
} else if (_valueType == ValueType.String) { } else if (_valueType == ValueType.String) {
final indirect = _indirect; final indirect = _indirect;
var size_byte_width = _byteWidth; var sizeByteWidth = _byteWidth;
var size = _readUInt(indirect - size_byte_width, var size = _readUInt(indirect - sizeByteWidth,
BitWidthUtil.fromByteWidth(size_byte_width)); BitWidthUtil.fromByteWidth(sizeByteWidth));
while (_buffer.getInt8(indirect + size) != 0) { while (_buffer.getInt8(indirect + size) != 0) {
size_byte_width <<= 1; sizeByteWidth <<= 1;
size = _readUInt(indirect - size_byte_width, size = _readUInt(indirect - sizeByteWidth,
BitWidthUtil.fromByteWidth(size_byte_width)); BitWidthUtil.fromByteWidth(sizeByteWidth));
} }
_length = size; _length = size;
} else if (_valueType == ValueType.Key) { } else if (_valueType == ValueType.Key) {
@@ -374,8 +374,8 @@ class Reference {
} }
int _diffKeys( int _diffKeys(
List<int> input, int index, int indirect_offset, int byteWidth) { List<int> input, int index, int indirectOffset, int byteWidth) {
final keyOffset = indirect_offset + index * byteWidth; final keyOffset = indirectOffset + index * byteWidth;
final keyIndirectOffset = final keyIndirectOffset =
keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth)); keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
for (var i = 0; i < input.length; i++) { for (var i = 0; i < input.length; i++) {

View File

@@ -47,7 +47,7 @@ class BitWidthUtil {
if (value == 8) { if (value == 8) {
return BitWidth.width64; return BitWidth.width64;
} }
throw Exception('Unexpected value ${value}'); throw Exception('Unexpected value $value');
} }
static int paddingSize(int bufSize, int scalarSize) { static int paddingSize(int bufSize, int scalarSize) {

View File

@@ -12,5 +12,6 @@ dev_dependencies:
test: ^1.17.7 test: ^1.17.7
test_reflective_loader: ^0.2.0 test_reflective_loader: ^0.2.0
path: ^1.8.0 path: ^1.8.0
lints: ^1.0.1
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'

View File

@@ -30,12 +30,12 @@ int indexToField(int index) {
@reflectiveTest @reflectiveTest
class CheckOtherLangaugesData { class CheckOtherLangaugesData {
test_cppData() async { test_cppData() async {
List<int> data = await new io.File(path.join( List<int> data = await io.File(path.join(
path.context.current, path.context.current,
'test', 'test',
'monsterdata_test.mon', 'monsterdata_test.mon',
)).readAsBytes(); )).readAsBytes();
example.Monster mon = new example.Monster(data); example.Monster mon = example.Monster(data);
expect(mon.hp, 80); expect(mon.hp, 80);
expect(mon.mana, 150); expect(mon.mana, 150);
expect(mon.name, 'MyMonster'); expect(mon.name, 'MyMonster');
@@ -156,7 +156,7 @@ class CustomAllocator extends Allocator {
@reflectiveTest @reflectiveTest
class BuilderTest { class BuilderTest {
void test_monsterBuilder([Builder? builder]) { void test_monsterBuilder([Builder? builder]) {
final fbBuilder = builder ?? new Builder(); final fbBuilder = builder ?? Builder();
final str = fbBuilder.writeString('MyMonster'); final str = fbBuilder.writeString('MyMonster');
fbBuilder.writeString('test1'); fbBuilder.writeString('test1');
@@ -168,12 +168,12 @@ class BuilderTest {
final List<int> treasure = [0, 1, 2, 3, 4]; final List<int> treasure = [0, 1, 2, 3, 4];
final inventory = fbBuilder.writeListUint8(treasure); final inventory = fbBuilder.writeListUint8(treasure);
final monBuilder = new example.MonsterBuilder(fbBuilder) final monBuilder = example.MonsterBuilder(fbBuilder)
..begin() ..begin()
..addNameOffset(fred); ..addNameOffset(fred);
final mon2 = monBuilder.finish(); final mon2 = monBuilder.finish();
final testBuilder = new example.TestBuilder(fbBuilder); final testBuilder = example.TestBuilder(fbBuilder);
testBuilder.finish(10, 20); testBuilder.finish(10, 20);
testBuilder.finish(30, 40); testBuilder.finish(30, 40);
final test4 = fbBuilder.endStructVector(2); final test4 = fbBuilder.endStructVector(2);
@@ -181,7 +181,7 @@ class BuilderTest {
monBuilder monBuilder
..begin() ..begin()
..addPos( ..addPos(
new example.Vec3Builder(fbBuilder).finish( example.Vec3Builder(fbBuilder).finish(
1.0, 1.0,
2.0, 2.0,
3.0, 3.0,
@@ -202,28 +202,28 @@ class BuilderTest {
} }
void test_error_addInt32_withoutStartTable([Builder? builder]) { void test_error_addInt32_withoutStartTable([Builder? builder]) {
builder ??= new Builder(); builder ??= Builder();
expect(() { expect(() {
builder!.addInt32(0, 0); builder!.addInt32(0, 0);
}, throwsA(isA<AssertionError>())); }, throwsA(isA<AssertionError>()));
} }
void test_error_addOffset_withoutStartTable() { void test_error_addOffset_withoutStartTable() {
Builder builder = new Builder(); Builder builder = Builder();
expect(() { expect(() {
builder.addOffset(0, 0); builder.addOffset(0, 0);
}, throwsA(isA<AssertionError>())); }, throwsA(isA<AssertionError>()));
} }
void test_error_endTable_withoutStartTable() { void test_error_endTable_withoutStartTable() {
Builder builder = new Builder(); Builder builder = Builder();
expect(() { expect(() {
builder.endTable(); builder.endTable();
}, throwsA(isA<AssertionError>())); }, throwsA(isA<AssertionError>()));
} }
void test_error_startTable_duringTable() { void test_error_startTable_duringTable() {
Builder builder = new Builder(); Builder builder = Builder();
builder.startTable(0); builder.startTable(0);
expect(() { expect(() {
builder.startTable(0); builder.startTable(0);
@@ -231,7 +231,7 @@ class BuilderTest {
} }
void test_error_writeString_duringTable() { void test_error_writeString_duringTable() {
Builder builder = new Builder(); Builder builder = Builder();
builder.startTable(1); builder.startTable(1);
expect(() { expect(() {
builder.writeString('12345'); builder.writeString('12345');
@@ -241,7 +241,7 @@ class BuilderTest {
void test_file_identifier() { void test_file_identifier() {
Uint8List byteList; Uint8List byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
builder.startTable(0); builder.startTable(0);
int offset = builder.endTable(); int offset = builder.endTable();
builder.finish(offset, 'Az~ÿ'); builder.finish(offset, 'Az~ÿ');
@@ -307,7 +307,7 @@ class BuilderTest {
expect(builder.size(), byteList.length); expect(builder.size(), byteList.length);
} }
// read and verify // read and verify
BufferContext buffer = new BufferContext.fromBytes(byteList); BufferContext buffer = BufferContext.fromBytes(byteList);
int objectOffset = buffer.derefObject(0); int objectOffset = buffer.derefObject(0);
// was not written, so uses the new default value // was not written, so uses the new default value
expect( expect(
@@ -324,7 +324,7 @@ class BuilderTest {
void test_table_format([Builder? builder]) { void test_table_format([Builder? builder]) {
Uint8List byteList; Uint8List byteList;
{ {
builder ??= new Builder(initialSize: 0); builder ??= Builder(initialSize: 0);
builder.startTable(3); builder.startTable(3);
builder.addInt32(0, 10); builder.addInt32(0, 10);
builder.addInt32(1, 20); builder.addInt32(1, 20);
@@ -359,7 +359,7 @@ class BuilderTest {
String unicodeString = 'Проба пера'; String unicodeString = 'Проба пера';
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int? latinStringOffset = int? latinStringOffset =
builder.writeString(latinString, asciiOptimization: true); builder.writeString(latinString, asciiOptimization: true);
int? unicodeStringOffset = int? unicodeStringOffset =
@@ -372,7 +372,7 @@ class BuilderTest {
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
int objectOffset = buf.derefObject(0); int objectOffset = buf.derefObject(0);
expect( expect(
const StringReader() const StringReader()
@@ -387,7 +387,7 @@ class BuilderTest {
void test_table_types([Builder? builder]) { void test_table_types([Builder? builder]) {
List<int> byteList; List<int> byteList;
{ {
builder ??= new Builder(initialSize: 0); builder ??= Builder(initialSize: 0);
int? stringOffset = builder.writeString('12345'); int? stringOffset = builder.writeString('12345');
builder.startTable(7); builder.startTable(7);
builder.addBool(0, true); builder.addBool(0, true);
@@ -402,7 +402,7 @@ class BuilderTest {
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
int objectOffset = buf.derefObject(0); int objectOffset = buf.derefObject(0);
expect( expect(
const BoolReader() const BoolReader()
@@ -439,13 +439,13 @@ class BuilderTest {
// write // write
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int offset = builder.writeListUint32(values); int offset = builder.writeListUint32(values);
builder.finish(offset); builder.finish(offset);
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<int> items = const Uint32ListReader().read(buf, 0); List<int> items = const Uint32ListReader().read(buf, 0);
expect(items, hasLength(4)); expect(items, hasLength(4));
expect(items, orderedEquals(values)); expect(items, orderedEquals(values));
@@ -456,8 +456,8 @@ class BuilderTest {
// write // write
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
List<bool> values = new List<bool>.filled(len, false); List<bool> values = List<bool>.filled(len, false);
for (int bit in trueBits) { for (int bit in trueBits) {
values[bit] = true; values[bit] = true;
} }
@@ -466,7 +466,7 @@ class BuilderTest {
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<bool> items = const BoolListReader().read(buf, 0); List<bool> items = const BoolListReader().read(buf, 0);
expect(items, hasLength(len)); expect(items, hasLength(len));
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
@@ -485,26 +485,26 @@ class BuilderTest {
verifyListBooleans(33, <int>[1, 2, 24, 25, 31, 32]); verifyListBooleans(33, <int>[1, 2, 24, 25, 31, 32]);
verifyListBooleans(63, <int>[]); verifyListBooleans(63, <int>[]);
verifyListBooleans(63, <int>[0, 1, 2, 61, 62]); verifyListBooleans(63, <int>[0, 1, 2, 61, 62]);
verifyListBooleans(63, new List<int>.generate(63, (i) => i)); verifyListBooleans(63, List<int>.generate(63, (i) => i));
verifyListBooleans(64, <int>[]); verifyListBooleans(64, <int>[]);
verifyListBooleans(64, <int>[0, 1, 2, 61, 62, 63]); verifyListBooleans(64, <int>[0, 1, 2, 61, 62, 63]);
verifyListBooleans(64, <int>[1, 2, 62]); verifyListBooleans(64, <int>[1, 2, 62]);
verifyListBooleans(64, <int>[0, 1, 2, 63]); verifyListBooleans(64, <int>[0, 1, 2, 63]);
verifyListBooleans(64, new List<int>.generate(64, (i) => i)); verifyListBooleans(64, List<int>.generate(64, (i) => i));
verifyListBooleans(100, <int>[0, 3, 30, 60, 90, 99]); verifyListBooleans(100, <int>[0, 3, 30, 60, 90, 99]);
} }
void test_writeList_ofInt32() { void test_writeList_ofInt32() {
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int offset = builder.writeListInt32(<int>[1, 2, 3, 4, 5]); int offset = builder.writeListInt32(<int>[1, 2, 3, 4, 5]);
builder.finish(offset); builder.finish(offset);
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<int> items = const ListReader<int>(const Int32Reader()).read(buf, 0); List<int> items = const ListReader<int>(Int32Reader()).read(buf, 0);
expect(items, hasLength(5)); expect(items, hasLength(5));
expect(items, orderedEquals(<int>[1, 2, 3, 4, 5])); expect(items, orderedEquals(<int>[1, 2, 3, 4, 5]));
} }
@@ -514,14 +514,14 @@ class BuilderTest {
// write // write
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int offset = builder.writeListFloat64(values); int offset = builder.writeListFloat64(values);
builder.finish(offset); builder.finish(offset);
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<double> items = const Float64ListReader().read(buf, 0); List<double> items = const Float64ListReader().read(buf, 0);
expect(items, hasLength(values.length)); expect(items, hasLength(values.length));
@@ -535,13 +535,13 @@ class BuilderTest {
// write // write
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int offset = builder.writeListFloat32(values); int offset = builder.writeListFloat32(values);
builder.finish(offset); builder.finish(offset);
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<double> items = const Float32ListReader().read(buf, 0); List<double> items = const Float32ListReader().read(buf, 0);
expect(items, hasLength(5)); expect(items, hasLength(5));
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
@@ -552,7 +552,7 @@ class BuilderTest {
void test_writeList_ofObjects([Builder? builder]) { void test_writeList_ofObjects([Builder? builder]) {
List<int> byteList; List<int> byteList;
{ {
builder ??= new Builder(initialSize: 0); builder ??= Builder(initialSize: 0);
// write the object #1 // write the object #1
int object1; int object1;
{ {
@@ -575,9 +575,9 @@ class BuilderTest {
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<TestPointImpl> items = List<TestPointImpl> items =
const ListReader<TestPointImpl>(const TestPointReader()).read(buf, 0); const ListReader<TestPointImpl>(TestPointReader()).read(buf, 0);
expect(items, hasLength(2)); expect(items, hasLength(2));
expect(items[0].x, 10); expect(items[0].x, 10);
expect(items[0].y, 20); expect(items[0].y, 20);
@@ -588,7 +588,7 @@ class BuilderTest {
void test_writeList_ofStrings_asRoot() { void test_writeList_ofStrings_asRoot() {
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int? str1 = builder.writeString('12345'); int? str1 = builder.writeString('12345');
int? str2 = builder.writeString('ABC'); int? str2 = builder.writeString('ABC');
int offset = builder.writeList([str1, str2]); int offset = builder.writeList([str1, str2]);
@@ -596,9 +596,8 @@ class BuilderTest {
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<String> items = List<String> items = const ListReader<String>(StringReader()).read(buf, 0);
const ListReader<String>(const StringReader()).read(buf, 0);
expect(items, hasLength(2)); expect(items, hasLength(2));
expect(items, contains('12345')); expect(items, contains('12345'));
expect(items, contains('ABC')); expect(items, contains('ABC'));
@@ -607,7 +606,7 @@ class BuilderTest {
void test_writeList_ofStrings_inObject([Builder? builder]) { void test_writeList_ofStrings_inObject([Builder? builder]) {
List<int> byteList; List<int> byteList;
{ {
builder ??= new Builder(initialSize: 0); builder ??= Builder(initialSize: 0);
int listOffset = builder.writeList( int listOffset = builder.writeList(
[builder.writeString('12345'), builder.writeString('ABC')]); [builder.writeString('12345'), builder.writeString('ABC')]);
builder.startTable(1); builder.startTable(1);
@@ -617,8 +616,8 @@ class BuilderTest {
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
StringListWrapperImpl reader = new StringListWrapperReader().read(buf, 0); StringListWrapperImpl reader = StringListWrapperReader().read(buf, 0);
List<String>? items = reader.items; List<String>? items = reader.items;
expect(items, hasLength(2)); expect(items, hasLength(2));
expect(items, contains('12345')); expect(items, contains('12345'));
@@ -628,13 +627,13 @@ class BuilderTest {
void test_writeList_ofUint32() { void test_writeList_ofUint32() {
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int offset = builder.writeListUint32(<int>[1, 2, 0x9ABCDEF0]); int offset = builder.writeListUint32(<int>[1, 2, 0x9ABCDEF0]);
builder.finish(offset); builder.finish(offset);
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<int> items = const Uint32ListReader().read(buf, 0); List<int> items = const Uint32ListReader().read(buf, 0);
expect(items, hasLength(3)); expect(items, hasLength(3));
expect(items, orderedEquals(<int>[1, 2, 0x9ABCDEF0])); expect(items, orderedEquals(<int>[1, 2, 0x9ABCDEF0]));
@@ -643,13 +642,13 @@ class BuilderTest {
void test_writeList_ofUint16() { void test_writeList_ofUint16() {
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int offset = builder.writeListUint16(<int>[1, 2, 60000]); int offset = builder.writeListUint16(<int>[1, 2, 60000]);
builder.finish(offset); builder.finish(offset);
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<int> items = const Uint16ListReader().read(buf, 0); List<int> items = const Uint16ListReader().read(buf, 0);
expect(items, hasLength(3)); expect(items, hasLength(3));
expect(items, orderedEquals(<int>[1, 2, 60000])); expect(items, orderedEquals(<int>[1, 2, 60000]));
@@ -658,13 +657,13 @@ class BuilderTest {
void test_writeList_ofUint8() { void test_writeList_ofUint8() {
List<int> byteList; List<int> byteList;
{ {
Builder builder = new Builder(initialSize: 0); Builder builder = Builder(initialSize: 0);
int offset = builder.writeListUint8(<int>[1, 2, 3, 4, 0x9A]); int offset = builder.writeListUint8(<int>[1, 2, 3, 4, 0x9A]);
builder.finish(offset); builder.finish(offset);
byteList = builder.buffer; byteList = builder.buffer;
} }
// read and verify // read and verify
BufferContext buf = new BufferContext.fromBytes(byteList); BufferContext buf = BufferContext.fromBytes(byteList);
List<int> items = const Uint8ListReader().read(buf, 0); List<int> items = const Uint8ListReader().read(buf, 0);
expect(items, hasLength(5)); expect(items, hasLength(5));
expect(items, orderedEquals(<int>[1, 2, 3, 4, 0x9A])); expect(items, orderedEquals(<int>[1, 2, 3, 4, 0x9A]));
@@ -687,22 +686,22 @@ class BuilderTest {
_permutationsOf(List.generate(testCases.length, (index) => index)); _permutationsOf(List.generate(testCases.length, (index) => index));
expect(testCasesPermutations.length, _factorial(testCases.length)); expect(testCasesPermutations.length, _factorial(testCases.length));
testCasesPermutations.forEach((List<int> indexes) { for (var indexes in testCasesPermutations) {
// print the order so failures are reproducible // print the order so failures are reproducible
printOnFailure('Running reset() test cases in order: $indexes'); printOnFailure('Running reset() test cases in order: $indexes');
Builder? builder; Builder? builder;
indexes.forEach((index) { for (var index in indexes) {
if (builder == null) { if (builder == null) {
// Initial size small enough so at least one test case increases it. // Initial size small enough so at least one test case increases it.
// On the other hand, it's large enough so that some test cases don't. // On the other hand, it's large enough so that some test cases don't.
builder = Builder(initialSize: 32); builder = Builder(initialSize: 32);
} else { } else {
builder!.reset(); builder.reset();
} }
testCases[index](builder); testCases[index](builder);
}); }
}); }
} }
// Generate permutations of the given list // Generate permutations of the given list
@@ -731,7 +730,9 @@ class BuilderTest {
// a very simple implementation of n! // a very simple implementation of n!
int _factorial(int n) { int _factorial(int n) {
var result = 1; var result = 1;
for (var i = 2; i <= n; i++) result *= i; for (var i = 2; i <= n; i++) {
result *= i;
}
return result; return result;
} }
} }
@@ -836,7 +837,7 @@ class StringListWrapperImpl {
StringListWrapperImpl(this.bp, this.offset); StringListWrapperImpl(this.bp, this.offset);
List<String>? get items => const ListReader<String>(const StringReader()) List<String>? get items => const ListReader<String>(StringReader())
.vTableGetNullable(bp, offset, indexToField(0)); .vTableGetNullable(bp, offset, indexToField(0));
} }
@@ -845,7 +846,7 @@ class StringListWrapperReader extends TableReader<StringListWrapperImpl> {
@override @override
StringListWrapperImpl createObject(BufferContext object, int offset) { StringListWrapperImpl createObject(BufferContext object, int offset) {
return new StringListWrapperImpl(object, offset); return StringListWrapperImpl(object, offset);
} }
} }
@@ -865,7 +866,7 @@ class TestPointReader extends TableReader<TestPointImpl> {
@override @override
TestPointImpl createObject(BufferContext object, int offset) { TestPointImpl createObject(BufferContext object, int offset) {
return new TestPointImpl(object, offset); return TestPointImpl(object, offset);
} }
} }

View File

@@ -12,11 +12,11 @@ import './monster_test_my_game.example_generated.dart' as my_game_example;
class Monster { class Monster {
Monster._(this._bc, this._bcOffset); Monster._(this._bc, this._bcOffset);
factory Monster(List<int> bytes) { factory Monster(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Monster> reader = const _MonsterReader(); static const fb.Reader<Monster> reader = _MonsterReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -52,7 +52,7 @@ class _MonsterReader extends fb.TableReader<Monster> {
@override @override
Monster createObject(fb.BufferContext bc, int offset) => Monster createObject(fb.BufferContext bc, int offset) =>
new Monster._(bc, offset); Monster._(bc, offset);
} }
class MonsterObjectBuilder extends fb.ObjectBuilder { class MonsterObjectBuilder extends fb.ObjectBuilder {
@@ -69,9 +69,8 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -17,7 +17,7 @@ class Color {
factory Color.fromValue(int value) { factory Color.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum Color'); throw StateError('Invalid value $value for bit flag enum Color');
} }
return result; return result;
} }
@@ -27,20 +27,20 @@ class Color {
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const Color Red = const Color._(1); static const Color Red = Color._(1);
/// \brief color Green /// \brief color Green
/// Green is bit_flag with value (1u << 1) /// Green is bit_flag with value (1u << 1)
static const Color Green = const Color._(2); static const Color Green = Color._(2);
/// \brief color Blue (1u << 3) /// \brief color Blue (1u << 3)
static const Color Blue = const Color._(8); static const Color Blue = Color._(8);
static const Map<int, Color> values = { static const Map<int, Color> values = {
1: Red, 1: Red,
2: Green, 2: Green,
8: Blue}; 8: Blue};
static const fb.Reader<Color> reader = const _ColorReader(); static const fb.Reader<Color> reader = _ColorReader();
@override @override
String toString() { String toString() {
@@ -56,7 +56,7 @@ class _ColorReader extends fb.Reader<Color> {
@override @override
Color read(fb.BufferContext bc, int offset) => Color read(fb.BufferContext bc, int offset) =>
new Color.fromValue(const fb.Uint8Reader().read(bc, offset)); Color.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class Race { class Race {
@@ -66,7 +66,7 @@ class Race {
factory Race.fromValue(int value) { factory Race.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum Race'); throw StateError('Invalid value $value for bit flag enum Race');
} }
return result; return result;
} }
@@ -78,17 +78,17 @@ class Race {
static const int maxValue = 2; static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const Race None = const Race._(-1); static const Race None = Race._(-1);
static const Race Human = const Race._(0); static const Race Human = Race._(0);
static const Race Dwarf = const Race._(1); static const Race Dwarf = Race._(1);
static const Race Elf = const Race._(2); static const Race Elf = Race._(2);
static const Map<int, Race> values = { static const Map<int, Race> values = {
-1: None, -1: None,
0: Human, 0: Human,
1: Dwarf, 1: Dwarf,
2: Elf}; 2: Elf};
static const fb.Reader<Race> reader = const _RaceReader(); static const fb.Reader<Race> reader = _RaceReader();
@override @override
String toString() { String toString() {
@@ -104,7 +104,7 @@ class _RaceReader extends fb.Reader<Race> {
@override @override
Race read(fb.BufferContext bc, int offset) => Race read(fb.BufferContext bc, int offset) =>
new Race.fromValue(const fb.Int8Reader().read(bc, offset)); Race.fromValue(const fb.Int8Reader().read(bc, offset));
} }
class AnyTypeId { class AnyTypeId {
@@ -114,7 +114,7 @@ class AnyTypeId {
factory AnyTypeId.fromValue(int value) { factory AnyTypeId.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum AnyTypeId'); throw StateError('Invalid value $value for bit flag enum AnyTypeId');
} }
return result; return result;
} }
@@ -126,17 +126,17 @@ class AnyTypeId {
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const AnyTypeId NONE = const AnyTypeId._(0); static const AnyTypeId NONE = AnyTypeId._(0);
static const AnyTypeId Monster = const AnyTypeId._(1); static const AnyTypeId Monster = AnyTypeId._(1);
static const AnyTypeId TestSimpleTableWithEnum = const AnyTypeId._(2); static const AnyTypeId TestSimpleTableWithEnum = AnyTypeId._(2);
static const AnyTypeId MyGame_Example2_Monster = const AnyTypeId._(3); static const AnyTypeId MyGame_Example2_Monster = AnyTypeId._(3);
static const Map<int, AnyTypeId> values = { static const Map<int, AnyTypeId> values = {
0: NONE, 0: NONE,
1: Monster, 1: Monster,
2: TestSimpleTableWithEnum, 2: TestSimpleTableWithEnum,
3: MyGame_Example2_Monster}; 3: MyGame_Example2_Monster};
static const fb.Reader<AnyTypeId> reader = const _AnyTypeIdReader(); static const fb.Reader<AnyTypeId> reader = _AnyTypeIdReader();
@override @override
String toString() { String toString() {
@@ -152,7 +152,7 @@ class _AnyTypeIdReader extends fb.Reader<AnyTypeId> {
@override @override
AnyTypeId read(fb.BufferContext bc, int offset) => AnyTypeId read(fb.BufferContext bc, int offset) =>
new AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class AnyUniqueAliasesTypeId { class AnyUniqueAliasesTypeId {
@@ -162,7 +162,7 @@ class AnyUniqueAliasesTypeId {
factory AnyUniqueAliasesTypeId.fromValue(int value) { factory AnyUniqueAliasesTypeId.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId'); throw StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId');
} }
return result; return result;
} }
@@ -174,17 +174,17 @@ class AnyUniqueAliasesTypeId {
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const AnyUniqueAliasesTypeId NONE = const AnyUniqueAliasesTypeId._(0); static const AnyUniqueAliasesTypeId NONE = AnyUniqueAliasesTypeId._(0);
static const AnyUniqueAliasesTypeId M = const AnyUniqueAliasesTypeId._(1); static const AnyUniqueAliasesTypeId M = AnyUniqueAliasesTypeId._(1);
static const AnyUniqueAliasesTypeId TS = const AnyUniqueAliasesTypeId._(2); static const AnyUniqueAliasesTypeId TS = AnyUniqueAliasesTypeId._(2);
static const AnyUniqueAliasesTypeId M2 = const AnyUniqueAliasesTypeId._(3); static const AnyUniqueAliasesTypeId M2 = AnyUniqueAliasesTypeId._(3);
static const Map<int, AnyUniqueAliasesTypeId> values = { static const Map<int, AnyUniqueAliasesTypeId> values = {
0: NONE, 0: NONE,
1: M, 1: M,
2: TS, 2: TS,
3: M2}; 3: M2};
static const fb.Reader<AnyUniqueAliasesTypeId> reader = const _AnyUniqueAliasesTypeIdReader(); static const fb.Reader<AnyUniqueAliasesTypeId> reader = _AnyUniqueAliasesTypeIdReader();
@override @override
String toString() { String toString() {
@@ -200,7 +200,7 @@ class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> {
@override @override
AnyUniqueAliasesTypeId read(fb.BufferContext bc, int offset) => AnyUniqueAliasesTypeId read(fb.BufferContext bc, int offset) =>
new AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class AnyAmbiguousAliasesTypeId { class AnyAmbiguousAliasesTypeId {
@@ -210,7 +210,7 @@ class AnyAmbiguousAliasesTypeId {
factory AnyAmbiguousAliasesTypeId.fromValue(int value) { factory AnyAmbiguousAliasesTypeId.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId'); throw StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId');
} }
return result; return result;
} }
@@ -222,17 +222,17 @@ class AnyAmbiguousAliasesTypeId {
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const AnyAmbiguousAliasesTypeId NONE = const AnyAmbiguousAliasesTypeId._(0); static const AnyAmbiguousAliasesTypeId NONE = AnyAmbiguousAliasesTypeId._(0);
static const AnyAmbiguousAliasesTypeId M1 = const AnyAmbiguousAliasesTypeId._(1); static const AnyAmbiguousAliasesTypeId M1 = AnyAmbiguousAliasesTypeId._(1);
static const AnyAmbiguousAliasesTypeId M2 = const AnyAmbiguousAliasesTypeId._(2); static const AnyAmbiguousAliasesTypeId M2 = AnyAmbiguousAliasesTypeId._(2);
static const AnyAmbiguousAliasesTypeId M3 = const AnyAmbiguousAliasesTypeId._(3); static const AnyAmbiguousAliasesTypeId M3 = AnyAmbiguousAliasesTypeId._(3);
static const Map<int, AnyAmbiguousAliasesTypeId> values = { static const Map<int, AnyAmbiguousAliasesTypeId> values = {
0: NONE, 0: NONE,
1: M1, 1: M1,
2: M2, 2: M2,
3: M3}; 3: M3};
static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = const _AnyAmbiguousAliasesTypeIdReader(); static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = _AnyAmbiguousAliasesTypeIdReader();
@override @override
String toString() { String toString() {
@@ -248,13 +248,13 @@ class _AnyAmbiguousAliasesTypeIdReader extends fb.Reader<AnyAmbiguousAliasesType
@override @override
AnyAmbiguousAliasesTypeId read(fb.BufferContext bc, int offset) => AnyAmbiguousAliasesTypeId read(fb.BufferContext bc, int offset) =>
new AnyAmbiguousAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyAmbiguousAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class Test { class Test {
Test._(this._bc, this._bcOffset); Test._(this._bc, this._bcOffset);
static const fb.Reader<Test> reader = const _TestReader(); static const fb.Reader<Test> reader = _TestReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -306,11 +306,11 @@ class _TestReader extends fb.StructReader<Test> {
@override @override
Test createObject(fb.BufferContext bc, int offset) => Test createObject(fb.BufferContext bc, int offset) =>
new Test._(bc, offset); Test._(bc, offset);
} }
class TestBuilder { class TestBuilder {
TestBuilder(this.fbBuilder) {} TestBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -346,20 +346,19 @@ class TestObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class TestSimpleTableWithEnum { class TestSimpleTableWithEnum {
TestSimpleTableWithEnum._(this._bc, this._bcOffset); TestSimpleTableWithEnum._(this._bc, this._bcOffset);
factory TestSimpleTableWithEnum(List<int> bytes) { factory TestSimpleTableWithEnum(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<TestSimpleTableWithEnum> reader = const _TestSimpleTableWithEnumReader(); static const fb.Reader<TestSimpleTableWithEnum> reader = _TestSimpleTableWithEnumReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -403,11 +402,11 @@ class _TestSimpleTableWithEnumReader extends fb.TableReader<TestSimpleTableWithE
@override @override
TestSimpleTableWithEnum createObject(fb.BufferContext bc, int offset) => TestSimpleTableWithEnum createObject(fb.BufferContext bc, int offset) =>
new TestSimpleTableWithEnum._(bc, offset); TestSimpleTableWithEnum._(bc, offset);
} }
class TestSimpleTableWithEnumBuilder { class TestSimpleTableWithEnumBuilder {
TestSimpleTableWithEnumBuilder(this.fbBuilder) {} TestSimpleTableWithEnumBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -444,16 +443,15 @@ class TestSimpleTableWithEnumObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Vec3 { class Vec3 {
Vec3._(this._bc, this._bcOffset); Vec3._(this._bc, this._bcOffset);
static const fb.Reader<Vec3> reader = const _Vec3Reader(); static const fb.Reader<Vec3> reader = _Vec3Reader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -527,11 +525,11 @@ class _Vec3Reader extends fb.StructReader<Vec3> {
@override @override
Vec3 createObject(fb.BufferContext bc, int offset) => Vec3 createObject(fb.BufferContext bc, int offset) =>
new Vec3._(bc, offset); Vec3._(bc, offset);
} }
class Vec3Builder { class Vec3Builder {
Vec3Builder(this.fbBuilder) {} Vec3Builder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -591,16 +589,15 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Ability { class Ability {
Ability._(this._bc, this._bcOffset); Ability._(this._bc, this._bcOffset);
static const fb.Reader<Ability> reader = const _AbilityReader(); static const fb.Reader<Ability> reader = _AbilityReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -651,11 +648,11 @@ class _AbilityReader extends fb.StructReader<Ability> {
@override @override
Ability createObject(fb.BufferContext bc, int offset) => Ability createObject(fb.BufferContext bc, int offset) =>
new Ability._(bc, offset); Ability._(bc, offset);
} }
class AbilityBuilder { class AbilityBuilder {
AbilityBuilder(this.fbBuilder) {} AbilityBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -689,16 +686,15 @@ class AbilityObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class StructOfStructs { class StructOfStructs {
StructOfStructs._(this._bc, this._bcOffset); StructOfStructs._(this._bc, this._bcOffset);
static const fb.Reader<StructOfStructs> reader = const _StructOfStructsReader(); static const fb.Reader<StructOfStructs> reader = _StructOfStructsReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -754,11 +750,11 @@ class _StructOfStructsReader extends fb.StructReader<StructOfStructs> {
@override @override
StructOfStructs createObject(fb.BufferContext bc, int offset) => StructOfStructs createObject(fb.BufferContext bc, int offset) =>
new StructOfStructs._(bc, offset); StructOfStructs._(bc, offset);
} }
class StructOfStructsBuilder { class StructOfStructsBuilder {
StructOfStructsBuilder(this.fbBuilder) {} StructOfStructsBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -797,20 +793,19 @@ class StructOfStructsObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Stat { class Stat {
Stat._(this._bc, this._bcOffset); Stat._(this._bc, this._bcOffset);
factory Stat(List<int> bytes) { factory Stat(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Stat> reader = const _StatReader(); static const fb.Reader<Stat> reader = _StatReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -866,11 +861,11 @@ class _StatReader extends fb.TableReader<Stat> {
@override @override
Stat createObject(fb.BufferContext bc, int offset) => Stat createObject(fb.BufferContext bc, int offset) =>
new Stat._(bc, offset); Stat._(bc, offset);
} }
class StatBuilder { class StatBuilder {
StatBuilder(this.fbBuilder) {} StatBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -925,20 +920,19 @@ class StatObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Referrable { class Referrable {
Referrable._(this._bc, this._bcOffset); Referrable._(this._bc, this._bcOffset);
factory Referrable(List<int> bytes) { factory Referrable(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Referrable> reader = const _ReferrableReader(); static const fb.Reader<Referrable> reader = _ReferrableReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -982,11 +976,11 @@ class _ReferrableReader extends fb.TableReader<Referrable> {
@override @override
Referrable createObject(fb.BufferContext bc, int offset) => Referrable createObject(fb.BufferContext bc, int offset) =>
new Referrable._(bc, offset); Referrable._(bc, offset);
} }
class ReferrableBuilder { class ReferrableBuilder {
ReferrableBuilder(this.fbBuilder) {} ReferrableBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -1023,9 +1017,8 @@ class ReferrableObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
@@ -1033,11 +1026,11 @@ class ReferrableObjectBuilder extends fb.ObjectBuilder {
class Monster { class Monster {
Monster._(this._bc, this._bcOffset); Monster._(this._bc, this._bcOffset);
factory Monster(List<int> bytes) { factory Monster(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Monster> reader = const _MonsterReader(); static const fb.Reader<Monster> reader = _MonsterReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -1046,10 +1039,10 @@ class Monster {
int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150); int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150);
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100); int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10); String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
List<int>? get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 14); List<int>? get inventory => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 14);
Color get color => Color.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 16, 8)); Color get color => Color.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 16, 8));
AnyTypeId? get testType => AnyTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 18)); AnyTypeId? get testType => AnyTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 18));
dynamic? get test { dynamic get test {
switch (testType?.value) { switch (testType?.value) {
case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 20); case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 20);
case 2: return TestSimpleTableWithEnum.reader.vTableGetNullable(_bc, _bcOffset, 20); case 2: return TestSimpleTableWithEnum.reader.vTableGetNullable(_bc, _bcOffset, 20);
@@ -1058,12 +1051,12 @@ class Monster {
} }
} }
List<Test>? get test4 => const fb.ListReader<Test>(Test.reader).vTableGetNullable(_bc, _bcOffset, 22); List<Test>? get test4 => const fb.ListReader<Test>(Test.reader).vTableGetNullable(_bc, _bcOffset, 22);
List<String>? get testarrayofstring => const fb.ListReader<String>(const fb.StringReader()).vTableGetNullable(_bc, _bcOffset, 24); List<String>? get testarrayofstring => const fb.ListReader<String>(fb.StringReader()).vTableGetNullable(_bc, _bcOffset, 24);
/// an example documentation comment: this will end up in the generated code /// an example documentation comment: this will end up in the generated code
/// multiline too /// multiline too
List<Monster>? get testarrayoftables => const fb.ListReader<Monster>(Monster.reader).vTableGetNullable(_bc, _bcOffset, 26); List<Monster>? get testarrayoftables => const fb.ListReader<Monster>(Monster.reader).vTableGetNullable(_bc, _bcOffset, 26);
Monster? get enemy => Monster.reader.vTableGetNullable(_bc, _bcOffset, 28); Monster? get enemy => Monster.reader.vTableGetNullable(_bc, _bcOffset, 28);
List<int>? get testnestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 30); List<int>? get testnestedflatbuffer => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 30);
Stat? get testempty => Stat.reader.vTableGetNullable(_bc, _bcOffset, 32); Stat? get testempty => Stat.reader.vTableGetNullable(_bc, _bcOffset, 32);
bool get testbool => const fb.BoolReader().vTableGet(_bc, _bcOffset, 34, false); bool get testbool => const fb.BoolReader().vTableGet(_bc, _bcOffset, 34, false);
int get testhashs32Fnv1 => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 36, 0); int get testhashs32Fnv1 => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 36, 0);
@@ -1074,27 +1067,27 @@ class Monster {
int get testhashu32Fnv1a => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 46, 0); int get testhashu32Fnv1a => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 46, 0);
int get testhashs64Fnv1a => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 48, 0); int get testhashs64Fnv1a => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 48, 0);
int get testhashu64Fnv1a => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 50, 0); int get testhashu64Fnv1a => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 50, 0);
List<bool>? get testarrayofbools => const fb.ListReader<bool>(const fb.BoolReader()).vTableGetNullable(_bc, _bcOffset, 52); List<bool>? get testarrayofbools => const fb.ListReader<bool>(fb.BoolReader()).vTableGetNullable(_bc, _bcOffset, 52);
double get testf => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 54, 3.14159); double get testf => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 54, 3.14159);
double get testf2 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 56, 3.0); double get testf2 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 56, 3.0);
double get testf3 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 58, 0.0); double get testf3 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 58, 0.0);
List<String>? get testarrayofstring2 => const fb.ListReader<String>(const fb.StringReader()).vTableGetNullable(_bc, _bcOffset, 60); List<String>? get testarrayofstring2 => const fb.ListReader<String>(fb.StringReader()).vTableGetNullable(_bc, _bcOffset, 60);
List<Ability>? get testarrayofsortedstruct => const fb.ListReader<Ability>(Ability.reader).vTableGetNullable(_bc, _bcOffset, 62); List<Ability>? get testarrayofsortedstruct => const fb.ListReader<Ability>(Ability.reader).vTableGetNullable(_bc, _bcOffset, 62);
List<int>? get flex => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 64); List<int>? get flex => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 64);
List<Test>? get test5 => const fb.ListReader<Test>(Test.reader).vTableGetNullable(_bc, _bcOffset, 66); List<Test>? get test5 => const fb.ListReader<Test>(Test.reader).vTableGetNullable(_bc, _bcOffset, 66);
List<int>? get vectorOfLongs => const fb.ListReader<int>(const fb.Int64Reader()).vTableGetNullable(_bc, _bcOffset, 68); List<int>? get vectorOfLongs => const fb.ListReader<int>(fb.Int64Reader()).vTableGetNullable(_bc, _bcOffset, 68);
List<double>? get vectorOfDoubles => const fb.ListReader<double>(const fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 70); List<double>? get vectorOfDoubles => const fb.ListReader<double>(fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 70);
my_game.InParentNamespace? get parentNamespaceTest => my_game.InParentNamespace.reader.vTableGetNullable(_bc, _bcOffset, 72); my_game.InParentNamespace? get parentNamespaceTest => my_game.InParentNamespace.reader.vTableGetNullable(_bc, _bcOffset, 72);
List<Referrable>? get vectorOfReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGetNullable(_bc, _bcOffset, 74); List<Referrable>? get vectorOfReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGetNullable(_bc, _bcOffset, 74);
int get singleWeakReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 76, 0); int get singleWeakReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 76, 0);
List<int>? get vectorOfWeakReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 78); List<int>? get vectorOfWeakReferences => const fb.ListReader<int>(fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 78);
List<Referrable>? get vectorOfStrongReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGetNullable(_bc, _bcOffset, 80); List<Referrable>? get vectorOfStrongReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGetNullable(_bc, _bcOffset, 80);
int get coOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 82, 0); int get coOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 82, 0);
List<int>? get vectorOfCoOwningReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 84); List<int>? get vectorOfCoOwningReferences => const fb.ListReader<int>(fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 84);
int get nonOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 86, 0); int get nonOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 86, 0);
List<int>? get vectorOfNonOwningReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 88); List<int>? get vectorOfNonOwningReferences => const fb.ListReader<int>(fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 88);
AnyUniqueAliasesTypeId? get anyUniqueType => AnyUniqueAliasesTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 90)); AnyUniqueAliasesTypeId? get anyUniqueType => AnyUniqueAliasesTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 90));
dynamic? get anyUnique { dynamic get anyUnique {
switch (anyUniqueType?.value) { switch (anyUniqueType?.value) {
case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 92); case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 92);
case 2: return TestSimpleTableWithEnum.reader.vTableGetNullable(_bc, _bcOffset, 92); case 2: return TestSimpleTableWithEnum.reader.vTableGetNullable(_bc, _bcOffset, 92);
@@ -1103,7 +1096,7 @@ class Monster {
} }
} }
AnyAmbiguousAliasesTypeId? get anyAmbiguousType => AnyAmbiguousAliasesTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 94)); AnyAmbiguousAliasesTypeId? get anyAmbiguousType => AnyAmbiguousAliasesTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 94));
dynamic? get anyAmbiguous { dynamic get anyAmbiguous {
switch (anyAmbiguousType?.value) { switch (anyAmbiguousType?.value) {
case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 96); case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 96);
case 2: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 96); case 2: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 96);
@@ -1113,7 +1106,7 @@ class Monster {
} }
List<Color>? get vectorOfEnums => const fb.ListReader<Color>(Color.reader).vTableGetNullable(_bc, _bcOffset, 98); List<Color>? get vectorOfEnums => const fb.ListReader<Color>(Color.reader).vTableGetNullable(_bc, _bcOffset, 98);
Race get signedEnum => Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1)); Race get signedEnum => Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1));
List<int>? get testrequirednestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 102); List<int>? get testrequirednestedflatbuffer => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 102);
List<Stat>? get scalarKeySortedTables => const fb.ListReader<Stat>(Stat.reader).vTableGetNullable(_bc, _bcOffset, 104); List<Stat>? get scalarKeySortedTables => const fb.ListReader<Stat>(Stat.reader).vTableGetNullable(_bc, _bcOffset, 104);
@override @override
@@ -1126,15 +1119,15 @@ class Monster {
mana: mana, mana: mana,
hp: hp, hp: hp,
name: name, name: name,
inventory: const fb.ListReader<int>(const fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 14), inventory: const fb.ListReader<int>(fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 14),
color: color, color: color,
testType: testType, testType: testType,
test: test, test: test,
test4: test4?.map((e) => e.unpack()).toList(), test4: test4?.map((e) => e.unpack()).toList(),
testarrayofstring: const fb.ListReader<String>(const 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(),
enemy: enemy?.unpack(), enemy: enemy?.unpack(),
testnestedflatbuffer: const fb.ListReader<int>(const fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 30), testnestedflatbuffer: const fb.ListReader<int>(fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 30),
testempty: testempty?.unpack(), testempty: testempty?.unpack(),
testbool: testbool, testbool: testbool,
testhashs32Fnv1: testhashs32Fnv1, testhashs32Fnv1: testhashs32Fnv1,
@@ -1145,32 +1138,32 @@ class Monster {
testhashu32Fnv1a: testhashu32Fnv1a, testhashu32Fnv1a: testhashu32Fnv1a,
testhashs64Fnv1a: testhashs64Fnv1a, testhashs64Fnv1a: testhashs64Fnv1a,
testhashu64Fnv1a: testhashu64Fnv1a, testhashu64Fnv1a: testhashu64Fnv1a,
testarrayofbools: const fb.ListReader<bool>(const fb.BoolReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 52), testarrayofbools: const fb.ListReader<bool>(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>(const fb.StringReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 60), testarrayofstring2: const fb.ListReader<String>(fb.StringReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 60),
testarrayofsortedstruct: testarrayofsortedstruct?.map((e) => e.unpack()).toList(), testarrayofsortedstruct: testarrayofsortedstruct?.map((e) => e.unpack()).toList(),
flex: const fb.ListReader<int>(const fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 64), flex: const fb.ListReader<int>(fb.Uint8Reader(), 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>(const fb.Int64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 68), vectorOfLongs: const fb.ListReader<int>(fb.Int64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 68),
vectorOfDoubles: const fb.ListReader<double>(const fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 70), 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>(const fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 78), vectorOfWeakReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 78),
vectorOfStrongReferrables: vectorOfStrongReferrables?.map((e) => e.unpack()).toList(), vectorOfStrongReferrables: vectorOfStrongReferrables?.map((e) => e.unpack()).toList(),
coOwningReference: coOwningReference, coOwningReference: coOwningReference,
vectorOfCoOwningReferences: const fb.ListReader<int>(const fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 84), vectorOfCoOwningReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 84),
nonOwningReference: nonOwningReference, nonOwningReference: nonOwningReference,
vectorOfNonOwningReferences: const fb.ListReader<int>(const 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,
anyAmbiguousType: anyAmbiguousType, anyAmbiguousType: anyAmbiguousType,
anyAmbiguous: anyAmbiguous, anyAmbiguous: anyAmbiguous,
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.ListReader<int>(const fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 102), testrequirednestedflatbuffer: const fb.ListReader<int>(fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 102),
scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList()); scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList());
static int pack(fb.Builder fbBuilder, MonsterT? object) { static int pack(fb.Builder fbBuilder, MonsterT? object) {
@@ -1188,7 +1181,7 @@ class MonsterT {
List<int>? inventory; List<int>? inventory;
Color color; Color color;
AnyTypeId? testType; AnyTypeId? testType;
dynamic? test; dynamic test;
List<TestT>? test4; List<TestT>? test4;
List<String>? testarrayofstring; List<String>? testarrayofstring;
/// an example documentation comment: this will end up in the generated code /// an example documentation comment: this will end up in the generated code
@@ -1226,9 +1219,9 @@ class MonsterT {
int nonOwningReference; int nonOwningReference;
List<int>? vectorOfNonOwningReferences; List<int>? vectorOfNonOwningReferences;
AnyUniqueAliasesTypeId? anyUniqueType; AnyUniqueAliasesTypeId? anyUniqueType;
dynamic? anyUnique; dynamic anyUnique;
AnyAmbiguousAliasesTypeId? anyAmbiguousType; AnyAmbiguousAliasesTypeId? anyAmbiguousType;
dynamic? anyAmbiguous; dynamic anyAmbiguous;
List<Color>? vectorOfEnums; List<Color>? vectorOfEnums;
Race signedEnum; Race signedEnum;
List<int>? testrequirednestedflatbuffer; List<int>? testrequirednestedflatbuffer;
@@ -1292,9 +1285,9 @@ class MonsterT {
final int? inventoryOffset = inventory == null ? null final int? inventoryOffset = inventory == null ? null
: fbBuilder.writeListUint8(inventory!); : fbBuilder.writeListUint8(inventory!);
final int? testOffset = test?.pack(fbBuilder); final int? testOffset = test?.pack(fbBuilder);
int? test4Offset = null; int? test4Offset;
if (test4 != null) { if (test4 != null) {
test4!.forEach((e) => e.pack(fbBuilder)); for (var e in test4!) { e.pack(fbBuilder); }
test4Offset = fbBuilder.endStructVector(test4!.length); test4Offset = fbBuilder.endStructVector(test4!.length);
} }
final int? testarrayofstringOffset = testarrayofstring == null ? null final int? testarrayofstringOffset = testarrayofstring == null ? null
@@ -1309,16 +1302,16 @@ class MonsterT {
: fbBuilder.writeListBool(testarrayofbools!); : fbBuilder.writeListBool(testarrayofbools!);
final int? testarrayofstring2Offset = testarrayofstring2 == null ? null final int? testarrayofstring2Offset = testarrayofstring2 == null ? null
: fbBuilder.writeList(testarrayofstring2!.map(fbBuilder.writeString).toList()); : fbBuilder.writeList(testarrayofstring2!.map(fbBuilder.writeString).toList());
int? testarrayofsortedstructOffset = null; int? testarrayofsortedstructOffset;
if (testarrayofsortedstruct != null) { if (testarrayofsortedstruct != null) {
testarrayofsortedstruct!.forEach((e) => e.pack(fbBuilder)); for (var e in testarrayofsortedstruct!) { e.pack(fbBuilder); }
testarrayofsortedstructOffset = fbBuilder.endStructVector(testarrayofsortedstruct!.length); testarrayofsortedstructOffset = fbBuilder.endStructVector(testarrayofsortedstruct!.length);
} }
final int? flexOffset = flex == null ? null final int? flexOffset = flex == null ? null
: fbBuilder.writeListUint8(flex!); : fbBuilder.writeListUint8(flex!);
int? test5Offset = null; int? test5Offset;
if (test5 != null) { if (test5 != null) {
test5!.forEach((e) => e.pack(fbBuilder)); for (var e in test5!) { e.pack(fbBuilder); }
test5Offset = fbBuilder.endStructVector(test5!.length); test5Offset = fbBuilder.endStructVector(test5!.length);
} }
final int? vectorOfLongsOffset = vectorOfLongs == null ? null final int? vectorOfLongsOffset = vectorOfLongs == null ? null
@@ -1411,11 +1404,11 @@ class _MonsterReader extends fb.TableReader<Monster> {
@override @override
Monster createObject(fb.BufferContext bc, int offset) => Monster createObject(fb.BufferContext bc, int offset) =>
new Monster._(bc, offset); Monster._(bc, offset);
} }
class MonsterBuilder { class MonsterBuilder {
MonsterBuilder(this.fbBuilder) {} MonsterBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -1637,7 +1630,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
final List<int>? _inventory; final List<int>? _inventory;
final Color? _color; final Color? _color;
final AnyTypeId? _testType; final AnyTypeId? _testType;
final dynamic? _test; final dynamic _test;
final List<TestObjectBuilder>? _test4; final List<TestObjectBuilder>? _test4;
final List<String>? _testarrayofstring; final List<String>? _testarrayofstring;
final List<MonsterObjectBuilder>? _testarrayoftables; final List<MonsterObjectBuilder>? _testarrayoftables;
@@ -1673,9 +1666,9 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
final int? _nonOwningReference; final int? _nonOwningReference;
final List<int>? _vectorOfNonOwningReferences; final List<int>? _vectorOfNonOwningReferences;
final AnyUniqueAliasesTypeId? _anyUniqueType; final AnyUniqueAliasesTypeId? _anyUniqueType;
final dynamic? _anyUnique; final dynamic _anyUnique;
final AnyAmbiguousAliasesTypeId? _anyAmbiguousType; final AnyAmbiguousAliasesTypeId? _anyAmbiguousType;
final dynamic? _anyAmbiguous; final dynamic _anyAmbiguous;
final List<Color>? _vectorOfEnums; final List<Color>? _vectorOfEnums;
final Race? _signedEnum; final Race? _signedEnum;
final List<int>? _testrequirednestedflatbuffer; final List<int>? _testrequirednestedflatbuffer;
@@ -1689,7 +1682,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
List<int>? inventory, List<int>? inventory,
Color? color, Color? color,
AnyTypeId? testType, AnyTypeId? testType,
dynamic? test, dynamic test,
List<TestObjectBuilder>? test4, List<TestObjectBuilder>? test4,
List<String>? testarrayofstring, List<String>? testarrayofstring,
List<MonsterObjectBuilder>? testarrayoftables, List<MonsterObjectBuilder>? testarrayoftables,
@@ -1725,9 +1718,9 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
int? nonOwningReference, int? nonOwningReference,
List<int>? vectorOfNonOwningReferences, List<int>? vectorOfNonOwningReferences,
AnyUniqueAliasesTypeId? anyUniqueType, AnyUniqueAliasesTypeId? anyUniqueType,
dynamic? anyUnique, dynamic anyUnique,
AnyAmbiguousAliasesTypeId? anyAmbiguousType, AnyAmbiguousAliasesTypeId? anyAmbiguousType,
dynamic? anyAmbiguous, dynamic anyAmbiguous,
List<Color>? vectorOfEnums, List<Color>? vectorOfEnums,
Race? signedEnum, Race? signedEnum,
List<int>? testrequirednestedflatbuffer, List<int>? testrequirednestedflatbuffer,
@@ -1894,20 +1887,19 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class TypeAliases { class TypeAliases {
TypeAliases._(this._bc, this._bcOffset); TypeAliases._(this._bc, this._bcOffset);
factory TypeAliases(List<int> bytes) { factory TypeAliases(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<TypeAliases> reader = const _TypeAliasesReader(); static const fb.Reader<TypeAliases> reader = _TypeAliasesReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -1922,8 +1914,8 @@ class TypeAliases {
int get u64 => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 18, 0); int get u64 => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 18, 0);
double get f32 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 20, 0.0); double get f32 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 20, 0.0);
double get f64 => const fb.Float64Reader().vTableGet(_bc, _bcOffset, 22, 0.0); double get f64 => const fb.Float64Reader().vTableGet(_bc, _bcOffset, 22, 0.0);
List<int>? get v8 => const fb.ListReader<int>(const fb.Int8Reader()).vTableGetNullable(_bc, _bcOffset, 24); List<int>? get v8 => const fb.ListReader<int>(fb.Int8Reader()).vTableGetNullable(_bc, _bcOffset, 24);
List<double>? get vf64 => const fb.ListReader<double>(const fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 26); List<double>? get vf64 => const fb.ListReader<double>(fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 26);
@override @override
String toString() { String toString() {
@@ -1941,8 +1933,8 @@ class TypeAliases {
u64: u64, u64: u64,
f32: f32, f32: f32,
f64: f64, f64: f64,
v8: const fb.ListReader<int>(const fb.Int8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 24), v8: const fb.ListReader<int>(fb.Int8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 24),
vf64: const fb.ListReader<double>(const fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 26)); 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) {
if (object == null) return 0; if (object == null) return 0;
@@ -2010,11 +2002,11 @@ class _TypeAliasesReader extends fb.TableReader<TypeAliases> {
@override @override
TypeAliases createObject(fb.BufferContext bc, int offset) => TypeAliases createObject(fb.BufferContext bc, int offset) =>
new TypeAliases._(bc, offset); TypeAliases._(bc, offset);
} }
class TypeAliasesBuilder { class TypeAliasesBuilder {
TypeAliasesBuilder(this.fbBuilder) {} TypeAliasesBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -2143,9 +2135,8 @@ class TypeAliasesObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -12,11 +12,11 @@ import './monster_test_my_game.example2_generated.dart' as my_game_example2;
class InParentNamespace { class InParentNamespace {
InParentNamespace._(this._bc, this._bcOffset); InParentNamespace._(this._bc, this._bcOffset);
factory InParentNamespace(List<int> bytes) { factory InParentNamespace(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<InParentNamespace> reader = const _InParentNamespaceReader(); static const fb.Reader<InParentNamespace> reader = _InParentNamespaceReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -52,7 +52,7 @@ class _InParentNamespaceReader extends fb.TableReader<InParentNamespace> {
@override @override
InParentNamespace createObject(fb.BufferContext bc, int offset) => InParentNamespace createObject(fb.BufferContext bc, int offset) =>
new InParentNamespace._(bc, offset); InParentNamespace._(bc, offset);
} }
class InParentNamespaceObjectBuilder extends fb.ObjectBuilder { class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
@@ -69,9 +69,8 @@ class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -233,8 +233,7 @@ class DartGenerator : public BaseGenerator {
code += " factory " + name + ".fromValue(int value) {\n"; code += " factory " + name + ".fromValue(int value) {\n";
code += " final result = values[value];\n"; code += " final result = values[value];\n";
code += " if (result == null) {\n"; code += " if (result == null) {\n";
code += code += " throw StateError('Invalid value $value for bit flag enum ";
" throw new StateError('Invalid value $value for bit flag enum ";
code += name + "');\n"; code += name + "');\n";
code += " }\n"; code += " }\n";
@@ -265,8 +264,8 @@ class DartGenerator : public BaseGenerator {
if (it != enum_def.Vals().begin()) { code += '\n'; } if (it != enum_def.Vals().begin()) { code += '\n'; }
GenDocComment(ev.doc_comment, &code, "", " "); GenDocComment(ev.doc_comment, &code, "", " ");
} }
code += " static const " + name + " " + ev.name + " = "; code += " static const " + name + " " + ev.name + " = " + name + "._(" +
code += "const " + name + "._(" + enum_def.ToString(ev) + ");\n"; enum_def.ToString(ev) + ");\n";
} }
code += " static const Map<int, " + name + "> values = {\n"; code += " static const Map<int, " + name + "> values = {\n";
@@ -277,8 +276,8 @@ class DartGenerator : public BaseGenerator {
} }
code += "};\n\n"; code += "};\n\n";
code += " static const " + _kFb + ".Reader<" + name + code += " static const " + _kFb + ".Reader<" + name + "> reader = _" +
"> reader = const _" + name + "Reader();\n\n"; name + "Reader();\n\n";
code += " @override\n"; code += " @override\n";
code += " String toString() {\n"; code += " String toString() {\n";
code += " return '" + name + "{value: $value}';\n"; code += " return '" + name + "{value: $value}';\n";
@@ -301,7 +300,7 @@ class DartGenerator : public BaseGenerator {
code += " @override\n"; code += " @override\n";
code += code +=
" " + name + " read(" + _kFb + ".BufferContext bc, int offset) =>\n"; " " + name + " read(" + _kFb + ".BufferContext bc, int offset) =>\n";
code += " new " + name + ".fromValue(const " + _kFb + "." + code += " " + name + ".fromValue(const " + _kFb + "." +
GenType(enum_def.underlying_type) + "Reader().read(bc, offset));\n"; GenType(enum_def.underlying_type) + "Reader().read(bc, offset));\n";
code += "}\n\n"; code += "}\n\n";
} }
@@ -330,24 +329,25 @@ class DartGenerator : public BaseGenerator {
std::string GenReaderTypeName(const Type &type, Namespace *current_namespace, std::string GenReaderTypeName(const Type &type, Namespace *current_namespace,
const FieldDef &def, const FieldDef &def,
bool parent_is_vector = false, bool parent_is_vector = false, bool lazy = true,
bool lazy = true) { bool constConstruct = true) {
std::string prefix = (constConstruct ? "const " : "") + _kFb;
if (type.base_type == BASE_TYPE_BOOL) { if (type.base_type == BASE_TYPE_BOOL) {
return "const " + _kFb + ".BoolReader()"; return prefix + ".BoolReader()";
} else if (IsVector(type)) { } else if (IsVector(type)) {
return "const " + _kFb + ".ListReader<" + return prefix + ".ListReader<" +
GenDartTypeName(type.VectorType(), current_namespace, def) + ">(" + GenDartTypeName(type.VectorType(), current_namespace, def) + ">(" +
GenReaderTypeName(type.VectorType(), current_namespace, def, GenReaderTypeName(type.VectorType(), current_namespace, def, true,
true) + true, false) +
(lazy ? ")" : ", lazy: false)"); (lazy ? ")" : ", lazy: false)");
} else if (IsString(type)) { } else if (IsString(type)) {
return "const " + _kFb + ".StringReader()"; return prefix + ".StringReader()";
} }
if (IsScalar(type.base_type)) { if (IsScalar(type.base_type)) {
if (type.enum_def && parent_is_vector) { if (type.enum_def && parent_is_vector) {
return GenDartTypeName(type, current_namespace, def) + ".reader"; return GenDartTypeName(type, current_namespace, def) + ".reader";
} }
return "const " + _kFb + "." + GenType(type) + "Reader()"; return prefix + "." + GenType(type) + "Reader()";
} else { } else {
return GenDartTypeName(type, current_namespace, def) + ".reader"; return GenDartTypeName(type, current_namespace, def) + ".reader";
} }
@@ -391,6 +391,15 @@ class DartGenerator : public BaseGenerator {
} }
} }
std::string GenDartTypeName(const Type &type, Namespace *current_namespace,
const FieldDef &def, bool nullable,
std::string struct_type_suffix) {
std::string typeName =
GenDartTypeName(type, current_namespace, def, struct_type_suffix);
if (nullable && typeName != "dynamic") typeName += "?";
return typeName;
}
static const std::string MaybeWrapNamespace(const std::string &type_name, static const std::string MaybeWrapNamespace(const std::string &type_name,
Namespace *current_ns, Namespace *current_ns,
const FieldDef &field) { const FieldDef &field) {
@@ -436,15 +445,15 @@ class DartGenerator : public BaseGenerator {
code += " " + object_name + "._(this._bc, this._bcOffset);\n"; code += " " + object_name + "._(this._bc, this._bcOffset);\n";
if (!struct_def.fixed) { if (!struct_def.fixed) {
code += " factory " + object_name + "(List<int> bytes) {\n"; code += " factory " + object_name + "(List<int> bytes) {\n";
code += " " + _kFb + ".BufferContext rootRef = new " + _kFb + code +=
".BufferContext.fromBytes(bytes);\n"; " final rootRef = " + _kFb + ".BufferContext.fromBytes(bytes);\n";
code += " return reader.read(rootRef, 0);\n"; code += " return reader.read(rootRef, 0);\n";
code += " }\n"; code += " }\n";
} }
code += "\n"; code += "\n";
code += " static const " + _kFb + ".Reader<" + object_name + code += " static const " + _kFb + ".Reader<" + object_name +
"> reader = const " + reader_name + "();\n\n"; "> reader = " + reader_name + "();\n\n";
code += " final " + _kFb + ".BufferContext _bc;\n"; code += " final " + _kFb + ".BufferContext _bc;\n";
code += " final int _bcOffset;\n\n"; code += " final int _bcOffset;\n\n";
@@ -504,14 +513,13 @@ class DartGenerator : public BaseGenerator {
const FieldDef &field = *it->second; const FieldDef &field = *it->second;
std::string field_name = MakeCamel(field.name, false); std::string field_name = MakeCamel(field.name, false);
std::string type_name = GenDartTypeName(
field.value.type, struct_def.defined_namespace, field, "T");
std::string defaultValue = getDefaultValue(field.value); std::string defaultValue = getDefaultValue(field.value);
bool isNullable = defaultValue.empty() && !struct_def.fixed; std::string type_name =
GenDartTypeName(field.value.type, struct_def.defined_namespace, field,
defaultValue.empty() && !struct_def.fixed, "T");
GenDocComment(field.doc_comment, &code, "", " "); GenDocComment(field.doc_comment, &code, "", " ");
code += " " + type_name + (isNullable ? "? " : " ") + field_name + ";\n"; code += " " + type_name + " " + field_name + ";\n";
if (!constructor_args.empty()) constructor_args += ",\n"; if (!constructor_args.empty()) constructor_args += ",\n";
constructor_args += " "; constructor_args += " ";
@@ -648,15 +656,15 @@ class DartGenerator : public BaseGenerator {
auto &field = *pair.second; auto &field = *pair.second;
std::string field_name = MakeCamel(field.name, false); std::string field_name = MakeCamel(field.name, false);
std::string type_name = GenDartTypeName(
field.value.type, struct_def.defined_namespace, field);
GenDocComment(field.doc_comment, &code, "", " ");
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 type_name =
GenDartTypeName(field.value.type, struct_def.defined_namespace, field,
isNullable, "");
code += " " + type_name + (isNullable ? "?" : ""); GenDocComment(field.doc_comment, &code, "", " ");
code += " get " + field_name;
code += " " + type_name + " get " + field_name;
if (field.value.type.base_type == BASE_TYPE_UNION) { if (field.value.type.base_type == BASE_TYPE_UNION) {
code += " {\n"; code += " {\n";
code += " switch (" + field_name + "Type?.value) {\n"; code += " switch (" + field_name + "Type?.value) {\n";
@@ -773,7 +781,7 @@ class DartGenerator : public BaseGenerator {
} }
code += " @override\n"; code += " @override\n";
code += " " + impl_name + code += " " + impl_name +
" createObject(fb.BufferContext bc, int offset) => \n new " + " createObject(fb.BufferContext bc, int offset) => \n " +
impl_name + "._(bc, offset);\n"; impl_name + "._(bc, offset);\n";
code += "}\n\n"; code += "}\n\n";
} }
@@ -786,7 +794,7 @@ class DartGenerator : public BaseGenerator {
auto &builder_name = *builder_name_ptr; auto &builder_name = *builder_name_ptr;
code += "class " + builder_name + " {\n"; code += "class " + builder_name + " {\n";
code += " " + builder_name + "(this.fbBuilder) {}\n\n"; code += " " + builder_name + "(this.fbBuilder);\n\n";
code += " final " + _kFb + ".Builder fbBuilder;\n\n"; code += " final " + _kFb + ".Builder fbBuilder;\n\n";
if (struct_def.fixed) { if (struct_def.fixed) {
@@ -904,9 +912,8 @@ class DartGenerator : public BaseGenerator {
code += " final " + code += " final " +
GenDartTypeName(field.value.type, struct_def.defined_namespace, GenDartTypeName(field.value.type, struct_def.defined_namespace,
field, "ObjectBuilder") + field, !struct_def.fixed, "ObjectBuilder") +
(struct_def.fixed ? "" : "?") + " _" + " _" + MakeCamel(field.name, false) + ";\n";
MakeCamel(field.name, false) + ";\n";
} }
code += "\n"; code += "\n";
code += " " + builder_name + "("; code += " " + builder_name + "(";
@@ -921,9 +928,8 @@ class DartGenerator : public BaseGenerator {
code += " "; code += " ";
code += (struct_def.fixed ? "required " : "") + code += (struct_def.fixed ? "required " : "") +
GenDartTypeName(field.value.type, struct_def.defined_namespace, GenDartTypeName(field.value.type, struct_def.defined_namespace,
field, "ObjectBuilder") + field, !struct_def.fixed, "ObjectBuilder") +
(struct_def.fixed ? "" : "?") + " " + " " + MakeCamel(field.name, false) + ",\n";
MakeCamel(field.name, false) + ",\n";
} }
code += " })\n"; code += " })\n";
code += " : "; code += " : ";
@@ -953,10 +959,9 @@ class DartGenerator : public BaseGenerator {
code += " /// Convenience method to serialize to byte list.\n"; code += " /// Convenience method to serialize to byte list.\n";
code += " @override\n"; code += " @override\n";
code += " Uint8List toBytes([String? fileIdentifier]) {\n"; code += " Uint8List toBytes([String? fileIdentifier]) {\n";
code += " " + _kFb + ".Builder fbBuilder = new "; code += " final fbBuilder = " + _kFb +
code += _kFb + ".Builder(deduplicateTables: false);\n"; ".Builder(deduplicateTables: false);\n";
code += " int offset = finish(fbBuilder);\n"; code += " fbBuilder.finish(finish(fbBuilder), fileIdentifier);\n";
code += " fbBuilder.finish(offset, fileIdentifier);\n";
code += " return fbBuilder.buffer;\n"; code += " return fbBuilder.buffer;\n";
code += " }\n"; code += " }\n";
code += "}\n"; code += "}\n";
@@ -982,10 +987,10 @@ class DartGenerator : public BaseGenerator {
if (pack && IsVector(field.value.type) && if (pack && IsVector(field.value.type) &&
field.value.type.VectorType().base_type == BASE_TYPE_STRUCT && field.value.type.VectorType().base_type == BASE_TYPE_STRUCT &&
field.value.type.struct_def->fixed) { field.value.type.struct_def->fixed) {
code += " int? " + offset_name + " = null;\n"; code += " int? " + offset_name + ";\n";
code += " if (" + field_name + " != null) {\n"; code += " if (" + field_name + " != null) {\n";
code += code +=
" " + field_name + "!.forEach((e) => e.pack(fbBuilder));\n"; " for (var e in " + field_name + "!) { e.pack(fbBuilder); }\n";
code += " " + MakeCamel(field.name, false) + code += " " + MakeCamel(field.name, false) +
"Offset = fbBuilder.endStructVector(" + field_name + "Offset = fbBuilder.endStructVector(" + field_name +
"!.length);\n"; "!.length);\n";

View File

@@ -10,11 +10,11 @@ import 'package:flat_buffers/flat_buffers.dart' as fb;
class MonsterExtra { class MonsterExtra {
MonsterExtra._(this._bc, this._bcOffset); MonsterExtra._(this._bc, this._bcOffset);
factory MonsterExtra(List<int> bytes) { factory MonsterExtra(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<MonsterExtra> reader = const _MonsterExtraReader(); static const fb.Reader<MonsterExtra> reader = _MonsterExtraReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -27,8 +27,8 @@ class MonsterExtra {
double get f1 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 14, double.nan); double get f1 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 14, double.nan);
double get f2 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 16, double.infinity); double get f2 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 16, double.infinity);
double get f3 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 18, double.negativeInfinity); double get f3 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 18, double.negativeInfinity);
List<double>? get dvec => const fb.ListReader<double>(const fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 20); List<double>? get dvec => const fb.ListReader<double>(fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 20);
List<double>? get fvec => const fb.ListReader<double>(const fb.Float32Reader()).vTableGetNullable(_bc, _bcOffset, 22); List<double>? get fvec => const fb.ListReader<double>(fb.Float32Reader()).vTableGetNullable(_bc, _bcOffset, 22);
@override @override
String toString() { String toString() {
@@ -44,8 +44,8 @@ class MonsterExtra {
f1: f1, f1: f1,
f2: f2, f2: f2,
f3: f3, f3: f3,
dvec: const fb.ListReader<double>(const fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 20), dvec: const fb.ListReader<double>(fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 20),
fvec: const fb.ListReader<double>(const fb.Float32Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 22)); fvec: const fb.ListReader<double>(fb.Float32Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 22));
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;
@@ -107,11 +107,11 @@ class _MonsterExtraReader extends fb.TableReader<MonsterExtra> {
@override @override
MonsterExtra createObject(fb.BufferContext bc, int offset) => MonsterExtra createObject(fb.BufferContext bc, int offset) =>
new MonsterExtra._(bc, offset); MonsterExtra._(bc, offset);
} }
class MonsterExtraBuilder { class MonsterExtraBuilder {
MonsterExtraBuilder(this.fbBuilder) {} MonsterExtraBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -224,9 +224,8 @@ class MonsterExtraObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -12,11 +12,11 @@ import './monster_test_my_game.example_generated.dart' as my_game_example;
class Monster { class Monster {
Monster._(this._bc, this._bcOffset); Monster._(this._bc, this._bcOffset);
factory Monster(List<int> bytes) { factory Monster(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Monster> reader = const _MonsterReader(); static const fb.Reader<Monster> reader = _MonsterReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -52,7 +52,7 @@ class _MonsterReader extends fb.TableReader<Monster> {
@override @override
Monster createObject(fb.BufferContext bc, int offset) => Monster createObject(fb.BufferContext bc, int offset) =>
new Monster._(bc, offset); Monster._(bc, offset);
} }
class MonsterObjectBuilder extends fb.ObjectBuilder { class MonsterObjectBuilder extends fb.ObjectBuilder {
@@ -69,9 +69,8 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -17,7 +17,7 @@ class Color {
factory Color.fromValue(int value) { factory Color.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum Color'); throw StateError('Invalid value $value for bit flag enum Color');
} }
return result; return result;
} }
@@ -27,20 +27,20 @@ class Color {
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const Color Red = const Color._(1); static const Color Red = Color._(1);
/// \brief color Green /// \brief color Green
/// Green is bit_flag with value (1u << 1) /// Green is bit_flag with value (1u << 1)
static const Color Green = const Color._(2); static const Color Green = Color._(2);
/// \brief color Blue (1u << 3) /// \brief color Blue (1u << 3)
static const Color Blue = const Color._(8); static const Color Blue = Color._(8);
static const Map<int, Color> values = { static const Map<int, Color> values = {
1: Red, 1: Red,
2: Green, 2: Green,
8: Blue}; 8: Blue};
static const fb.Reader<Color> reader = const _ColorReader(); static const fb.Reader<Color> reader = _ColorReader();
@override @override
String toString() { String toString() {
@@ -56,7 +56,7 @@ class _ColorReader extends fb.Reader<Color> {
@override @override
Color read(fb.BufferContext bc, int offset) => Color read(fb.BufferContext bc, int offset) =>
new Color.fromValue(const fb.Uint8Reader().read(bc, offset)); Color.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class Race { class Race {
@@ -66,7 +66,7 @@ class Race {
factory Race.fromValue(int value) { factory Race.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum Race'); throw StateError('Invalid value $value for bit flag enum Race');
} }
return result; return result;
} }
@@ -78,17 +78,17 @@ class Race {
static const int maxValue = 2; static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const Race None = const Race._(-1); static const Race None = Race._(-1);
static const Race Human = const Race._(0); static const Race Human = Race._(0);
static const Race Dwarf = const Race._(1); static const Race Dwarf = Race._(1);
static const Race Elf = const Race._(2); static const Race Elf = Race._(2);
static const Map<int, Race> values = { static const Map<int, Race> values = {
-1: None, -1: None,
0: Human, 0: Human,
1: Dwarf, 1: Dwarf,
2: Elf}; 2: Elf};
static const fb.Reader<Race> reader = const _RaceReader(); static const fb.Reader<Race> reader = _RaceReader();
@override @override
String toString() { String toString() {
@@ -104,7 +104,7 @@ class _RaceReader extends fb.Reader<Race> {
@override @override
Race read(fb.BufferContext bc, int offset) => Race read(fb.BufferContext bc, int offset) =>
new Race.fromValue(const fb.Int8Reader().read(bc, offset)); Race.fromValue(const fb.Int8Reader().read(bc, offset));
} }
class AnyTypeId { class AnyTypeId {
@@ -114,7 +114,7 @@ class AnyTypeId {
factory AnyTypeId.fromValue(int value) { factory AnyTypeId.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum AnyTypeId'); throw StateError('Invalid value $value for bit flag enum AnyTypeId');
} }
return result; return result;
} }
@@ -126,17 +126,17 @@ class AnyTypeId {
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const AnyTypeId NONE = const AnyTypeId._(0); static const AnyTypeId NONE = AnyTypeId._(0);
static const AnyTypeId Monster = const AnyTypeId._(1); static const AnyTypeId Monster = AnyTypeId._(1);
static const AnyTypeId TestSimpleTableWithEnum = const AnyTypeId._(2); static const AnyTypeId TestSimpleTableWithEnum = AnyTypeId._(2);
static const AnyTypeId MyGame_Example2_Monster = const AnyTypeId._(3); static const AnyTypeId MyGame_Example2_Monster = AnyTypeId._(3);
static const Map<int, AnyTypeId> values = { static const Map<int, AnyTypeId> values = {
0: NONE, 0: NONE,
1: Monster, 1: Monster,
2: TestSimpleTableWithEnum, 2: TestSimpleTableWithEnum,
3: MyGame_Example2_Monster}; 3: MyGame_Example2_Monster};
static const fb.Reader<AnyTypeId> reader = const _AnyTypeIdReader(); static const fb.Reader<AnyTypeId> reader = _AnyTypeIdReader();
@override @override
String toString() { String toString() {
@@ -152,7 +152,7 @@ class _AnyTypeIdReader extends fb.Reader<AnyTypeId> {
@override @override
AnyTypeId read(fb.BufferContext bc, int offset) => AnyTypeId read(fb.BufferContext bc, int offset) =>
new AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class AnyUniqueAliasesTypeId { class AnyUniqueAliasesTypeId {
@@ -162,7 +162,7 @@ class AnyUniqueAliasesTypeId {
factory AnyUniqueAliasesTypeId.fromValue(int value) { factory AnyUniqueAliasesTypeId.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId'); throw StateError('Invalid value $value for bit flag enum AnyUniqueAliasesTypeId');
} }
return result; return result;
} }
@@ -174,17 +174,17 @@ class AnyUniqueAliasesTypeId {
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const AnyUniqueAliasesTypeId NONE = const AnyUniqueAliasesTypeId._(0); static const AnyUniqueAliasesTypeId NONE = AnyUniqueAliasesTypeId._(0);
static const AnyUniqueAliasesTypeId M = const AnyUniqueAliasesTypeId._(1); static const AnyUniqueAliasesTypeId M = AnyUniqueAliasesTypeId._(1);
static const AnyUniqueAliasesTypeId TS = const AnyUniqueAliasesTypeId._(2); static const AnyUniqueAliasesTypeId TS = AnyUniqueAliasesTypeId._(2);
static const AnyUniqueAliasesTypeId M2 = const AnyUniqueAliasesTypeId._(3); static const AnyUniqueAliasesTypeId M2 = AnyUniqueAliasesTypeId._(3);
static const Map<int, AnyUniqueAliasesTypeId> values = { static const Map<int, AnyUniqueAliasesTypeId> values = {
0: NONE, 0: NONE,
1: M, 1: M,
2: TS, 2: TS,
3: M2}; 3: M2};
static const fb.Reader<AnyUniqueAliasesTypeId> reader = const _AnyUniqueAliasesTypeIdReader(); static const fb.Reader<AnyUniqueAliasesTypeId> reader = _AnyUniqueAliasesTypeIdReader();
@override @override
String toString() { String toString() {
@@ -200,7 +200,7 @@ class _AnyUniqueAliasesTypeIdReader extends fb.Reader<AnyUniqueAliasesTypeId> {
@override @override
AnyUniqueAliasesTypeId read(fb.BufferContext bc, int offset) => AnyUniqueAliasesTypeId read(fb.BufferContext bc, int offset) =>
new AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class AnyAmbiguousAliasesTypeId { class AnyAmbiguousAliasesTypeId {
@@ -210,7 +210,7 @@ class AnyAmbiguousAliasesTypeId {
factory AnyAmbiguousAliasesTypeId.fromValue(int value) { factory AnyAmbiguousAliasesTypeId.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId'); throw StateError('Invalid value $value for bit flag enum AnyAmbiguousAliasesTypeId');
} }
return result; return result;
} }
@@ -222,17 +222,17 @@ class AnyAmbiguousAliasesTypeId {
static const int maxValue = 3; static const int maxValue = 3;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const AnyAmbiguousAliasesTypeId NONE = const AnyAmbiguousAliasesTypeId._(0); static const AnyAmbiguousAliasesTypeId NONE = AnyAmbiguousAliasesTypeId._(0);
static const AnyAmbiguousAliasesTypeId M1 = const AnyAmbiguousAliasesTypeId._(1); static const AnyAmbiguousAliasesTypeId M1 = AnyAmbiguousAliasesTypeId._(1);
static const AnyAmbiguousAliasesTypeId M2 = const AnyAmbiguousAliasesTypeId._(2); static const AnyAmbiguousAliasesTypeId M2 = AnyAmbiguousAliasesTypeId._(2);
static const AnyAmbiguousAliasesTypeId M3 = const AnyAmbiguousAliasesTypeId._(3); static const AnyAmbiguousAliasesTypeId M3 = AnyAmbiguousAliasesTypeId._(3);
static const Map<int, AnyAmbiguousAliasesTypeId> values = { static const Map<int, AnyAmbiguousAliasesTypeId> values = {
0: NONE, 0: NONE,
1: M1, 1: M1,
2: M2, 2: M2,
3: M3}; 3: M3};
static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = const _AnyAmbiguousAliasesTypeIdReader(); static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = _AnyAmbiguousAliasesTypeIdReader();
@override @override
String toString() { String toString() {
@@ -248,13 +248,13 @@ class _AnyAmbiguousAliasesTypeIdReader extends fb.Reader<AnyAmbiguousAliasesType
@override @override
AnyAmbiguousAliasesTypeId read(fb.BufferContext bc, int offset) => AnyAmbiguousAliasesTypeId read(fb.BufferContext bc, int offset) =>
new AnyAmbiguousAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); AnyAmbiguousAliasesTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class Test { class Test {
Test._(this._bc, this._bcOffset); Test._(this._bc, this._bcOffset);
static const fb.Reader<Test> reader = const _TestReader(); static const fb.Reader<Test> reader = _TestReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -306,11 +306,11 @@ class _TestReader extends fb.StructReader<Test> {
@override @override
Test createObject(fb.BufferContext bc, int offset) => Test createObject(fb.BufferContext bc, int offset) =>
new Test._(bc, offset); Test._(bc, offset);
} }
class TestBuilder { class TestBuilder {
TestBuilder(this.fbBuilder) {} TestBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -346,20 +346,19 @@ class TestObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class TestSimpleTableWithEnum { class TestSimpleTableWithEnum {
TestSimpleTableWithEnum._(this._bc, this._bcOffset); TestSimpleTableWithEnum._(this._bc, this._bcOffset);
factory TestSimpleTableWithEnum(List<int> bytes) { factory TestSimpleTableWithEnum(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<TestSimpleTableWithEnum> reader = const _TestSimpleTableWithEnumReader(); static const fb.Reader<TestSimpleTableWithEnum> reader = _TestSimpleTableWithEnumReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -403,11 +402,11 @@ class _TestSimpleTableWithEnumReader extends fb.TableReader<TestSimpleTableWithE
@override @override
TestSimpleTableWithEnum createObject(fb.BufferContext bc, int offset) => TestSimpleTableWithEnum createObject(fb.BufferContext bc, int offset) =>
new TestSimpleTableWithEnum._(bc, offset); TestSimpleTableWithEnum._(bc, offset);
} }
class TestSimpleTableWithEnumBuilder { class TestSimpleTableWithEnumBuilder {
TestSimpleTableWithEnumBuilder(this.fbBuilder) {} TestSimpleTableWithEnumBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -444,16 +443,15 @@ class TestSimpleTableWithEnumObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Vec3 { class Vec3 {
Vec3._(this._bc, this._bcOffset); Vec3._(this._bc, this._bcOffset);
static const fb.Reader<Vec3> reader = const _Vec3Reader(); static const fb.Reader<Vec3> reader = _Vec3Reader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -527,11 +525,11 @@ class _Vec3Reader extends fb.StructReader<Vec3> {
@override @override
Vec3 createObject(fb.BufferContext bc, int offset) => Vec3 createObject(fb.BufferContext bc, int offset) =>
new Vec3._(bc, offset); Vec3._(bc, offset);
} }
class Vec3Builder { class Vec3Builder {
Vec3Builder(this.fbBuilder) {} Vec3Builder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -591,16 +589,15 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Ability { class Ability {
Ability._(this._bc, this._bcOffset); Ability._(this._bc, this._bcOffset);
static const fb.Reader<Ability> reader = const _AbilityReader(); static const fb.Reader<Ability> reader = _AbilityReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -651,11 +648,11 @@ class _AbilityReader extends fb.StructReader<Ability> {
@override @override
Ability createObject(fb.BufferContext bc, int offset) => Ability createObject(fb.BufferContext bc, int offset) =>
new Ability._(bc, offset); Ability._(bc, offset);
} }
class AbilityBuilder { class AbilityBuilder {
AbilityBuilder(this.fbBuilder) {} AbilityBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -689,16 +686,15 @@ class AbilityObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class StructOfStructs { class StructOfStructs {
StructOfStructs._(this._bc, this._bcOffset); StructOfStructs._(this._bc, this._bcOffset);
static const fb.Reader<StructOfStructs> reader = const _StructOfStructsReader(); static const fb.Reader<StructOfStructs> reader = _StructOfStructsReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -754,11 +750,11 @@ class _StructOfStructsReader extends fb.StructReader<StructOfStructs> {
@override @override
StructOfStructs createObject(fb.BufferContext bc, int offset) => StructOfStructs createObject(fb.BufferContext bc, int offset) =>
new StructOfStructs._(bc, offset); StructOfStructs._(bc, offset);
} }
class StructOfStructsBuilder { class StructOfStructsBuilder {
StructOfStructsBuilder(this.fbBuilder) {} StructOfStructsBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -797,20 +793,19 @@ class StructOfStructsObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Stat { class Stat {
Stat._(this._bc, this._bcOffset); Stat._(this._bc, this._bcOffset);
factory Stat(List<int> bytes) { factory Stat(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Stat> reader = const _StatReader(); static const fb.Reader<Stat> reader = _StatReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -866,11 +861,11 @@ class _StatReader extends fb.TableReader<Stat> {
@override @override
Stat createObject(fb.BufferContext bc, int offset) => Stat createObject(fb.BufferContext bc, int offset) =>
new Stat._(bc, offset); Stat._(bc, offset);
} }
class StatBuilder { class StatBuilder {
StatBuilder(this.fbBuilder) {} StatBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -925,20 +920,19 @@ class StatObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class Referrable { class Referrable {
Referrable._(this._bc, this._bcOffset); Referrable._(this._bc, this._bcOffset);
factory Referrable(List<int> bytes) { factory Referrable(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Referrable> reader = const _ReferrableReader(); static const fb.Reader<Referrable> reader = _ReferrableReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -982,11 +976,11 @@ class _ReferrableReader extends fb.TableReader<Referrable> {
@override @override
Referrable createObject(fb.BufferContext bc, int offset) => Referrable createObject(fb.BufferContext bc, int offset) =>
new Referrable._(bc, offset); Referrable._(bc, offset);
} }
class ReferrableBuilder { class ReferrableBuilder {
ReferrableBuilder(this.fbBuilder) {} ReferrableBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -1023,9 +1017,8 @@ class ReferrableObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
@@ -1033,11 +1026,11 @@ class ReferrableObjectBuilder extends fb.ObjectBuilder {
class Monster { class Monster {
Monster._(this._bc, this._bcOffset); Monster._(this._bc, this._bcOffset);
factory Monster(List<int> bytes) { factory Monster(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<Monster> reader = const _MonsterReader(); static const fb.Reader<Monster> reader = _MonsterReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -1046,10 +1039,10 @@ class Monster {
int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150); int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150);
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100); int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10); String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
List<int>? get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 14); List<int>? get inventory => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 14);
Color get color => Color.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 16, 8)); Color get color => Color.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 16, 8));
AnyTypeId? get testType => AnyTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 18)); AnyTypeId? get testType => AnyTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 18));
dynamic? get test { dynamic get test {
switch (testType?.value) { switch (testType?.value) {
case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 20); case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 20);
case 2: return TestSimpleTableWithEnum.reader.vTableGetNullable(_bc, _bcOffset, 20); case 2: return TestSimpleTableWithEnum.reader.vTableGetNullable(_bc, _bcOffset, 20);
@@ -1058,12 +1051,12 @@ class Monster {
} }
} }
List<Test>? get test4 => const fb.ListReader<Test>(Test.reader).vTableGetNullable(_bc, _bcOffset, 22); List<Test>? get test4 => const fb.ListReader<Test>(Test.reader).vTableGetNullable(_bc, _bcOffset, 22);
List<String>? get testarrayofstring => const fb.ListReader<String>(const fb.StringReader()).vTableGetNullable(_bc, _bcOffset, 24); List<String>? get testarrayofstring => const fb.ListReader<String>(fb.StringReader()).vTableGetNullable(_bc, _bcOffset, 24);
/// an example documentation comment: this will end up in the generated code /// an example documentation comment: this will end up in the generated code
/// multiline too /// multiline too
List<Monster>? get testarrayoftables => const fb.ListReader<Monster>(Monster.reader).vTableGetNullable(_bc, _bcOffset, 26); List<Monster>? get testarrayoftables => const fb.ListReader<Monster>(Monster.reader).vTableGetNullable(_bc, _bcOffset, 26);
Monster? get enemy => Monster.reader.vTableGetNullable(_bc, _bcOffset, 28); Monster? get enemy => Monster.reader.vTableGetNullable(_bc, _bcOffset, 28);
List<int>? get testnestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 30); List<int>? get testnestedflatbuffer => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 30);
Stat? get testempty => Stat.reader.vTableGetNullable(_bc, _bcOffset, 32); Stat? get testempty => Stat.reader.vTableGetNullable(_bc, _bcOffset, 32);
bool get testbool => const fb.BoolReader().vTableGet(_bc, _bcOffset, 34, false); bool get testbool => const fb.BoolReader().vTableGet(_bc, _bcOffset, 34, false);
int get testhashs32Fnv1 => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 36, 0); int get testhashs32Fnv1 => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 36, 0);
@@ -1074,27 +1067,27 @@ class Monster {
int get testhashu32Fnv1a => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 46, 0); int get testhashu32Fnv1a => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 46, 0);
int get testhashs64Fnv1a => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 48, 0); int get testhashs64Fnv1a => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 48, 0);
int get testhashu64Fnv1a => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 50, 0); int get testhashu64Fnv1a => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 50, 0);
List<bool>? get testarrayofbools => const fb.ListReader<bool>(const fb.BoolReader()).vTableGetNullable(_bc, _bcOffset, 52); List<bool>? get testarrayofbools => const fb.ListReader<bool>(fb.BoolReader()).vTableGetNullable(_bc, _bcOffset, 52);
double get testf => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 54, 3.14159); double get testf => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 54, 3.14159);
double get testf2 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 56, 3.0); double get testf2 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 56, 3.0);
double get testf3 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 58, 0.0); double get testf3 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 58, 0.0);
List<String>? get testarrayofstring2 => const fb.ListReader<String>(const fb.StringReader()).vTableGetNullable(_bc, _bcOffset, 60); List<String>? get testarrayofstring2 => const fb.ListReader<String>(fb.StringReader()).vTableGetNullable(_bc, _bcOffset, 60);
List<Ability>? get testarrayofsortedstruct => const fb.ListReader<Ability>(Ability.reader).vTableGetNullable(_bc, _bcOffset, 62); List<Ability>? get testarrayofsortedstruct => const fb.ListReader<Ability>(Ability.reader).vTableGetNullable(_bc, _bcOffset, 62);
List<int>? get flex => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 64); List<int>? get flex => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 64);
List<Test>? get test5 => const fb.ListReader<Test>(Test.reader).vTableGetNullable(_bc, _bcOffset, 66); List<Test>? get test5 => const fb.ListReader<Test>(Test.reader).vTableGetNullable(_bc, _bcOffset, 66);
List<int>? get vectorOfLongs => const fb.ListReader<int>(const fb.Int64Reader()).vTableGetNullable(_bc, _bcOffset, 68); List<int>? get vectorOfLongs => const fb.ListReader<int>(fb.Int64Reader()).vTableGetNullable(_bc, _bcOffset, 68);
List<double>? get vectorOfDoubles => const fb.ListReader<double>(const fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 70); List<double>? get vectorOfDoubles => const fb.ListReader<double>(fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 70);
my_game.InParentNamespace? get parentNamespaceTest => my_game.InParentNamespace.reader.vTableGetNullable(_bc, _bcOffset, 72); my_game.InParentNamespace? get parentNamespaceTest => my_game.InParentNamespace.reader.vTableGetNullable(_bc, _bcOffset, 72);
List<Referrable>? get vectorOfReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGetNullable(_bc, _bcOffset, 74); List<Referrable>? get vectorOfReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGetNullable(_bc, _bcOffset, 74);
int get singleWeakReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 76, 0); int get singleWeakReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 76, 0);
List<int>? get vectorOfWeakReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 78); List<int>? get vectorOfWeakReferences => const fb.ListReader<int>(fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 78);
List<Referrable>? get vectorOfStrongReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGetNullable(_bc, _bcOffset, 80); List<Referrable>? get vectorOfStrongReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGetNullable(_bc, _bcOffset, 80);
int get coOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 82, 0); int get coOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 82, 0);
List<int>? get vectorOfCoOwningReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 84); List<int>? get vectorOfCoOwningReferences => const fb.ListReader<int>(fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 84);
int get nonOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 86, 0); int get nonOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 86, 0);
List<int>? get vectorOfNonOwningReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 88); List<int>? get vectorOfNonOwningReferences => const fb.ListReader<int>(fb.Uint64Reader()).vTableGetNullable(_bc, _bcOffset, 88);
AnyUniqueAliasesTypeId? get anyUniqueType => AnyUniqueAliasesTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 90)); AnyUniqueAliasesTypeId? get anyUniqueType => AnyUniqueAliasesTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 90));
dynamic? get anyUnique { dynamic get anyUnique {
switch (anyUniqueType?.value) { switch (anyUniqueType?.value) {
case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 92); case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 92);
case 2: return TestSimpleTableWithEnum.reader.vTableGetNullable(_bc, _bcOffset, 92); case 2: return TestSimpleTableWithEnum.reader.vTableGetNullable(_bc, _bcOffset, 92);
@@ -1103,7 +1096,7 @@ class Monster {
} }
} }
AnyAmbiguousAliasesTypeId? get anyAmbiguousType => AnyAmbiguousAliasesTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 94)); AnyAmbiguousAliasesTypeId? get anyAmbiguousType => AnyAmbiguousAliasesTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 94));
dynamic? get anyAmbiguous { dynamic get anyAmbiguous {
switch (anyAmbiguousType?.value) { switch (anyAmbiguousType?.value) {
case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 96); case 1: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 96);
case 2: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 96); case 2: return Monster.reader.vTableGetNullable(_bc, _bcOffset, 96);
@@ -1113,7 +1106,7 @@ class Monster {
} }
List<Color>? get vectorOfEnums => const fb.ListReader<Color>(Color.reader).vTableGetNullable(_bc, _bcOffset, 98); List<Color>? get vectorOfEnums => const fb.ListReader<Color>(Color.reader).vTableGetNullable(_bc, _bcOffset, 98);
Race get signedEnum => Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1)); Race get signedEnum => Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1));
List<int>? get testrequirednestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 102); List<int>? get testrequirednestedflatbuffer => const fb.ListReader<int>(fb.Uint8Reader()).vTableGetNullable(_bc, _bcOffset, 102);
List<Stat>? get scalarKeySortedTables => const fb.ListReader<Stat>(Stat.reader).vTableGetNullable(_bc, _bcOffset, 104); List<Stat>? get scalarKeySortedTables => const fb.ListReader<Stat>(Stat.reader).vTableGetNullable(_bc, _bcOffset, 104);
@override @override
@@ -1126,15 +1119,15 @@ class Monster {
mana: mana, mana: mana,
hp: hp, hp: hp,
name: name, name: name,
inventory: const fb.ListReader<int>(const fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 14), inventory: const fb.ListReader<int>(fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 14),
color: color, color: color,
testType: testType, testType: testType,
test: test, test: test,
test4: test4?.map((e) => e.unpack()).toList(), test4: test4?.map((e) => e.unpack()).toList(),
testarrayofstring: const fb.ListReader<String>(const 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(),
enemy: enemy?.unpack(), enemy: enemy?.unpack(),
testnestedflatbuffer: const fb.ListReader<int>(const fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 30), testnestedflatbuffer: const fb.ListReader<int>(fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 30),
testempty: testempty?.unpack(), testempty: testempty?.unpack(),
testbool: testbool, testbool: testbool,
testhashs32Fnv1: testhashs32Fnv1, testhashs32Fnv1: testhashs32Fnv1,
@@ -1145,32 +1138,32 @@ class Monster {
testhashu32Fnv1a: testhashu32Fnv1a, testhashu32Fnv1a: testhashu32Fnv1a,
testhashs64Fnv1a: testhashs64Fnv1a, testhashs64Fnv1a: testhashs64Fnv1a,
testhashu64Fnv1a: testhashu64Fnv1a, testhashu64Fnv1a: testhashu64Fnv1a,
testarrayofbools: const fb.ListReader<bool>(const fb.BoolReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 52), testarrayofbools: const fb.ListReader<bool>(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>(const fb.StringReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 60), testarrayofstring2: const fb.ListReader<String>(fb.StringReader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 60),
testarrayofsortedstruct: testarrayofsortedstruct?.map((e) => e.unpack()).toList(), testarrayofsortedstruct: testarrayofsortedstruct?.map((e) => e.unpack()).toList(),
flex: const fb.ListReader<int>(const fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 64), flex: const fb.ListReader<int>(fb.Uint8Reader(), 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>(const fb.Int64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 68), vectorOfLongs: const fb.ListReader<int>(fb.Int64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 68),
vectorOfDoubles: const fb.ListReader<double>(const fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 70), 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>(const fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 78), vectorOfWeakReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 78),
vectorOfStrongReferrables: vectorOfStrongReferrables?.map((e) => e.unpack()).toList(), vectorOfStrongReferrables: vectorOfStrongReferrables?.map((e) => e.unpack()).toList(),
coOwningReference: coOwningReference, coOwningReference: coOwningReference,
vectorOfCoOwningReferences: const fb.ListReader<int>(const fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 84), vectorOfCoOwningReferences: const fb.ListReader<int>(fb.Uint64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 84),
nonOwningReference: nonOwningReference, nonOwningReference: nonOwningReference,
vectorOfNonOwningReferences: const fb.ListReader<int>(const 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,
anyAmbiguousType: anyAmbiguousType, anyAmbiguousType: anyAmbiguousType,
anyAmbiguous: anyAmbiguous, anyAmbiguous: anyAmbiguous,
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.ListReader<int>(const fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 102), testrequirednestedflatbuffer: const fb.ListReader<int>(fb.Uint8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 102),
scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList()); scalarKeySortedTables: scalarKeySortedTables?.map((e) => e.unpack()).toList());
static int pack(fb.Builder fbBuilder, MonsterT? object) { static int pack(fb.Builder fbBuilder, MonsterT? object) {
@@ -1188,7 +1181,7 @@ class MonsterT {
List<int>? inventory; List<int>? inventory;
Color color; Color color;
AnyTypeId? testType; AnyTypeId? testType;
dynamic? test; dynamic test;
List<TestT>? test4; List<TestT>? test4;
List<String>? testarrayofstring; List<String>? testarrayofstring;
/// an example documentation comment: this will end up in the generated code /// an example documentation comment: this will end up in the generated code
@@ -1226,9 +1219,9 @@ class MonsterT {
int nonOwningReference; int nonOwningReference;
List<int>? vectorOfNonOwningReferences; List<int>? vectorOfNonOwningReferences;
AnyUniqueAliasesTypeId? anyUniqueType; AnyUniqueAliasesTypeId? anyUniqueType;
dynamic? anyUnique; dynamic anyUnique;
AnyAmbiguousAliasesTypeId? anyAmbiguousType; AnyAmbiguousAliasesTypeId? anyAmbiguousType;
dynamic? anyAmbiguous; dynamic anyAmbiguous;
List<Color>? vectorOfEnums; List<Color>? vectorOfEnums;
Race signedEnum; Race signedEnum;
List<int>? testrequirednestedflatbuffer; List<int>? testrequirednestedflatbuffer;
@@ -1292,9 +1285,9 @@ class MonsterT {
final int? inventoryOffset = inventory == null ? null final int? inventoryOffset = inventory == null ? null
: fbBuilder.writeListUint8(inventory!); : fbBuilder.writeListUint8(inventory!);
final int? testOffset = test?.pack(fbBuilder); final int? testOffset = test?.pack(fbBuilder);
int? test4Offset = null; int? test4Offset;
if (test4 != null) { if (test4 != null) {
test4!.forEach((e) => e.pack(fbBuilder)); for (var e in test4!) { e.pack(fbBuilder); }
test4Offset = fbBuilder.endStructVector(test4!.length); test4Offset = fbBuilder.endStructVector(test4!.length);
} }
final int? testarrayofstringOffset = testarrayofstring == null ? null final int? testarrayofstringOffset = testarrayofstring == null ? null
@@ -1309,16 +1302,16 @@ class MonsterT {
: fbBuilder.writeListBool(testarrayofbools!); : fbBuilder.writeListBool(testarrayofbools!);
final int? testarrayofstring2Offset = testarrayofstring2 == null ? null final int? testarrayofstring2Offset = testarrayofstring2 == null ? null
: fbBuilder.writeList(testarrayofstring2!.map(fbBuilder.writeString).toList()); : fbBuilder.writeList(testarrayofstring2!.map(fbBuilder.writeString).toList());
int? testarrayofsortedstructOffset = null; int? testarrayofsortedstructOffset;
if (testarrayofsortedstruct != null) { if (testarrayofsortedstruct != null) {
testarrayofsortedstruct!.forEach((e) => e.pack(fbBuilder)); for (var e in testarrayofsortedstruct!) { e.pack(fbBuilder); }
testarrayofsortedstructOffset = fbBuilder.endStructVector(testarrayofsortedstruct!.length); testarrayofsortedstructOffset = fbBuilder.endStructVector(testarrayofsortedstruct!.length);
} }
final int? flexOffset = flex == null ? null final int? flexOffset = flex == null ? null
: fbBuilder.writeListUint8(flex!); : fbBuilder.writeListUint8(flex!);
int? test5Offset = null; int? test5Offset;
if (test5 != null) { if (test5 != null) {
test5!.forEach((e) => e.pack(fbBuilder)); for (var e in test5!) { e.pack(fbBuilder); }
test5Offset = fbBuilder.endStructVector(test5!.length); test5Offset = fbBuilder.endStructVector(test5!.length);
} }
final int? vectorOfLongsOffset = vectorOfLongs == null ? null final int? vectorOfLongsOffset = vectorOfLongs == null ? null
@@ -1411,11 +1404,11 @@ class _MonsterReader extends fb.TableReader<Monster> {
@override @override
Monster createObject(fb.BufferContext bc, int offset) => Monster createObject(fb.BufferContext bc, int offset) =>
new Monster._(bc, offset); Monster._(bc, offset);
} }
class MonsterBuilder { class MonsterBuilder {
MonsterBuilder(this.fbBuilder) {} MonsterBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -1637,7 +1630,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
final List<int>? _inventory; final List<int>? _inventory;
final Color? _color; final Color? _color;
final AnyTypeId? _testType; final AnyTypeId? _testType;
final dynamic? _test; final dynamic _test;
final List<TestObjectBuilder>? _test4; final List<TestObjectBuilder>? _test4;
final List<String>? _testarrayofstring; final List<String>? _testarrayofstring;
final List<MonsterObjectBuilder>? _testarrayoftables; final List<MonsterObjectBuilder>? _testarrayoftables;
@@ -1673,9 +1666,9 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
final int? _nonOwningReference; final int? _nonOwningReference;
final List<int>? _vectorOfNonOwningReferences; final List<int>? _vectorOfNonOwningReferences;
final AnyUniqueAliasesTypeId? _anyUniqueType; final AnyUniqueAliasesTypeId? _anyUniqueType;
final dynamic? _anyUnique; final dynamic _anyUnique;
final AnyAmbiguousAliasesTypeId? _anyAmbiguousType; final AnyAmbiguousAliasesTypeId? _anyAmbiguousType;
final dynamic? _anyAmbiguous; final dynamic _anyAmbiguous;
final List<Color>? _vectorOfEnums; final List<Color>? _vectorOfEnums;
final Race? _signedEnum; final Race? _signedEnum;
final List<int>? _testrequirednestedflatbuffer; final List<int>? _testrequirednestedflatbuffer;
@@ -1689,7 +1682,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
List<int>? inventory, List<int>? inventory,
Color? color, Color? color,
AnyTypeId? testType, AnyTypeId? testType,
dynamic? test, dynamic test,
List<TestObjectBuilder>? test4, List<TestObjectBuilder>? test4,
List<String>? testarrayofstring, List<String>? testarrayofstring,
List<MonsterObjectBuilder>? testarrayoftables, List<MonsterObjectBuilder>? testarrayoftables,
@@ -1725,9 +1718,9 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
int? nonOwningReference, int? nonOwningReference,
List<int>? vectorOfNonOwningReferences, List<int>? vectorOfNonOwningReferences,
AnyUniqueAliasesTypeId? anyUniqueType, AnyUniqueAliasesTypeId? anyUniqueType,
dynamic? anyUnique, dynamic anyUnique,
AnyAmbiguousAliasesTypeId? anyAmbiguousType, AnyAmbiguousAliasesTypeId? anyAmbiguousType,
dynamic? anyAmbiguous, dynamic anyAmbiguous,
List<Color>? vectorOfEnums, List<Color>? vectorOfEnums,
Race? signedEnum, Race? signedEnum,
List<int>? testrequirednestedflatbuffer, List<int>? testrequirednestedflatbuffer,
@@ -1894,20 +1887,19 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class TypeAliases { class TypeAliases {
TypeAliases._(this._bc, this._bcOffset); TypeAliases._(this._bc, this._bcOffset);
factory TypeAliases(List<int> bytes) { factory TypeAliases(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<TypeAliases> reader = const _TypeAliasesReader(); static const fb.Reader<TypeAliases> reader = _TypeAliasesReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -1922,8 +1914,8 @@ class TypeAliases {
int get u64 => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 18, 0); int get u64 => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 18, 0);
double get f32 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 20, 0.0); double get f32 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 20, 0.0);
double get f64 => const fb.Float64Reader().vTableGet(_bc, _bcOffset, 22, 0.0); double get f64 => const fb.Float64Reader().vTableGet(_bc, _bcOffset, 22, 0.0);
List<int>? get v8 => const fb.ListReader<int>(const fb.Int8Reader()).vTableGetNullable(_bc, _bcOffset, 24); List<int>? get v8 => const fb.ListReader<int>(fb.Int8Reader()).vTableGetNullable(_bc, _bcOffset, 24);
List<double>? get vf64 => const fb.ListReader<double>(const fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 26); List<double>? get vf64 => const fb.ListReader<double>(fb.Float64Reader()).vTableGetNullable(_bc, _bcOffset, 26);
@override @override
String toString() { String toString() {
@@ -1941,8 +1933,8 @@ class TypeAliases {
u64: u64, u64: u64,
f32: f32, f32: f32,
f64: f64, f64: f64,
v8: const fb.ListReader<int>(const fb.Int8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 24), v8: const fb.ListReader<int>(fb.Int8Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 24),
vf64: const fb.ListReader<double>(const fb.Float64Reader(), lazy: false).vTableGetNullable(_bc, _bcOffset, 26)); 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) {
if (object == null) return 0; if (object == null) return 0;
@@ -2010,11 +2002,11 @@ class _TypeAliasesReader extends fb.TableReader<TypeAliases> {
@override @override
TypeAliases createObject(fb.BufferContext bc, int offset) => TypeAliases createObject(fb.BufferContext bc, int offset) =>
new TypeAliases._(bc, offset); TypeAliases._(bc, offset);
} }
class TypeAliasesBuilder { class TypeAliasesBuilder {
TypeAliasesBuilder(this.fbBuilder) {} TypeAliasesBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -2143,9 +2135,8 @@ class TypeAliasesObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -12,11 +12,11 @@ import './monster_test_my_game.example2_generated.dart' as my_game_example2;
class InParentNamespace { class InParentNamespace {
InParentNamespace._(this._bc, this._bcOffset); InParentNamespace._(this._bc, this._bcOffset);
factory InParentNamespace(List<int> bytes) { factory InParentNamespace(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<InParentNamespace> reader = const _InParentNamespaceReader(); static const fb.Reader<InParentNamespace> reader = _InParentNamespaceReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -52,7 +52,7 @@ class _InParentNamespaceReader extends fb.TableReader<InParentNamespace> {
@override @override
InParentNamespace createObject(fb.BufferContext bc, int offset) => InParentNamespace createObject(fb.BufferContext bc, int offset) =>
new InParentNamespace._(bc, offset); InParentNamespace._(bc, offset);
} }
class InParentNamespaceObjectBuilder extends fb.ObjectBuilder { class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
@@ -69,9 +69,8 @@ class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -14,7 +14,7 @@ class UnionInNestedNSTypeId {
factory UnionInNestedNSTypeId.fromValue(int value) { factory UnionInNestedNSTypeId.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum UnionInNestedNSTypeId'); throw StateError('Invalid value $value for bit flag enum UnionInNestedNSTypeId');
} }
return result; return result;
} }
@@ -26,13 +26,13 @@ class UnionInNestedNSTypeId {
static const int maxValue = 1; static const int maxValue = 1;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const UnionInNestedNSTypeId NONE = const UnionInNestedNSTypeId._(0); static const UnionInNestedNSTypeId NONE = UnionInNestedNSTypeId._(0);
static const UnionInNestedNSTypeId TableInNestedNS = const UnionInNestedNSTypeId._(1); static const UnionInNestedNSTypeId TableInNestedNS = UnionInNestedNSTypeId._(1);
static const Map<int, UnionInNestedNSTypeId> values = { static const Map<int, UnionInNestedNSTypeId> values = {
0: NONE, 0: NONE,
1: TableInNestedNS}; 1: TableInNestedNS};
static const fb.Reader<UnionInNestedNSTypeId> reader = const _UnionInNestedNSTypeIdReader(); static const fb.Reader<UnionInNestedNSTypeId> reader = _UnionInNestedNSTypeIdReader();
@override @override
String toString() { String toString() {
@@ -48,7 +48,7 @@ class _UnionInNestedNSTypeIdReader extends fb.Reader<UnionInNestedNSTypeId> {
@override @override
UnionInNestedNSTypeId read(fb.BufferContext bc, int offset) => UnionInNestedNSTypeId read(fb.BufferContext bc, int offset) =>
new UnionInNestedNSTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); UnionInNestedNSTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
} }
class EnumInNestedNS { class EnumInNestedNS {
@@ -58,7 +58,7 @@ class EnumInNestedNS {
factory EnumInNestedNS.fromValue(int value) { factory EnumInNestedNS.fromValue(int value) {
final result = values[value]; final result = values[value];
if (result == null) { if (result == null) {
throw new StateError('Invalid value $value for bit flag enum EnumInNestedNS'); throw StateError('Invalid value $value for bit flag enum EnumInNestedNS');
} }
return result; return result;
} }
@@ -70,15 +70,15 @@ class EnumInNestedNS {
static const int maxValue = 2; static const int maxValue = 2;
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const EnumInNestedNS A = const EnumInNestedNS._(0); static const EnumInNestedNS A = EnumInNestedNS._(0);
static const EnumInNestedNS B = const EnumInNestedNS._(1); static const EnumInNestedNS B = EnumInNestedNS._(1);
static const EnumInNestedNS C = const EnumInNestedNS._(2); static const EnumInNestedNS C = EnumInNestedNS._(2);
static const Map<int, EnumInNestedNS> values = { static const Map<int, EnumInNestedNS> values = {
0: A, 0: A,
1: B, 1: B,
2: C}; 2: C};
static const fb.Reader<EnumInNestedNS> reader = const _EnumInNestedNSReader(); static const fb.Reader<EnumInNestedNS> reader = _EnumInNestedNSReader();
@override @override
String toString() { String toString() {
@@ -94,17 +94,17 @@ class _EnumInNestedNSReader extends fb.Reader<EnumInNestedNS> {
@override @override
EnumInNestedNS read(fb.BufferContext bc, int offset) => EnumInNestedNS read(fb.BufferContext bc, int offset) =>
new EnumInNestedNS.fromValue(const fb.Int8Reader().read(bc, offset)); EnumInNestedNS.fromValue(const fb.Int8Reader().read(bc, offset));
} }
class TableInNestedNS { class TableInNestedNS {
TableInNestedNS._(this._bc, this._bcOffset); TableInNestedNS._(this._bc, this._bcOffset);
factory TableInNestedNS(List<int> bytes) { factory TableInNestedNS(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<TableInNestedNS> reader = const _TableInNestedNSReader(); static const fb.Reader<TableInNestedNS> reader = _TableInNestedNSReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -148,11 +148,11 @@ class _TableInNestedNSReader extends fb.TableReader<TableInNestedNS> {
@override @override
TableInNestedNS createObject(fb.BufferContext bc, int offset) => TableInNestedNS createObject(fb.BufferContext bc, int offset) =>
new TableInNestedNS._(bc, offset); TableInNestedNS._(bc, offset);
} }
class TableInNestedNSBuilder { class TableInNestedNSBuilder {
TableInNestedNSBuilder(this.fbBuilder) {} TableInNestedNSBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -189,16 +189,15 @@ class TableInNestedNSObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class StructInNestedNS { class StructInNestedNS {
StructInNestedNS._(this._bc, this._bcOffset); StructInNestedNS._(this._bc, this._bcOffset);
static const fb.Reader<StructInNestedNS> reader = const _StructInNestedNSReader(); static const fb.Reader<StructInNestedNS> reader = _StructInNestedNSReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -249,11 +248,11 @@ class _StructInNestedNSReader extends fb.StructReader<StructInNestedNS> {
@override @override
StructInNestedNS createObject(fb.BufferContext bc, int offset) => StructInNestedNS createObject(fb.BufferContext bc, int offset) =>
new StructInNestedNS._(bc, offset); StructInNestedNS._(bc, offset);
} }
class StructInNestedNSBuilder { class StructInNestedNSBuilder {
StructInNestedNSBuilder(this.fbBuilder) {} StructInNestedNSBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -287,9 +286,8 @@ class StructInNestedNSObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -11,11 +11,11 @@ import './namespace_test2_namespace_c_generated.dart' as namespace_c;
class TableInFirstNS { class TableInFirstNS {
TableInFirstNS._(this._bc, this._bcOffset); TableInFirstNS._(this._bc, this._bcOffset);
factory TableInFirstNS(List<int> bytes) { factory TableInFirstNS(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<TableInFirstNS> reader = const _TableInFirstNSReader(); static const fb.Reader<TableInFirstNS> reader = _TableInFirstNSReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -23,7 +23,7 @@ class TableInFirstNS {
namespace_a_namespace_b.TableInNestedNS? get fooTable => namespace_a_namespace_b.TableInNestedNS.reader.vTableGetNullable(_bc, _bcOffset, 4); namespace_a_namespace_b.TableInNestedNS? get fooTable => namespace_a_namespace_b.TableInNestedNS.reader.vTableGetNullable(_bc, _bcOffset, 4);
EnumInNestedNS get fooEnum => EnumInNestedNS.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 6, 0)); EnumInNestedNS get fooEnum => EnumInNestedNS.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 6, 0));
UnionInNestedNSTypeId? get fooUnionType => UnionInNestedNSTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 8)); UnionInNestedNSTypeId? get fooUnionType => UnionInNestedNSTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 8));
dynamic? get fooUnion { dynamic get fooUnion {
switch (fooUnionType?.value) { switch (fooUnionType?.value) {
case 1: return TableInNestedNS.reader.vTableGetNullable(_bc, _bcOffset, 10); case 1: return TableInNestedNS.reader.vTableGetNullable(_bc, _bcOffset, 10);
default: return null; default: return null;
@@ -53,7 +53,7 @@ class TableInFirstNST {
namespace_a_namespace_b.TableInNestedNST? fooTable; namespace_a_namespace_b.TableInNestedNST? fooTable;
EnumInNestedNS fooEnum; EnumInNestedNS fooEnum;
UnionInNestedNSTypeId? fooUnionType; UnionInNestedNSTypeId? fooUnionType;
dynamic? fooUnion; dynamic fooUnion;
namespace_a_namespace_b.StructInNestedNST? fooStruct; namespace_a_namespace_b.StructInNestedNST? fooStruct;
TableInFirstNST({ TableInFirstNST({
@@ -88,11 +88,11 @@ class _TableInFirstNSReader extends fb.TableReader<TableInFirstNS> {
@override @override
TableInFirstNS createObject(fb.BufferContext bc, int offset) => TableInFirstNS createObject(fb.BufferContext bc, int offset) =>
new TableInFirstNS._(bc, offset); TableInFirstNS._(bc, offset);
} }
class TableInFirstNSBuilder { class TableInFirstNSBuilder {
TableInFirstNSBuilder(this.fbBuilder) {} TableInFirstNSBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -130,14 +130,14 @@ class TableInFirstNSObjectBuilder extends fb.ObjectBuilder {
final namespace_a_namespace_b.TableInNestedNSObjectBuilder? _fooTable; final namespace_a_namespace_b.TableInNestedNSObjectBuilder? _fooTable;
final EnumInNestedNS? _fooEnum; final EnumInNestedNS? _fooEnum;
final UnionInNestedNSTypeId? _fooUnionType; final UnionInNestedNSTypeId? _fooUnionType;
final dynamic? _fooUnion; final dynamic _fooUnion;
final namespace_a_namespace_b.StructInNestedNSObjectBuilder? _fooStruct; final namespace_a_namespace_b.StructInNestedNSObjectBuilder? _fooStruct;
TableInFirstNSObjectBuilder({ TableInFirstNSObjectBuilder({
namespace_a_namespace_b.TableInNestedNSObjectBuilder? fooTable, namespace_a_namespace_b.TableInNestedNSObjectBuilder? fooTable,
EnumInNestedNS? fooEnum, EnumInNestedNS? fooEnum,
UnionInNestedNSTypeId? fooUnionType, UnionInNestedNSTypeId? fooUnionType,
dynamic? fooUnion, dynamic fooUnion,
namespace_a_namespace_b.StructInNestedNSObjectBuilder? fooStruct, namespace_a_namespace_b.StructInNestedNSObjectBuilder? fooStruct,
}) })
: _fooTable = fooTable, : _fooTable = fooTable,
@@ -165,20 +165,19 @@ class TableInFirstNSObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }
class SecondTableInA { class SecondTableInA {
SecondTableInA._(this._bc, this._bcOffset); SecondTableInA._(this._bc, this._bcOffset);
factory SecondTableInA(List<int> bytes) { factory SecondTableInA(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<SecondTableInA> reader = const _SecondTableInAReader(); static const fb.Reader<SecondTableInA> reader = _SecondTableInAReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -223,11 +222,11 @@ class _SecondTableInAReader extends fb.TableReader<SecondTableInA> {
@override @override
SecondTableInA createObject(fb.BufferContext bc, int offset) => SecondTableInA createObject(fb.BufferContext bc, int offset) =>
new SecondTableInA._(bc, offset); SecondTableInA._(bc, offset);
} }
class SecondTableInABuilder { class SecondTableInABuilder {
SecondTableInABuilder(this.fbBuilder) {} SecondTableInABuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -265,9 +264,8 @@ class SecondTableInAObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }

View File

@@ -11,11 +11,11 @@ import './namespace_test2_namespace_a_generated.dart' as namespace_a;
class TableInC { class TableInC {
TableInC._(this._bc, this._bcOffset); TableInC._(this._bc, this._bcOffset);
factory TableInC(List<int> bytes) { factory TableInC(List<int> bytes) {
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0); return reader.read(rootRef, 0);
} }
static const fb.Reader<TableInC> reader = const _TableInCReader(); static const fb.Reader<TableInC> reader = _TableInCReader();
final fb.BufferContext _bc; final fb.BufferContext _bc;
final int _bcOffset; final int _bcOffset;
@@ -66,11 +66,11 @@ class _TableInCReader extends fb.TableReader<TableInC> {
@override @override
TableInC createObject(fb.BufferContext bc, int offset) => TableInC createObject(fb.BufferContext bc, int offset) =>
new TableInC._(bc, offset); TableInC._(bc, offset);
} }
class TableInCBuilder { class TableInCBuilder {
TableInCBuilder(this.fbBuilder) {} TableInCBuilder(this.fbBuilder);
final fb.Builder fbBuilder; final fb.Builder fbBuilder;
@@ -117,9 +117,8 @@ class TableInCObjectBuilder extends fb.ObjectBuilder {
/// Convenience method to serialize to byte list. /// Convenience method to serialize to byte list.
@override @override
Uint8List toBytes([String? fileIdentifier]) { Uint8List toBytes([String? fileIdentifier]) {
fb.Builder fbBuilder = new fb.Builder(deduplicateTables: false); final fbBuilder = fb.Builder(deduplicateTables: false);
int offset = finish(fbBuilder); fbBuilder.finish(finish(fbBuilder), fileIdentifier);
fbBuilder.finish(offset, fileIdentifier);
return fbBuilder.buffer; return fbBuilder.buffer;
} }
} }