summaryrefslogtreecommitdiff
path: root/dart
diff options
context:
space:
mode:
Diffstat (limited to 'dart')
-rw-r--r--dart/lib/flat_buffers.dart9
-rw-r--r--dart/test/bool_structs.fbs10
-rw-r--r--dart/test/flat_buffers_test.dart20
3 files changed, 37 insertions, 2 deletions
diff --git a/dart/lib/flat_buffers.dart b/dart/lib/flat_buffers.dart
index d27d4bf3..c69e01f1 100644
--- a/dart/lib/flat_buffers.dart
+++ b/dart/lib/flat_buffers.dart
@@ -401,6 +401,15 @@ class Builder {
_setFloat32AtTail(_tail, value);
}
+ /// Writes a bool to the tail of the buffer after preparing space for it.
+ /// Bools are represented as a Uint8, with the value set to '1' for true, and '0' for false
+ ///
+ /// Updates the [offset] pointer. This method is intended for use when writing structs to the buffer.
+ void putBool(bool value) {
+ _prepare(_sizeofUint8, 1);
+ _buf.setInt8(_buf.lengthInBytes - _tail, value ? 1 : 0);
+ }
+
/// Writes a Int64 to the tail of the buffer after preparing space for it.
///
/// Updates the [offset] pointer. This method is intended for use when writing structs to the buffer.
diff --git a/dart/test/bool_structs.fbs b/dart/test/bool_structs.fbs
new file mode 100644
index 00000000..47b26b5b
--- /dev/null
+++ b/dart/test/bool_structs.fbs
@@ -0,0 +1,10 @@
+// Test for #7355
+table Foo {
+ my_foo : foo_properties;
+}
+
+struct foo_properties
+{
+ a : bool;
+ b : bool;
+}
diff --git a/dart/test/flat_buffers_test.dart b/dart/test/flat_buffers_test.dart
index 79207366..99a0e7c3 100644
--- a/dart/test/flat_buffers_test.dart
+++ b/dart/test/flat_buffers_test.dart
@@ -14,6 +14,7 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
import './monster_test_my_game.example_generated.dart' as example;
import './monster_test_my_game.example2_generated.dart' as example2;
import './list_of_enums_generated.dart' as example3;
+import './bool_structs_generated.dart' as example4;
import './keyword_test_keyword_test_generated.dart' as keyword_test;
main() {
@@ -910,8 +911,11 @@ class GeneratorTest {
@reflectiveTest
class ListOfEnumsTest {
void test_listOfEnums() async {
- var mytable = example3.MyTableObjectBuilder(
- options: [example3.OptionsEnum.A, example3.OptionsEnum.B, example3.OptionsEnum.C]);
+ var mytable = example3.MyTableObjectBuilder(options: [
+ example3.OptionsEnum.A,
+ example3.OptionsEnum.B,
+ example3.OptionsEnum.C
+ ]);
var bytes = mytable.toBytes();
var mytable_read = example3.MyTable(bytes);
expect(mytable_read.options![0].value, example3.OptionsEnum.A.value);
@@ -919,3 +923,15 @@ class ListOfEnumsTest {
expect(mytable_read.options![2].value, example3.OptionsEnum.C.value);
}
}
+
+@reflectiveTest
+class BoolInStructTest {
+ void test_boolInStruct() async {
+ var mystruct = example4.FooObjectBuilder(
+ myFoo: example4.FooPropertiesObjectBuilder(a: true, b: false));
+ var bytes = mystruct.toBytes();
+ var mystruct_read = example4.Foo(bytes);
+ expect(mystruct_read.myFoo!.a, true);
+ expect(mystruct_read.myFoo!.b, false);
+ }
+}