mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 06:42:40 +00:00
Dart object API (#6682)
* dart test scripts - generate with `--gen-object-api` * Dart object API, pack and unpack methods (WIP) * Dart flatc - extract Builder code to separate functions to reuse it in Pack() * Dart flatc - use builder field-building implementation in pack() * Dart flatc - add pack() as an intance method of the "T" class * Dart object API - make inner fields unpacked as well * Dart object API - use pack() when collecting field offsets * Dart object API - use packOnce() for fields that are structs or vectors of structs * Dart object API - remove obsolete union support TODO * Dart object API - minor review changes, test and fixes * Dart object API - revert packOnce() - not supported by other object API implementations * Dart object API - update docs * update dart generated code in tests/ to fix CI failure on ./scripts/check-generated-code.sh * Dart flatc - fix compilation for old MSVC and c++0x
This commit is contained in:
@@ -104,6 +104,34 @@ class TableInNestedNS {
|
||||
String toString() {
|
||||
return 'TableInNestedNS{foo: $foo}';
|
||||
}
|
||||
|
||||
TableInNestedNST unpack() => TableInNestedNST(
|
||||
foo: foo);
|
||||
|
||||
static int pack(fb.Builder fbBuilder, TableInNestedNST object) {
|
||||
if (object == null) return 0;
|
||||
return object.pack(fbBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
class TableInNestedNST {
|
||||
int foo;
|
||||
|
||||
TableInNestedNST({
|
||||
this.foo});
|
||||
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
assert(fbBuilder != null);
|
||||
|
||||
fbBuilder.startTable();
|
||||
fbBuilder.addInt32(0, foo);
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TableInNestedNST{foo: $foo}';
|
||||
}
|
||||
}
|
||||
|
||||
class _TableInNestedNSReader extends fb.TableReader<TableInNestedNS> {
|
||||
@@ -177,6 +205,37 @@ class StructInNestedNS {
|
||||
String toString() {
|
||||
return 'StructInNestedNS{a: $a, b: $b}';
|
||||
}
|
||||
|
||||
StructInNestedNST unpack() => StructInNestedNST(
|
||||
a: a,
|
||||
b: b);
|
||||
|
||||
static int pack(fb.Builder fbBuilder, StructInNestedNST object) {
|
||||
if (object == null) return 0;
|
||||
return object.pack(fbBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
class StructInNestedNST {
|
||||
int a;
|
||||
int b;
|
||||
|
||||
StructInNestedNST({
|
||||
this.a,
|
||||
this.b});
|
||||
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
assert(fbBuilder != null);
|
||||
|
||||
fbBuilder.putInt32(b);
|
||||
fbBuilder.putInt32(a);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'StructInNestedNST{a: $a, b: $b}';
|
||||
}
|
||||
}
|
||||
|
||||
class _StructInNestedNSReader extends fb.StructReader<StructInNestedNS> {
|
||||
|
||||
Reference in New Issue
Block a user