[TS/JS] Entry point per namespace and reworked 1.x compatible single file build (#7510)

* [TS/JS] Entry point per namespace

* Fix handling of outputpath and array_test

* Attempt to fix generate_code

* Fix cwd for ts in generate_code

* Attempt to fixup bazel and some docs

* Add --ts-flat-files to bazel build to get bundle

* Move to DEFAULT_FLATC_TS_ARGS

* Attempt to add esbuild

* Attempt to use npm instead

* Remove futile attempt to add esbuild

* Attempt to as bazel esbuild

* Shuffle

* Upgrade bazel deps

* Revert failed attempts to get bazel working

* Ignore flatc tests for now

* Add esbuild dependency

* `package.json` Include esbuild

* `WORKSPACE` Add fetching esbuild binary

* Update WORKSPACE

* Unfreeze Lockfile

* Update WORKSPACE

* Update BUILD.bazel

* Rework to suggest instead of running external bundler

* Add esbuild generation to test script

* Prelim bundle test

* Run test JavaScriptTest from flatbuffers 1.x

* Deps upgrade

* Clang format fix

* Revert bazel changes

* Fix newline

* Generate with type declarations

* Handle "empty" root namespace

* Adjust tests for typescript_keywords.ts

* Separate test procedure for old node resolution module output

* Fix rel path for root level re-exports

* Bazel support for esbuild-based flatc

Unfortunately, we lose typing information because the new esbuild method
of generating single files does not generate type information.

The method used here is a bit hack-ish because it relies on parsing the
console output of flatc to figure out what to do.

* Try to fix bazel build for when node isn't present on host

* Auto formatting fixes

* Fix missing generated code

Co-authored-by: Derek Bailey <derekbailey@google.com>
Co-authored-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
This commit is contained in:
Björn Harrtell
2023-01-21 21:22:22 +01:00
committed by GitHub
parent 1703662285
commit ef76b5ece4
249 changed files with 11509 additions and 15906 deletions

View File

@@ -1,64 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
export class Attacker {
constructor() {
this.bb = null;
this.bb_pos = 0;
}
__init(i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
}
static getRootAsAttacker(bb, obj) {
return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
static getSizePrefixedRootAsAttacker(bb, obj) {
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
swordAttackDamage() {
const offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
}
mutate_sword_attack_damage(value) {
const offset = this.bb.__offset(this.bb_pos, 4);
if (offset === 0) {
return false;
}
this.bb.writeInt32(this.bb_pos + offset, value);
return true;
}
static getFullyQualifiedName() {
return 'Attacker';
}
static startAttacker(builder) {
builder.startObject(1);
}
static addSwordAttackDamage(builder, swordAttackDamage) {
builder.addFieldInt32(0, swordAttackDamage, 0);
}
static endAttacker(builder) {
const offset = builder.endObject();
return offset;
}
static createAttacker(builder, swordAttackDamage) {
Attacker.startAttacker(builder);
Attacker.addSwordAttackDamage(builder, swordAttackDamage);
return Attacker.endAttacker(builder);
}
unpack() {
return new AttackerT(this.swordAttackDamage());
}
unpackTo(_o) {
_o.swordAttackDamage = this.swordAttackDamage();
}
}
export class AttackerT {
constructor(swordAttackDamage = 0) {
this.swordAttackDamage = swordAttackDamage;
}
pack(builder) {
return Attacker.createAttacker(builder, this.swordAttackDamage);
}
}

View File

@@ -1,87 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
export class Attacker {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):Attacker {
this.bb_pos = i;
this.bb = bb;
return this;
}
static getRootAsAttacker(bb:flatbuffers.ByteBuffer, obj?:Attacker):Attacker {
return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
static getSizePrefixedRootAsAttacker(bb:flatbuffers.ByteBuffer, obj?:Attacker):Attacker {
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
swordAttackDamage():number {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
}
mutate_sword_attack_damage(value:number):boolean {
const offset = this.bb!.__offset(this.bb_pos, 4);
if (offset === 0) {
return false;
}
this.bb!.writeInt32(this.bb_pos + offset, value);
return true;
}
static getFullyQualifiedName():string {
return 'Attacker';
}
static startAttacker(builder:flatbuffers.Builder) {
builder.startObject(1);
}
static addSwordAttackDamage(builder:flatbuffers.Builder, swordAttackDamage:number) {
builder.addFieldInt32(0, swordAttackDamage, 0);
}
static endAttacker(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}
static createAttacker(builder:flatbuffers.Builder, swordAttackDamage:number):flatbuffers.Offset {
Attacker.startAttacker(builder);
Attacker.addSwordAttackDamage(builder, swordAttackDamage);
return Attacker.endAttacker(builder);
}
unpack(): AttackerT {
return new AttackerT(
this.swordAttackDamage()
);
}
unpackTo(_o: AttackerT): void {
_o.swordAttackDamage = this.swordAttackDamage();
}
}
export class AttackerT {
constructor(
public swordAttackDamage: number = 0
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return Attacker.createAttacker(builder,
this.swordAttackDamage
);
}
}

View File

@@ -1,44 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
export class BookReader {
constructor() {
this.bb = null;
this.bb_pos = 0;
}
__init(i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
}
booksRead() {
return this.bb.readInt32(this.bb_pos);
}
mutate_books_read(value) {
this.bb.writeInt32(this.bb_pos + 0, value);
return true;
}
static getFullyQualifiedName() {
return 'BookReader';
}
static sizeOf() {
return 4;
}
static createBookReader(builder, books_read) {
builder.prep(4, 4);
builder.writeInt32(books_read);
return builder.offset();
}
unpack() {
return new BookReaderT(this.booksRead());
}
unpackTo(_o) {
_o.booksRead = this.booksRead();
}
}
export class BookReaderT {
constructor(booksRead = 0) {
this.booksRead = booksRead;
}
pack(builder) {
return BookReader.createBookReader(builder, this.booksRead);
}
}

View File

@@ -1,63 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
export class BookReader {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):BookReader {
this.bb_pos = i;
this.bb = bb;
return this;
}
booksRead():number {
return this.bb!.readInt32(this.bb_pos);
}
mutate_books_read(value:number):boolean {
this.bb!.writeInt32(this.bb_pos + 0, value);
return true;
}
static getFullyQualifiedName():string {
return 'BookReader';
}
static sizeOf():number {
return 4;
}
static createBookReader(builder:flatbuffers.Builder, books_read: number):flatbuffers.Offset {
builder.prep(4, 4);
builder.writeInt32(books_read);
return builder.offset();
}
unpack(): BookReaderT {
return new BookReaderT(
this.booksRead()
);
}
unpackTo(_o: BookReaderT): void {
_o.booksRead = this.booksRead();
}
}
export class BookReaderT {
constructor(
public booksRead: number = 0
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return BookReader.createBookReader(builder,
this.booksRead
);
}
}

View File

@@ -1,38 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import { Attacker } from './attacker';
import { BookReader } from './book-reader';
import { Rapunzel } from './rapunzel';
export var Character;
(function (Character) {
Character[Character["NONE"] = 0] = "NONE";
Character[Character["MuLan"] = 1] = "MuLan";
Character[Character["Rapunzel"] = 2] = "Rapunzel";
Character[Character["Belle"] = 3] = "Belle";
Character[Character["BookFan"] = 4] = "BookFan";
Character[Character["Other"] = 5] = "Other";
Character[Character["Unused"] = 6] = "Unused";
})(Character || (Character = {}));
export function unionToCharacter(type, accessor) {
switch (Character[type]) {
case 'NONE': return null;
case 'MuLan': return accessor(new Attacker());
case 'Rapunzel': return accessor(new Rapunzel());
case 'Belle': return accessor(new BookReader());
case 'BookFan': return accessor(new BookReader());
case 'Other': return accessor('');
case 'Unused': return accessor('');
default: return null;
}
}
export function unionListToCharacter(type, accessor, index) {
switch (Character[type]) {
case 'NONE': return null;
case 'MuLan': return accessor(index, new Attacker());
case 'Rapunzel': return accessor(index, new Rapunzel());
case 'Belle': return accessor(index, new BookReader());
case 'BookFan': return accessor(index, new BookReader());
case 'Other': return accessor(index, '');
case 'Unused': return accessor(index, '');
default: return null;
}
}

View File

@@ -1,49 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import { Attacker, AttackerT } from './attacker';
import { BookReader, BookReaderT } from './book-reader';
import { Rapunzel, RapunzelT } from './rapunzel';
export enum Character {
NONE = 0,
MuLan = 1,
Rapunzel = 2,
Belle = 3,
BookFan = 4,
Other = 5,
Unused = 6
}
export function unionToCharacter(
type: Character,
accessor: (obj:Attacker|BookReader|Rapunzel|string) => Attacker|BookReader|Rapunzel|string|null
): Attacker|BookReader|Rapunzel|string|null {
switch(Character[type]) {
case 'NONE': return null;
case 'MuLan': return accessor(new Attacker())! as Attacker;
case 'Rapunzel': return accessor(new Rapunzel())! as Rapunzel;
case 'Belle': return accessor(new BookReader())! as BookReader;
case 'BookFan': return accessor(new BookReader())! as BookReader;
case 'Other': return accessor('') as string;
case 'Unused': return accessor('') as string;
default: return null;
}
}
export function unionListToCharacter(
type: Character,
accessor: (index: number, obj:Attacker|BookReader|Rapunzel|string) => Attacker|BookReader|Rapunzel|string|null,
index: number
): Attacker|BookReader|Rapunzel|string|null {
switch(Character[type]) {
case 'NONE': return null;
case 'MuLan': return accessor(index, new Attacker())! as Attacker;
case 'Rapunzel': return accessor(index, new Rapunzel())! as Rapunzel;
case 'Belle': return accessor(index, new BookReader())! as BookReader;
case 'BookFan': return accessor(index, new BookReader())! as BookReader;
case 'Other': return accessor(index, '') as string;
case 'Unused': return accessor(index, '') as string;
default: return null;
}
}

View File

@@ -1,63 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
export class FallingTub {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):FallingTub {
this.bb_pos = i;
this.bb = bb;
return this;
}
weight():number {
return this.bb!.readInt32(this.bb_pos);
}
mutate_weight(value:number):boolean {
this.bb!.writeInt32(this.bb_pos + 0, value);
return true;
}
static getFullyQualifiedName():string {
return 'FallingTub';
}
static sizeOf():number {
return 4;
}
static createFallingTub(builder:flatbuffers.Builder, weight: number):flatbuffers.Offset {
builder.prep(4, 4);
builder.writeInt32(weight);
return builder.offset();
}
unpack(): FallingTubT {
return new FallingTubT(
this.weight()
);
}
unpackTo(_o: FallingTubT): void {
_o.weight = this.weight();
}
}
export class FallingTubT {
constructor(
public weight: number = 0
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return FallingTub.createFallingTub(builder,
this.weight
);
}
}

View File

@@ -1,36 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import { FallingTub, FallingTubT } from './falling-tub';
import { HandFan, HandFanT } from './hand-fan';
export enum Gadget {
NONE = 0,
FallingTub = 1,
HandFan = 2
}
export function unionToGadget(
type: Gadget,
accessor: (obj:FallingTub|HandFan) => FallingTub|HandFan|null
): FallingTub|HandFan|null {
switch(Gadget[type]) {
case 'NONE': return null;
case 'FallingTub': return accessor(new FallingTub())! as FallingTub;
case 'HandFan': return accessor(new HandFan())! as HandFan;
default: return null;
}
}
export function unionListToGadget(
type: Gadget,
accessor: (index: number, obj:FallingTub|HandFan) => FallingTub|HandFan|null,
index: number
): FallingTub|HandFan|null {
switch(Gadget[type]) {
case 'NONE': return null;
case 'FallingTub': return accessor(index, new FallingTub())! as FallingTub;
case 'HandFan': return accessor(index, new HandFan())! as HandFan;
default: return null;
}
}

View File

@@ -1,87 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
export class HandFan {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):HandFan {
this.bb_pos = i;
this.bb = bb;
return this;
}
static getRootAsHandFan(bb:flatbuffers.ByteBuffer, obj?:HandFan):HandFan {
return (obj || new HandFan()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
static getSizePrefixedRootAsHandFan(bb:flatbuffers.ByteBuffer, obj?:HandFan):HandFan {
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
return (obj || new HandFan()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
length():number {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
}
mutate_length(value:number):boolean {
const offset = this.bb!.__offset(this.bb_pos, 4);
if (offset === 0) {
return false;
}
this.bb!.writeInt32(this.bb_pos + offset, value);
return true;
}
static getFullyQualifiedName():string {
return 'HandFan';
}
static startHandFan(builder:flatbuffers.Builder) {
builder.startObject(1);
}
static addLength(builder:flatbuffers.Builder, length:number) {
builder.addFieldInt32(0, length, 0);
}
static endHandFan(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}
static createHandFan(builder:flatbuffers.Builder, length:number):flatbuffers.Offset {
HandFan.startHandFan(builder);
HandFan.addLength(builder, length);
return HandFan.endHandFan(builder);
}
unpack(): HandFanT {
return new HandFanT(
this.length()
);
}
unpackTo(_o: HandFanT): void {
_o.length = this.length();
}
}
export class HandFanT {
constructor(
public length: number = 0
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return HandFan.createHandFan(builder,
this.length
);
}
}

View File

@@ -1,185 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
import { Character, unionToCharacter, unionListToCharacter } from './character';
export class Movie {
constructor() {
this.bb = null;
this.bb_pos = 0;
}
__init(i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
}
static getRootAsMovie(bb, obj) {
return (obj || new Movie()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
static getSizePrefixedRootAsMovie(bb, obj) {
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
return (obj || new Movie()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
static bufferHasIdentifier(bb) {
return bb.__has_identifier('MOVI');
}
mainCharacterType() {
const offset = this.bb.__offset(this.bb_pos, 4);
return offset ? this.bb.readUint8(this.bb_pos + offset) : Character.NONE;
}
mainCharacter(obj) {
const offset = this.bb.__offset(this.bb_pos, 6);
return offset ? this.bb.__union_with_string(obj, this.bb_pos + offset) : null;
}
charactersType(index) {
const offset = this.bb.__offset(this.bb_pos, 8);
return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
}
charactersTypeLength() {
const offset = this.bb.__offset(this.bb_pos, 8);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
}
charactersTypeArray() {
const offset = this.bb.__offset(this.bb_pos, 8);
return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
}
characters(index, obj) {
const offset = this.bb.__offset(this.bb_pos, 10);
return offset ? this.bb.__union_with_string(obj, this.bb.__vector(this.bb_pos + offset) + index * 4) : null;
}
charactersLength() {
const offset = this.bb.__offset(this.bb_pos, 10);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
}
static getFullyQualifiedName() {
return 'Movie';
}
static startMovie(builder) {
builder.startObject(4);
}
static addMainCharacterType(builder, mainCharacterType) {
builder.addFieldInt8(0, mainCharacterType, Character.NONE);
}
static addMainCharacter(builder, mainCharacterOffset) {
builder.addFieldOffset(1, mainCharacterOffset, 0);
}
static addCharactersType(builder, charactersTypeOffset) {
builder.addFieldOffset(2, charactersTypeOffset, 0);
}
static createCharactersTypeVector(builder, data) {
builder.startVector(1, data.length, 1);
for (let i = data.length - 1; i >= 0; i--) {
builder.addInt8(data[i]);
}
return builder.endVector();
}
static startCharactersTypeVector(builder, numElems) {
builder.startVector(1, numElems, 1);
}
static addCharacters(builder, charactersOffset) {
builder.addFieldOffset(3, charactersOffset, 0);
}
static createCharactersVector(builder, data) {
builder.startVector(4, data.length, 4);
for (let i = data.length - 1; i >= 0; i--) {
builder.addOffset(data[i]);
}
return builder.endVector();
}
static startCharactersVector(builder, numElems) {
builder.startVector(4, numElems, 4);
}
static endMovie(builder) {
const offset = builder.endObject();
return offset;
}
static finishMovieBuffer(builder, offset) {
builder.finish(offset, 'MOVI');
}
static finishSizePrefixedMovieBuffer(builder, offset) {
builder.finish(offset, 'MOVI', true);
}
static createMovie(builder, mainCharacterType, mainCharacterOffset, charactersTypeOffset, charactersOffset) {
Movie.startMovie(builder);
Movie.addMainCharacterType(builder, mainCharacterType);
Movie.addMainCharacter(builder, mainCharacterOffset);
Movie.addCharactersType(builder, charactersTypeOffset);
Movie.addCharacters(builder, charactersOffset);
return Movie.endMovie(builder);
}
unpack() {
return new MovieT(this.mainCharacterType(), (() => {
let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
if (temp === null) {
return null;
}
if (typeof temp === 'string') {
return temp;
}
return temp.unpack();
})(), this.bb.createScalarList(this.charactersType.bind(this), this.charactersTypeLength()), (() => {
let ret = [];
for (let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) {
let targetEnum = this.charactersType(targetEnumIndex);
if (targetEnum === null || Character[targetEnum] === 'NONE') {
continue;
}
let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
if (temp === null) {
continue;
}
if (typeof temp === 'string') {
ret.push(temp);
continue;
}
ret.push(temp.unpack());
}
return ret;
})());
}
unpackTo(_o) {
_o.mainCharacterType = this.mainCharacterType();
_o.mainCharacter = (() => {
let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
if (temp === null) {
return null;
}
if (typeof temp === 'string') {
return temp;
}
return temp.unpack();
})();
_o.charactersType = this.bb.createScalarList(this.charactersType.bind(this), this.charactersTypeLength());
_o.characters = (() => {
let ret = [];
for (let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) {
let targetEnum = this.charactersType(targetEnumIndex);
if (targetEnum === null || Character[targetEnum] === 'NONE') {
continue;
}
let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
if (temp === null) {
continue;
}
if (typeof temp === 'string') {
ret.push(temp);
continue;
}
ret.push(temp.unpack());
}
return ret;
})();
}
}
export class MovieT {
constructor(mainCharacterType = Character.NONE, mainCharacter = null, charactersType = [], characters = []) {
this.mainCharacterType = mainCharacterType;
this.mainCharacter = mainCharacter;
this.charactersType = charactersType;
this.characters = characters;
}
pack(builder) {
const mainCharacter = builder.createObjectOffset(this.mainCharacter);
const charactersType = Movie.createCharactersTypeVector(builder, this.charactersType);
const characters = Movie.createCharactersVector(builder, builder.createObjectOffsetList(this.characters));
return Movie.createMovie(builder, this.mainCharacterType, mainCharacter, charactersType, characters);
}
}

View File

@@ -1,211 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
import { Attacker, AttackerT } from './attacker';
import { BookReader, BookReaderT } from './book-reader';
import { Character, unionToCharacter, unionListToCharacter } from './character';
import { Rapunzel, RapunzelT } from './rapunzel';
export class Movie {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):Movie {
this.bb_pos = i;
this.bb = bb;
return this;
}
static getRootAsMovie(bb:flatbuffers.ByteBuffer, obj?:Movie):Movie {
return (obj || new Movie()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
static getSizePrefixedRootAsMovie(bb:flatbuffers.ByteBuffer, obj?:Movie):Movie {
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
return (obj || new Movie()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean {
return bb.__has_identifier('MOVI');
}
mainCharacterType():Character {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? this.bb!.readUint8(this.bb_pos + offset) : Character.NONE;
}
mainCharacter<T extends flatbuffers.Table>(obj:any|string):any|string|null {
const offset = this.bb!.__offset(this.bb_pos, 6);
return offset ? this.bb!.__union_with_string(obj, this.bb_pos + offset) : null;
}
charactersType(index: number):Character|null {
const offset = this.bb!.__offset(this.bb_pos, 8);
return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0;
}
charactersTypeLength():number {
const offset = this.bb!.__offset(this.bb_pos, 8);
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
}
charactersTypeArray():Uint8Array|null {
const offset = this.bb!.__offset(this.bb_pos, 8);
return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
}
characters(index: number, obj:any|string):any|string|null {
const offset = this.bb!.__offset(this.bb_pos, 10);
return offset ? this.bb!.__union_with_string(obj, this.bb!.__vector(this.bb_pos + offset) + index * 4) : null;
}
charactersLength():number {
const offset = this.bb!.__offset(this.bb_pos, 10);
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
}
static getFullyQualifiedName():string {
return 'Movie';
}
static startMovie(builder:flatbuffers.Builder) {
builder.startObject(4);
}
static addMainCharacterType(builder:flatbuffers.Builder, mainCharacterType:Character) {
builder.addFieldInt8(0, mainCharacterType, Character.NONE);
}
static addMainCharacter(builder:flatbuffers.Builder, mainCharacterOffset:flatbuffers.Offset) {
builder.addFieldOffset(1, mainCharacterOffset, 0);
}
static addCharactersType(builder:flatbuffers.Builder, charactersTypeOffset:flatbuffers.Offset) {
builder.addFieldOffset(2, charactersTypeOffset, 0);
}
static createCharactersTypeVector(builder:flatbuffers.Builder, data:Character[]):flatbuffers.Offset {
builder.startVector(1, data.length, 1);
for (let i = data.length - 1; i >= 0; i--) {
builder.addInt8(data[i]!);
}
return builder.endVector();
}
static startCharactersTypeVector(builder:flatbuffers.Builder, numElems:number) {
builder.startVector(1, numElems, 1);
}
static addCharacters(builder:flatbuffers.Builder, charactersOffset:flatbuffers.Offset) {
builder.addFieldOffset(3, charactersOffset, 0);
}
static createCharactersVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
builder.startVector(4, data.length, 4);
for (let i = data.length - 1; i >= 0; i--) {
builder.addOffset(data[i]!);
}
return builder.endVector();
}
static startCharactersVector(builder:flatbuffers.Builder, numElems:number) {
builder.startVector(4, numElems, 4);
}
static endMovie(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}
static finishMovieBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
builder.finish(offset, 'MOVI');
}
static finishSizePrefixedMovieBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
builder.finish(offset, 'MOVI', true);
}
static createMovie(builder:flatbuffers.Builder, mainCharacterType:Character, mainCharacterOffset:flatbuffers.Offset, charactersTypeOffset:flatbuffers.Offset, charactersOffset:flatbuffers.Offset):flatbuffers.Offset {
Movie.startMovie(builder);
Movie.addMainCharacterType(builder, mainCharacterType);
Movie.addMainCharacter(builder, mainCharacterOffset);
Movie.addCharactersType(builder, charactersTypeOffset);
Movie.addCharacters(builder, charactersOffset);
return Movie.endMovie(builder);
}
unpack(): MovieT {
return new MovieT(
this.mainCharacterType(),
(() => {
let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
if(temp === null) { return null; }
if(typeof temp === 'string') { return temp; }
return temp.unpack()
})(),
this.bb!.createScalarList(this.charactersType.bind(this), this.charactersTypeLength()),
(() => {
let ret = [];
for(let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) {
let targetEnum = this.charactersType(targetEnumIndex);
if(targetEnum === null || Character[targetEnum!] === 'NONE') { continue; }
let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
if(temp === null) { continue; }
if(typeof temp === 'string') { ret.push(temp); continue; }
ret.push(temp.unpack());
}
return ret;
})()
);
}
unpackTo(_o: MovieT): void {
_o.mainCharacterType = this.mainCharacterType();
_o.mainCharacter = (() => {
let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
if(temp === null) { return null; }
if(typeof temp === 'string') { return temp; }
return temp.unpack()
})();
_o.charactersType = this.bb!.createScalarList(this.charactersType.bind(this), this.charactersTypeLength());
_o.characters = (() => {
let ret = [];
for(let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) {
let targetEnum = this.charactersType(targetEnumIndex);
if(targetEnum === null || Character[targetEnum!] === 'NONE') { continue; }
let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
if(temp === null) { continue; }
if(typeof temp === 'string') { ret.push(temp); continue; }
ret.push(temp.unpack());
}
return ret;
})();
}
}
export class MovieT {
constructor(
public mainCharacterType: Character = Character.NONE,
public mainCharacter: AttackerT|BookReaderT|RapunzelT|string|null = null,
public charactersType: (Character)[] = [],
public characters: (AttackerT|BookReaderT|RapunzelT|string)[] = []
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
const mainCharacter = builder.createObjectOffset(this.mainCharacter);
const charactersType = Movie.createCharactersTypeVector(builder, this.charactersType);
const characters = Movie.createCharactersVector(builder, builder.createObjectOffsetList(this.characters));
return Movie.createMovie(builder,
this.mainCharacterType,
mainCharacter,
charactersType,
characters
);
}
}

View File

@@ -1,44 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
export class Rapunzel {
constructor() {
this.bb = null;
this.bb_pos = 0;
}
__init(i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
}
hairLength() {
return this.bb.readInt32(this.bb_pos);
}
mutate_hair_length(value) {
this.bb.writeInt32(this.bb_pos + 0, value);
return true;
}
static getFullyQualifiedName() {
return 'Rapunzel';
}
static sizeOf() {
return 4;
}
static createRapunzel(builder, hair_length) {
builder.prep(4, 4);
builder.writeInt32(hair_length);
return builder.offset();
}
unpack() {
return new RapunzelT(this.hairLength());
}
unpackTo(_o) {
_o.hairLength = this.hairLength();
}
}
export class RapunzelT {
constructor(hairLength = 0) {
this.hairLength = hairLength;
}
pack(builder) {
return Rapunzel.createRapunzel(builder, this.hairLength);
}
}

View File

@@ -1,63 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
export class Rapunzel {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):Rapunzel {
this.bb_pos = i;
this.bb = bb;
return this;
}
hairLength():number {
return this.bb!.readInt32(this.bb_pos);
}
mutate_hair_length(value:number):boolean {
this.bb!.writeInt32(this.bb_pos + 0, value);
return true;
}
static getFullyQualifiedName():string {
return 'Rapunzel';
}
static sizeOf():number {
return 4;
}
static createRapunzel(builder:flatbuffers.Builder, hair_length: number):flatbuffers.Offset {
builder.prep(4, 4);
builder.writeInt32(hair_length);
return builder.offset();
}
unpack(): RapunzelT {
return new RapunzelT(
this.hairLength()
);
}
unpackTo(_o: RapunzelT): void {
_o.hairLength = this.hairLength();
}
}
export class RapunzelT {
constructor(
public hairLength: number = 0
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return Rapunzel.createRapunzel(builder,
this.hairLength
);
}
}

View File

@@ -1,8 +0,0 @@
export { Attacker, AttackerT } from './attacker';
export { BookReader, BookReaderT } from './book-reader';
export { Character, unionToCharacter, unionListToCharacter } from './character';
export { FallingTub, FallingTubT } from './falling-tub';
export { Gadget, unionToGadget, unionListToGadget } from './gadget';
export { HandFan, HandFanT } from './hand-fan';
export { Movie, MovieT } from './movie';
export { Rapunzel, RapunzelT } from './rapunzel';

View File

@@ -1,8 +0,0 @@
export { Attacker, AttackerT } from './attacker';
export { BookReader, BookReaderT } from './book-reader';
export { Character, unionToCharacter, unionListToCharacter } from './character';
export { FallingTub, FallingTubT } from './falling-tub';
export { Gadget, unionToGadget, unionListToGadget } from './gadget';
export { HandFan, HandFanT } from './hand-fan';
export { Movie, MovieT } from './movie';
export { Rapunzel, RapunzelT } from './rapunzel';

View File

@@ -1,10 +0,0 @@
// automatically generated by the FlatBuffers compiler, do not modify
export { Attacker, AttackerT } from './attacker';
export { BookReader, BookReaderT } from './book-reader';
export { Character, unionToCharacter, unionListToCharacter } from './character';
export { FallingTub, FallingTubT } from './falling-tub';
export { Gadget, unionToGadget, unionListToGadget } from './gadget';
export { HandFan, HandFanT } from './hand-fan';
export { Movie, MovieT } from './movie';
export { Rapunzel, RapunzelT } from './rapunzel';