Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Dart imports #8380

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dart/test/bool_structs_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;



class Foo {
Foo._(this._bc, this._bcOffset);
factory Foo(List<int> bytes) {
Expand Down
1 change: 1 addition & 0 deletions dart/test/enums_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;



enum OptionsEnum {
A(1),
B(2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;


export './include_test1_generated.dart';
import './include_test1_generated.dart';

enum FromInclude {
Expand Down
5 changes: 5 additions & 0 deletions dart/test/includes_a.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace a;

table a {
options: uint8;
}
108 changes: 108 additions & 0 deletions dart/test/includes_a_a_generated.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names

library a;

import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;



class A {
A._(this._bc, this._bcOffset);
factory A(List<int> bytes) {
final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0);
}

static const fb.Reader<A> reader = _AReader();

final fb.BufferContext _bc;
final int _bcOffset;

int get options => const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 4, 0);

@override
String toString() {
return 'A{options: ${options}}';
}

AT unpack() => AT(
options: options);

static int pack(fb.Builder fbBuilder, AT? object) {
if (object == null) return 0;
return object.pack(fbBuilder);
}
}

class AT implements fb.Packable {
int options;

AT({
this.options = 0});

@override
int pack(fb.Builder fbBuilder) {
fbBuilder.startTable(1);
fbBuilder.addUint8(0, options);
return fbBuilder.endTable();
}

@override
String toString() {
return 'AT{options: ${options}}';
}
}

class _AReader extends fb.TableReader<A> {
const _AReader();

@override
A createObject(fb.BufferContext bc, int offset) =>
A._(bc, offset);
}

class ABuilder {
ABuilder(this.fbBuilder);

final fb.Builder fbBuilder;

void begin() {
fbBuilder.startTable(1);
}

int addOptions(int? options) {
fbBuilder.addUint8(0, options);
return fbBuilder.offset;
}

int finish() {
return fbBuilder.endTable();
}
}

class AObjectBuilder extends fb.ObjectBuilder {
final int? _options;

AObjectBuilder({
int? options,
})
: _options = options;

/// Finish building, and store into the [fbBuilder].
@override
int finish(fb.Builder fbBuilder) {
fbBuilder.startTable(1);
fbBuilder.addUint8(0, _options);
return fbBuilder.endTable();
}

/// Convenience method to serialize to byte list.
@override
Uint8List toBytes([String? fileIdentifier]) {
final fbBuilder = fb.Builder(deduplicateTables: false);
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
return fbBuilder.buffer;
}
}
7 changes: 7 additions & 0 deletions dart/test/includes_b.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include 'includes_a.fbs';

namespace a;

table b {
my_a: a;
}
112 changes: 112 additions & 0 deletions dart/test/includes_b_a_generated.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names

library a;

import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;


export './includes_a_a_generated.dart';
import './includes_a_a_generated.dart';

class B {
B._(this._bc, this._bcOffset);
factory B(List<int> bytes) {
final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0);
}

static const fb.Reader<B> reader = _BReader();

final fb.BufferContext _bc;
final int _bcOffset;

A? get myA => A.reader.vTableGetNullable(_bc, _bcOffset, 4);

@override
String toString() {
return 'B{myA: ${myA}}';
}

BT unpack() => BT(
myA: myA?.unpack());

static int pack(fb.Builder fbBuilder, BT? object) {
if (object == null) return 0;
return object.pack(fbBuilder);
}
}

class BT implements fb.Packable {
AT? myA;

BT({
this.myA});

@override
int pack(fb.Builder fbBuilder) {
final int? myAOffset = myA?.pack(fbBuilder);
fbBuilder.startTable(1);
fbBuilder.addOffset(0, myAOffset);
return fbBuilder.endTable();
}

@override
String toString() {
return 'BT{myA: ${myA}}';
}
}

class _BReader extends fb.TableReader<B> {
const _BReader();

@override
B createObject(fb.BufferContext bc, int offset) =>
B._(bc, offset);
}

class BBuilder {
BBuilder(this.fbBuilder);

final fb.Builder fbBuilder;

void begin() {
fbBuilder.startTable(1);
}

int addMyAOffset(int? offset) {
fbBuilder.addOffset(0, offset);
return fbBuilder.offset;
}

int finish() {
return fbBuilder.endTable();
}
}

class BObjectBuilder extends fb.ObjectBuilder {
final AObjectBuilder? _myA;

BObjectBuilder({
AObjectBuilder? myA,
})
: _myA = myA;

/// Finish building, and store into the [fbBuilder].
@override
int finish(fb.Builder fbBuilder) {
final int? myAOffset = _myA?.getOrCreateOffset(fbBuilder);
fbBuilder.startTable(1);
fbBuilder.addOffset(0, myAOffset);
return fbBuilder.endTable();
}

/// Convenience method to serialize to byte list.
@override
Uint8List toBytes([String? fileIdentifier]) {
final fbBuilder = fb.Builder(deduplicateTables: false);
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
return fbBuilder.buffer;
}
}
8 changes: 8 additions & 0 deletions dart/test/includes_c.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include 'includes_b.fbs';

namespace a;

table c {
my_a: a;
my_b: b;
}
127 changes: 127 additions & 0 deletions dart/test/includes_c_a_generated.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// automatically generated by the FlatBuffers compiler, do not modify
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names

library a;

import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;


export './includes_b_a_generated.dart';
import './includes_b_a_generated.dart';

class C {
C._(this._bc, this._bcOffset);
factory C(List<int> bytes) {
final rootRef = fb.BufferContext.fromBytes(bytes);
return reader.read(rootRef, 0);
}

static const fb.Reader<C> reader = _CReader();

final fb.BufferContext _bc;
final int _bcOffset;

A? get myA => A.reader.vTableGetNullable(_bc, _bcOffset, 4);
B? get myB => B.reader.vTableGetNullable(_bc, _bcOffset, 6);

@override
String toString() {
return 'C{myA: ${myA}, myB: ${myB}}';
}

CT unpack() => CT(
myA: myA?.unpack(),
myB: myB?.unpack());

static int pack(fb.Builder fbBuilder, CT? object) {
if (object == null) return 0;
return object.pack(fbBuilder);
}
}

class CT implements fb.Packable {
AT? myA;
BT? myB;

CT({
this.myA,
this.myB});

@override
int pack(fb.Builder fbBuilder) {
final int? myAOffset = myA?.pack(fbBuilder);
final int? myBOffset = myB?.pack(fbBuilder);
fbBuilder.startTable(2);
fbBuilder.addOffset(0, myAOffset);
fbBuilder.addOffset(1, myBOffset);
return fbBuilder.endTable();
}

@override
String toString() {
return 'CT{myA: ${myA}, myB: ${myB}}';
}
}

class _CReader extends fb.TableReader<C> {
const _CReader();

@override
C createObject(fb.BufferContext bc, int offset) =>
C._(bc, offset);
}

class CBuilder {
CBuilder(this.fbBuilder);

final fb.Builder fbBuilder;

void begin() {
fbBuilder.startTable(2);
}

int addMyAOffset(int? offset) {
fbBuilder.addOffset(0, offset);
return fbBuilder.offset;
}
int addMyBOffset(int? offset) {
fbBuilder.addOffset(1, offset);
return fbBuilder.offset;
}

int finish() {
return fbBuilder.endTable();
}
}

class CObjectBuilder extends fb.ObjectBuilder {
final AObjectBuilder? _myA;
final BObjectBuilder? _myB;

CObjectBuilder({
AObjectBuilder? myA,
BObjectBuilder? myB,
})
: _myA = myA,
_myB = myB;

/// Finish building, and store into the [fbBuilder].
@override
int finish(fb.Builder fbBuilder) {
final int? myAOffset = _myA?.getOrCreateOffset(fbBuilder);
final int? myBOffset = _myB?.getOrCreateOffset(fbBuilder);
fbBuilder.startTable(2);
fbBuilder.addOffset(0, myAOffset);
fbBuilder.addOffset(1, myBOffset);
return fbBuilder.endTable();
}

/// Convenience method to serialize to byte list.
@override
Uint8List toBytes([String? fileIdentifier]) {
final fbBuilder = fb.Builder(deduplicateTables: false);
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
return fbBuilder.buffer;
}
}
Loading
Loading