diff options
author | Dan Field <dfield@gmail.com> | 2018-08-09 12:50:54 -0400 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2018-08-09 09:50:54 -0700 |
commit | fd40cc61a4291791ec9f4a98178a7b021ff778eb (patch) | |
tree | 318477c531d953fc50af5a0a9c780a4558d8b544 /dart | |
parent | 38a6623f348ff055faea9cf659d17b04fd44506a (diff) | |
download | flatbuffers-fd40cc61a4291791ec9f4a98178a7b021ff778eb.tar.gz flatbuffers-fd40cc61a4291791ec9f4a98178a7b021ff778eb.tar.bz2 flatbuffers-fd40cc61a4291791ec9f4a98178a7b021ff778eb.zip |
Ensure strings are null terminated when written from Dart (#4862)
* Update for Dart 2.x constants
* Fix strings, update test, add CHANGELOG for Dart
Diffstat (limited to 'dart')
-rw-r--r-- | dart/CHANGELOG.md | 14 | ||||
-rw-r--r-- | dart/lib/flat_buffers.dart | 2 | ||||
-rw-r--r-- | dart/pubspec.yaml | 4 | ||||
-rw-r--r-- | dart/test/flat_buffers_test.dart | 2 | ||||
-rw-r--r-- | dart/test/monster_test_my_game.example_generated.dart | 52 |
5 files changed, 44 insertions, 30 deletions
diff --git a/dart/CHANGELOG.md b/dart/CHANGELOG.md new file mode 100644 index 00000000..5e2d2dee --- /dev/null +++ b/dart/CHANGELOG.md @@ -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
\ No newline at end of file diff --git a/dart/lib/flat_buffers.dart b/dart/lib/flat_buffers.dart index 6bd415ac..e2512604 100644 --- a/dart/lib/flat_buffers.dart +++ b/dart/lib/flat_buffers.dart @@ -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; diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml index 3f908773..2fda1d4d 100644 --- a/dart/pubspec.yaml +++ b/dart/pubspec.yaml @@ -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: diff --git a/dart/test/flat_buffers_test.dart b/dart/test/flat_buffers_test.dart index f38bdbb3..f9c5e01c 100644 --- a/dart/test/flat_buffers_test.dart +++ b/dart/test/flat_buffers_test.dart @@ -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}'); } } diff --git a/dart/test/monster_test_my_game.example_generated.dart b/dart/test/monster_test_my_game.example_generated.dart index d85b5919..6106a3ed 100644 --- a/dart/test/monster_test_my_game.example_generated.dart +++ b/dart/test/monster_test_my_game.example_generated.dart @@ -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); |