mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Ensure strings are null terminated when written from Dart (#4862)
* Update for Dart 2.x constants * Fix strings, update test, add CHANGELOG for Dart
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
38a6623f34
commit
fd40cc61a4
14
dart/CHANGELOG.md
Normal file
14
dart/CHANGELOG.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 1.9.2
|
||||
|
||||
- Ensure `_writeString` adds enough padding to null terminate strings.
|
||||
|
||||
## 1.9.1
|
||||
|
||||
- Changed constant identifiers to be compatible with Dart 2.x
|
||||
- No longer supports Dart 1.x
|
||||
|
||||
## 1.9.0
|
||||
|
||||
- Initial release, supports Dart 1.x and many dev versions of Dart 2.x
|
||||
@@ -662,7 +662,7 @@ class Builder {
|
||||
// TODO(scheglov) optimize for ASCII strings
|
||||
List<int> bytes = utf8.encode(value);
|
||||
int length = bytes.length;
|
||||
_prepare(4, 1, additionalBytes: length);
|
||||
_prepare(4, 1, additionalBytes: length + 1);
|
||||
final int result = _tail;
|
||||
_setUint32AtTail(_buf, _tail, length);
|
||||
int offset = _buf.lengthInBytes - _tail + 4;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: flat_buffers
|
||||
version: 1.9.1
|
||||
version: 1.9.2
|
||||
description: >
|
||||
FlatBuffers reading and writing library for Dart. Use the flatc compiler to
|
||||
generate Dart classes for a FlatBuffers schema, and this library to assist with
|
||||
@@ -13,7 +13,7 @@ authors:
|
||||
homepage: https://github.com/google/flatbuffers
|
||||
documentation: https://google.github.io/flatbuffers/index.html
|
||||
dev_dependencies:
|
||||
test: ^0.12.33
|
||||
test: ^1.3.0
|
||||
test_reflective_loader: ^0.1.4
|
||||
path: ^1.5.1
|
||||
environment:
|
||||
|
||||
@@ -59,7 +59,7 @@ class CheckOtherLangaugesData {
|
||||
|
||||
// this will fail if accessing any field fails.
|
||||
expect(mon.toString(),
|
||||
'Monster{pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], color: Color{value: 8}, testType: AnyTypeId{value: 1}, test: Monster{pos: null, mana: 150, hp: 100, name: Fred, inventory: null, color: Color{value: 8}, testType: null, test: null, test4: null, testarrayofstring: null, testarrayoftables: null, enemy: null, testnestedflatbuffer: null, testempty: null, testbool: null, testhashs32Fnv1: null, testhashu32Fnv1: null, testhashs64Fnv1: null, testhashu64Fnv1: null, testhashs32Fnv1a: null, testhashu32Fnv1a: null, testhashs64Fnv1a: null, testhashu64Fnv1a: null, testarrayofbools: null, testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: null, vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: null, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: null, vectorOfCoOwningReferences: null, nonOwningReference: null, vectorOfNonOwningReferences: null}, test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], testarrayofstring: [test1, test2], testarrayoftables: null, enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, inventory: null, color: Color{value: 8}, testType: null, test: null, test4: null, testarrayofstring: null, testarrayoftables: null, enemy: null, testnestedflatbuffer: null, testempty: null, testbool: null, testhashs32Fnv1: null, testhashu32Fnv1: null, testhashs64Fnv1: null, testhashu64Fnv1: null, testhashs32Fnv1a: null, testhashu32Fnv1a: null, testhashs64Fnv1a: null, testhashu64Fnv1a: null, testarrayofbools: null, testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: null, vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: null, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: null, vectorOfCoOwningReferences: null, nonOwningReference: null, vectorOfNonOwningReferences: null}, testnestedflatbuffer: null, testempty: null, testbool: null, testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, testhashs64Fnv1: 7930699090847568257, testhashu64Fnv1: 7930699090847568257, testhashs32Fnv1a: -1904106383, testhashu32Fnv1a: 2390860913, testhashs64Fnv1a: 4898026182817603057, testhashu64Fnv1a: 4898026182817603057, testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], vectorOfLongs: [1, 100, 10000, 1000000, 100000000], vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: null, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: null, vectorOfCoOwningReferences: null, nonOwningReference: null, vectorOfNonOwningReferences: null}');
|
||||
'Monster{pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], color: Color{value: 8}, testType: AnyTypeId{value: 1}, test: Monster{pos: null, mana: 150, hp: 100, name: Fred, inventory: null, color: Color{value: 8}, testType: AnyTypeId{value: 0}, test: null, test4: null, testarrayofstring: null, testarrayoftables: null, enemy: null, testnestedflatbuffer: null, testempty: null, testbool: false, testhashs32Fnv1: 0, testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: null, vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: 0, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: 0, vectorOfCoOwningReferences: null, nonOwningReference: 0, vectorOfNonOwningReferences: null}, test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], testarrayofstring: [test1, test2], testarrayoftables: null, enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, inventory: null, color: Color{value: 8}, testType: AnyTypeId{value: 0}, test: null, test4: null, testarrayofstring: null, testarrayoftables: null, enemy: null, testnestedflatbuffer: null, testempty: null, testbool: false, testhashs32Fnv1: 0, testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: null, vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: 0, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: 0, vectorOfCoOwningReferences: null, nonOwningReference: 0, vectorOfNonOwningReferences: null}, testnestedflatbuffer: null, testempty: null, testbool: false, testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, testhashs64Fnv1: 7930699090847568257, testhashu64Fnv1: 7930699090847568257, testhashs32Fnv1a: -1904106383, testhashu32Fnv1a: 2390860913, testhashs64Fnv1a: 4898026182817603057, testhashu64Fnv1a: 4898026182817603057, testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], vectorOfLongs: [1, 100, 10000, 1000000, 100000000], vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: 0, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: 0, vectorOfCoOwningReferences: null, nonOwningReference: 0, vectorOfNonOwningReferences: null}');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class Color {
|
||||
const Color._(this.value);
|
||||
|
||||
factory Color.fromValue(int value) {
|
||||
if (value == null) return null;
|
||||
if (value == null) value = 0;
|
||||
if (!values.containsKey(value)) {
|
||||
throw new StateError('Invalid value $value for bit flag enum Color');
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class AnyTypeId {
|
||||
const AnyTypeId._(this.value);
|
||||
|
||||
factory AnyTypeId.fromValue(int value) {
|
||||
if (value == null) return null;
|
||||
if (value == null) value = 0;
|
||||
if (!values.containsKey(value)) {
|
||||
throw new StateError('Invalid value $value for bit flag enum AnyTypeId');
|
||||
}
|
||||
@@ -428,8 +428,8 @@ class Stat {
|
||||
final int _bcOffset;
|
||||
|
||||
String get id => const fb.StringReader().vTableGet(_bc, _bcOffset, 4, null);
|
||||
int get val => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 6, null);
|
||||
int get count => const fb.Uint16Reader().vTableGet(_bc, _bcOffset, 8, null);
|
||||
int get val => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 6, 0);
|
||||
int get count => const fb.Uint16Reader().vTableGet(_bc, _bcOffset, 8, 0);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -524,7 +524,7 @@ class Referrable {
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
int get id => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 4, null);
|
||||
int get id => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 4, 0);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -607,7 +607,7 @@ class Monster {
|
||||
String get name => const fb.StringReader().vTableGet(_bc, _bcOffset, 10, null);
|
||||
List<int> get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 14, null);
|
||||
Color get color => new Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 8));
|
||||
AnyTypeId get testType => new AnyTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 18, null));
|
||||
AnyTypeId get testType => new AnyTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 18, 0));
|
||||
dynamic get test {
|
||||
switch (testType?.value) {
|
||||
case 1: return Monster.reader.vTableGet(_bc, _bcOffset, 20, null);
|
||||
@@ -624,15 +624,15 @@ class Monster {
|
||||
Monster get enemy => Monster.reader.vTableGet(_bc, _bcOffset, 28, null);
|
||||
List<int> get testnestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 30, null);
|
||||
Stat get testempty => Stat.reader.vTableGet(_bc, _bcOffset, 32, null);
|
||||
bool get testbool => const fb.BoolReader().vTableGet(_bc, _bcOffset, 34, null);
|
||||
int get testhashs32Fnv1 => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 36, null);
|
||||
int get testhashu32Fnv1 => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 38, null);
|
||||
int get testhashs64Fnv1 => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 40, null);
|
||||
int get testhashu64Fnv1 => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 42, null);
|
||||
int get testhashs32Fnv1a => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 44, null);
|
||||
int get testhashu32Fnv1a => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 46, null);
|
||||
int get testhashs64Fnv1a => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 48, null);
|
||||
int get testhashu64Fnv1a => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 50, null);
|
||||
bool get testbool => const fb.BoolReader().vTableGet(_bc, _bcOffset, 34, false);
|
||||
int get testhashs32Fnv1 => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 36, 0);
|
||||
int get testhashu32Fnv1 => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 38, 0);
|
||||
int get testhashs64Fnv1 => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 40, 0);
|
||||
int get testhashu64Fnv1 => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 42, 0);
|
||||
int get testhashs32Fnv1a => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 44, 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 testhashu64Fnv1a => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 50, 0);
|
||||
List<bool> get testarrayofbools => const fb.ListReader<bool>(const fb.BoolReader()).vTableGet(_bc, _bcOffset, 52, null);
|
||||
double get testf => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 54, 3.14159);
|
||||
double get testf2 => const fb.Float32Reader().vTableGet(_bc, _bcOffset, 56, 3.0);
|
||||
@@ -645,12 +645,12 @@ class Monster {
|
||||
List<double> get vectorOfDoubles => const fb.ListReader<double>(const fb.Float64Reader()).vTableGet(_bc, _bcOffset, 70, null);
|
||||
my_game.InParentNamespace get parentNamespaceTest => my_game.InParentNamespace.reader.vTableGet(_bc, _bcOffset, 72, null);
|
||||
List<Referrable> get vectorOfReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGet(_bc, _bcOffset, 74, null);
|
||||
int get singleWeakReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 76, null);
|
||||
int get singleWeakReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 76, 0);
|
||||
List<int> get vectorOfWeakReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGet(_bc, _bcOffset, 78, null);
|
||||
List<Referrable> get vectorOfStrongReferrables => const fb.ListReader<Referrable>(Referrable.reader).vTableGet(_bc, _bcOffset, 80, null);
|
||||
int get coOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 82, null);
|
||||
int get coOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 82, 0);
|
||||
List<int> get vectorOfCoOwningReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGet(_bc, _bcOffset, 84, null);
|
||||
int get nonOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 86, null);
|
||||
int get nonOwningReference => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 86, 0);
|
||||
List<int> get vectorOfNonOwningReferences => const fb.ListReader<int>(const fb.Uint64Reader()).vTableGet(_bc, _bcOffset, 88, null);
|
||||
|
||||
@override
|
||||
@@ -1157,14 +1157,14 @@ class TypeAliases {
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
int get i8 => const fb.Int8Reader().vTableGet(_bc, _bcOffset, 4, null);
|
||||
int get u8 => const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 6, null);
|
||||
int get i16 => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, null);
|
||||
int get u16 => const fb.Uint16Reader().vTableGet(_bc, _bcOffset, 10, null);
|
||||
int get i32 => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 12, null);
|
||||
int get u32 => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 14, null);
|
||||
int get i64 => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 16, null);
|
||||
int get u64 => const fb.Uint64Reader().vTableGet(_bc, _bcOffset, 18, null);
|
||||
int get i8 => const fb.Int8Reader().vTableGet(_bc, _bcOffset, 4, 0);
|
||||
int get u8 => const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 6, 0);
|
||||
int get i16 => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 0);
|
||||
int get u16 => const fb.Uint16Reader().vTableGet(_bc, _bcOffset, 10, 0);
|
||||
int get i32 => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 12, 0);
|
||||
int get u32 => const fb.Uint32Reader().vTableGet(_bc, _bcOffset, 14, 0);
|
||||
int get i64 => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 16, 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 f64 => const fb.Float64Reader().vTableGet(_bc, _bcOffset, 22, 0.0);
|
||||
List<int> get v8 => const fb.ListReader<int>(const fb.Int8Reader()).vTableGet(_bc, _bcOffset, 24, null);
|
||||
|
||||
@@ -19,7 +19,7 @@ pushd "$(dirname $0)" >/dev/null
|
||||
command -v pub >/dev/null 2>&1 || { echo >&2 "Dart tests require `pub` but it's not installed. Aborting."; exit 1; }
|
||||
command -v dart >/dev/null 2>&1 || { echo >&2 "Dart tests require dart to be in path but it's not installed. Aborting."; exit 1; }
|
||||
# output required files to the dart folder so that pub will be able to
|
||||
# distrubte them and more people can more easily run the dart tests
|
||||
# distribute them and more people can more easily run the dart tests
|
||||
../flatc --dart -I include_test -o ../dart/test monster_test.fbs
|
||||
cp monsterdata_test.mon ../dart/test
|
||||
|
||||
@@ -31,4 +31,4 @@ pub get
|
||||
dart test/flat_buffers_test.dart
|
||||
|
||||
# cleanup
|
||||
rm ../dart/test/monsterdata_test.mon
|
||||
rm ../dart/test/monsterdata_test.mon
|
||||
|
||||
Reference in New Issue
Block a user