mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-25 12:48:38 +00:00
[TS] Add Obj API (#5788)
* added basic code * backup work * got class property to work * backup progress * implementented fmt for creating code * added docs for genFieldUtils * back up work * added base helper js func * added union js code * added unpackTo and base for pack * added pack code * added null check for packing struct list * passes compile test * fixed some spacing of generated functions * added annotations for constructors * added obj api unpack test * tested pack to work * merge branch * separated js and ts test * fixed union signature to include string * fixed generator to support string union * hardcoded fb builder name * refactored struct vector creation * work around createLong * handle default value in constructor * update typescript docs * added notes about import flag * fixed formatting stuffs * undo TypescriptTest change * refactored fmt * updated generated code * remove ignoring union_vector for js * revert changes for .project * revert changes for package.json * don't generate js in ts test * fixed android project file * removed unused js function * removed package-lock.json * adjust createObjList to new signature * changed regex to callback style * fixed package.json * used existing func for generating annotation * changed ternary to !! * added return type for lambda * removed callback style for obj api generator * fixed js file indentation * removed unused header * added tests for string only union * handle string only union and refactor union conv func * updated generated ts files * renamed union conv func * made js test create files like other languages * removed union string only handling * don't allow null in createObjectOffsetList * updated generated ts code * changed the line that triggers Windows build errors * hopefully fix CI error
This commit is contained in:
@@ -19,7 +19,8 @@ export enum Color{
|
||||
* \brief color Blue (1u << 3)
|
||||
*/
|
||||
Blue= 8
|
||||
}};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
@@ -30,7 +31,8 @@ export enum Race{
|
||||
Human= 0,
|
||||
Dwarf= 1,
|
||||
Elf= 2
|
||||
}};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
@@ -41,7 +43,35 @@ export enum Any{
|
||||
Monster= 1,
|
||||
TestSimpleTableWithEnum= 2,
|
||||
MyGame_Example2_Monster= 3
|
||||
}};
|
||||
};
|
||||
|
||||
export function unionToAny(
|
||||
type: Any,
|
||||
accessor: (obj:MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster) => MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster|null
|
||||
): MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster|null {
|
||||
switch(MyGame.Example.Any[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'Monster': return accessor(new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
case 'TestSimpleTableWithEnum': return accessor(new MyGame.Example.TestSimpleTableWithEnum())! as MyGame.Example.TestSimpleTableWithEnum;
|
||||
case 'MyGame_Example2_Monster': return accessor(new MyGame.Example2.Monster())! as MyGame.Example2.Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToAny(
|
||||
type: Any,
|
||||
accessor: (index: number, obj:MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster) => MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster|null,
|
||||
index: number
|
||||
): MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster|null {
|
||||
switch(MyGame.Example.Any[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'Monster': return accessor(index, new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
case 'TestSimpleTableWithEnum': return accessor(index, new MyGame.Example.TestSimpleTableWithEnum())! as MyGame.Example.TestSimpleTableWithEnum;
|
||||
case 'MyGame_Example2_Monster': return accessor(index, new MyGame.Example2.Monster())! as MyGame.Example2.Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
@@ -52,7 +82,35 @@ export enum AnyUniqueAliases{
|
||||
M= 1,
|
||||
TS= 2,
|
||||
M2= 3
|
||||
}};
|
||||
};
|
||||
|
||||
export function unionToAnyUniqueAliases(
|
||||
type: AnyUniqueAliases,
|
||||
accessor: (obj:MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster) => MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster|null
|
||||
): MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster|null {
|
||||
switch(MyGame.Example.AnyUniqueAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M': return accessor(new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
case 'TS': return accessor(new MyGame.Example.TestSimpleTableWithEnum())! as MyGame.Example.TestSimpleTableWithEnum;
|
||||
case 'M2': return accessor(new MyGame.Example2.Monster())! as MyGame.Example2.Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToAnyUniqueAliases(
|
||||
type: AnyUniqueAliases,
|
||||
accessor: (index: number, obj:MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster) => MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster|null,
|
||||
index: number
|
||||
): MyGame.Example.Monster|MyGame.Example.TestSimpleTableWithEnum|MyGame.Example2.Monster|null {
|
||||
switch(MyGame.Example.AnyUniqueAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M': return accessor(index, new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
case 'TS': return accessor(index, new MyGame.Example.TestSimpleTableWithEnum())! as MyGame.Example.TestSimpleTableWithEnum;
|
||||
case 'M2': return accessor(index, new MyGame.Example2.Monster())! as MyGame.Example2.Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
@@ -63,7 +121,35 @@ export enum AnyAmbiguousAliases{
|
||||
M1= 1,
|
||||
M2= 2,
|
||||
M3= 3
|
||||
}};
|
||||
};
|
||||
|
||||
export function unionToAnyAmbiguousAliases(
|
||||
type: AnyAmbiguousAliases,
|
||||
accessor: (obj:MyGame.Example.Monster) => MyGame.Example.Monster|null
|
||||
): MyGame.Example.Monster|null {
|
||||
switch(MyGame.Example.AnyAmbiguousAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M1': return accessor(new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
case 'M2': return accessor(new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
case 'M3': return accessor(new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToAnyAmbiguousAliases(
|
||||
type: AnyAmbiguousAliases,
|
||||
accessor: (index: number, obj:MyGame.Example.Monster) => MyGame.Example.Monster|null,
|
||||
index: number
|
||||
): MyGame.Example.Monster|null {
|
||||
switch(MyGame.Example.AnyAmbiguousAliases[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'M1': return accessor(index, new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
case 'M2': return accessor(index, new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
case 'M3': return accessor(index, new MyGame.Example.Monster())! as MyGame.Example.Monster;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -123,6 +209,33 @@ static createInParentNamespace(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
InParentNamespace.startInParentNamespace(builder);
|
||||
return InParentNamespace.endInParentNamespace(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns InParentNamespaceT
|
||||
*/
|
||||
unpack(): InParentNamespaceT {
|
||||
return new InParentNamespaceT();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param InParentNamespaceT _o
|
||||
*/
|
||||
unpackTo(_o: InParentNamespaceT): void {};
|
||||
}
|
||||
|
||||
export class InParentNamespaceT {
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
constructor(){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return InParentNamespace.createInParentNamespace(builder);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -183,6 +296,33 @@ static createMonster(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
Monster.startMonster(builder);
|
||||
return Monster.endMonster(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns MonsterT
|
||||
*/
|
||||
unpack(): MonsterT {
|
||||
return new MonsterT();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param MonsterT _o
|
||||
*/
|
||||
unpackTo(_o: MonsterT): void {};
|
||||
}
|
||||
|
||||
export class MonsterT {
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
constructor(){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Monster.createMonster(builder);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -262,6 +402,47 @@ static createTest(builder:flatbuffers.Builder, a: number, b: number):flatbuffers
|
||||
return builder.offset();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @returns TestT
|
||||
*/
|
||||
unpack(): TestT {
|
||||
return new TestT(
|
||||
this.a(),
|
||||
this.b()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param TestT _o
|
||||
*/
|
||||
unpackTo(_o: TestT): void {
|
||||
_o.a = this.a();
|
||||
_o.b = this.b();
|
||||
};
|
||||
}
|
||||
|
||||
export class TestT {
|
||||
/**
|
||||
* @constructor
|
||||
* @param number a
|
||||
* @param number b
|
||||
*/
|
||||
constructor(
|
||||
public a: number = 0,
|
||||
public b: number = 0
|
||||
){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Test.createTest(builder,
|
||||
this.a,
|
||||
this.b
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -354,6 +535,42 @@ static createTestSimpleTableWithEnum(builder:flatbuffers.Builder, color:MyGame.E
|
||||
TestSimpleTableWithEnum.addColor(builder, color);
|
||||
return TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns TestSimpleTableWithEnumT
|
||||
*/
|
||||
unpack(): TestSimpleTableWithEnumT {
|
||||
return new TestSimpleTableWithEnumT(
|
||||
this.color()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param TestSimpleTableWithEnumT _o
|
||||
*/
|
||||
unpackTo(_o: TestSimpleTableWithEnumT): void {
|
||||
_o.color = this.color();
|
||||
};
|
||||
}
|
||||
|
||||
export class TestSimpleTableWithEnumT {
|
||||
/**
|
||||
* @constructor
|
||||
* @param MyGame.Example.Color color
|
||||
*/
|
||||
constructor(
|
||||
public color: MyGame.Example.Color = MyGame.Example.Color.Green
|
||||
){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return TestSimpleTableWithEnum.createTestSimpleTableWithEnum(builder,
|
||||
this.color
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -521,6 +738,68 @@ static createVec3(builder:flatbuffers.Builder, x: number, y: number, z: number,
|
||||
return builder.offset();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @returns Vec3T
|
||||
*/
|
||||
unpack(): Vec3T {
|
||||
return new Vec3T(
|
||||
this.x(),
|
||||
this.y(),
|
||||
this.z(),
|
||||
this.test1(),
|
||||
this.test2(),
|
||||
(this.test3() !== null ? this.test3()!.unpack() : null)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param Vec3T _o
|
||||
*/
|
||||
unpackTo(_o: Vec3T): void {
|
||||
_o.x = this.x();
|
||||
_o.y = this.y();
|
||||
_o.z = this.z();
|
||||
_o.test1 = this.test1();
|
||||
_o.test2 = this.test2();
|
||||
_o.test3 = (this.test3() !== null ? this.test3()!.unpack() : null);
|
||||
};
|
||||
}
|
||||
|
||||
export class Vec3T {
|
||||
/**
|
||||
* @constructor
|
||||
* @param number x
|
||||
* @param number y
|
||||
* @param number z
|
||||
* @param number test1
|
||||
* @param MyGame.Example.Color test2
|
||||
* @param MyGame.Example.TestT|null test3
|
||||
*/
|
||||
constructor(
|
||||
public x: number = 0.0,
|
||||
public y: number = 0.0,
|
||||
public z: number = 0.0,
|
||||
public test1: number = 0.0,
|
||||
public test2: MyGame.Example.Color = /** } */ (0),
|
||||
public test3: MyGame.Example.TestT|null = null
|
||||
){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Vec3.createVec3(builder,
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.test1,
|
||||
this.test2,
|
||||
(this.test3 === null ? 0 : this.test3.a!),
|
||||
(this.test3 === null ? 0 : this.test3.b!)
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -599,6 +878,47 @@ static createAbility(builder:flatbuffers.Builder, id: number, distance: number):
|
||||
return builder.offset();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @returns AbilityT
|
||||
*/
|
||||
unpack(): AbilityT {
|
||||
return new AbilityT(
|
||||
this.id(),
|
||||
this.distance()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param AbilityT _o
|
||||
*/
|
||||
unpackTo(_o: AbilityT): void {
|
||||
_o.id = this.id();
|
||||
_o.distance = this.distance();
|
||||
};
|
||||
}
|
||||
|
||||
export class AbilityT {
|
||||
/**
|
||||
* @constructor
|
||||
* @param number id
|
||||
* @param number distance
|
||||
*/
|
||||
constructor(
|
||||
public id: number = 0,
|
||||
public distance: number = 0
|
||||
){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Ability.createAbility(builder,
|
||||
this.id,
|
||||
this.distance
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -743,6 +1063,54 @@ static createStat(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset, val:
|
||||
Stat.addCount(builder, count);
|
||||
return Stat.endStat(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns StatT
|
||||
*/
|
||||
unpack(): StatT {
|
||||
return new StatT(
|
||||
this.id(),
|
||||
this.val(),
|
||||
this.count()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param StatT _o
|
||||
*/
|
||||
unpackTo(_o: StatT): void {
|
||||
_o.id = this.id();
|
||||
_o.val = this.val();
|
||||
_o.count = this.count();
|
||||
};
|
||||
}
|
||||
|
||||
export class StatT {
|
||||
/**
|
||||
* @constructor
|
||||
* @param string|Uint8Array|null id
|
||||
* @param flatbuffers.Long val
|
||||
* @param number count
|
||||
*/
|
||||
constructor(
|
||||
public id: string|Uint8Array|null = null,
|
||||
public val: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public count: number = 0
|
||||
){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const id = (this.id !== null ? builder.createString(this.id!) : 0);
|
||||
|
||||
return Stat.createStat(builder,
|
||||
id,
|
||||
this.val,
|
||||
this.count
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -835,6 +1203,42 @@ static createReferrable(builder:flatbuffers.Builder, id:flatbuffers.Long):flatbu
|
||||
Referrable.addId(builder, id);
|
||||
return Referrable.endReferrable(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns ReferrableT
|
||||
*/
|
||||
unpack(): ReferrableT {
|
||||
return new ReferrableT(
|
||||
this.id()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param ReferrableT _o
|
||||
*/
|
||||
unpackTo(_o: ReferrableT): void {
|
||||
_o.id = this.id();
|
||||
};
|
||||
}
|
||||
|
||||
export class ReferrableT {
|
||||
/**
|
||||
* @constructor
|
||||
* @param flatbuffers.Long id
|
||||
*/
|
||||
constructor(
|
||||
public id: flatbuffers.Long = flatbuffers.createLong(0, 0)
|
||||
){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return Referrable.createReferrable(builder,
|
||||
this.id
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -2597,6 +3001,324 @@ static createMonster(builder:flatbuffers.Builder, posOffset:flatbuffers.Offset,
|
||||
Monster.addSignedEnum(builder, signedEnum);
|
||||
return Monster.endMonster(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns MonsterT
|
||||
*/
|
||||
unpack(): MonsterT {
|
||||
return new MonsterT(
|
||||
(this.pos() !== null ? this.pos()!.unpack() : null),
|
||||
this.mana(),
|
||||
this.hp(),
|
||||
this.name(),
|
||||
this.bb!.createScalarList(this.inventory.bind(this), this.inventoryLength()),
|
||||
this.color(),
|
||||
this.testType(),
|
||||
(() => {
|
||||
let temp = MyGame.Example.unionToAny(this.testType(), this.test.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
return temp.unpack()
|
||||
})(),
|
||||
this.bb!.createObjList(this.test4.bind(this), this.test4Length()),
|
||||
this.bb!.createStringList(this.testarrayofstring.bind(this), this.testarrayofstringLength()),
|
||||
this.bb!.createObjList(this.testarrayoftables.bind(this), this.testarrayoftablesLength()),
|
||||
(this.enemy() !== null ? this.enemy()!.unpack() : null),
|
||||
this.bb!.createScalarList(this.testnestedflatbuffer.bind(this), this.testnestedflatbufferLength()),
|
||||
(this.testempty() !== null ? this.testempty()!.unpack() : null),
|
||||
this.testbool(),
|
||||
this.testhashs32Fnv1(),
|
||||
this.testhashu32Fnv1(),
|
||||
this.testhashs64Fnv1(),
|
||||
this.testhashu64Fnv1(),
|
||||
this.testhashs32Fnv1a(),
|
||||
this.testhashu32Fnv1a(),
|
||||
this.testhashs64Fnv1a(),
|
||||
this.testhashu64Fnv1a(),
|
||||
this.bb!.createScalarList(this.testarrayofbools.bind(this), this.testarrayofboolsLength()),
|
||||
this.testf(),
|
||||
this.testf2(),
|
||||
this.testf3(),
|
||||
this.bb!.createStringList(this.testarrayofstring2.bind(this), this.testarrayofstring2Length()),
|
||||
this.bb!.createObjList(this.testarrayofsortedstruct.bind(this), this.testarrayofsortedstructLength()),
|
||||
this.bb!.createScalarList(this.flex.bind(this), this.flexLength()),
|
||||
this.bb!.createObjList(this.test5.bind(this), this.test5Length()),
|
||||
this.bb!.createScalarList(this.vectorOfLongs.bind(this), this.vectorOfLongsLength()),
|
||||
this.bb!.createScalarList(this.vectorOfDoubles.bind(this), this.vectorOfDoublesLength()),
|
||||
(this.parentNamespaceTest() !== null ? this.parentNamespaceTest()!.unpack() : null),
|
||||
this.bb!.createObjList(this.vectorOfReferrables.bind(this), this.vectorOfReferrablesLength()),
|
||||
this.singleWeakReference(),
|
||||
this.bb!.createScalarList(this.vectorOfWeakReferences.bind(this), this.vectorOfWeakReferencesLength()),
|
||||
this.bb!.createObjList(this.vectorOfStrongReferrables.bind(this), this.vectorOfStrongReferrablesLength()),
|
||||
this.coOwningReference(),
|
||||
this.bb!.createScalarList(this.vectorOfCoOwningReferences.bind(this), this.vectorOfCoOwningReferencesLength()),
|
||||
this.nonOwningReference(),
|
||||
this.bb!.createScalarList(this.vectorOfNonOwningReferences.bind(this), this.vectorOfNonOwningReferencesLength()),
|
||||
this.anyUniqueType(),
|
||||
(() => {
|
||||
let temp = MyGame.Example.unionToAnyUniqueAliases(this.anyUniqueType(), this.anyUnique.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
return temp.unpack()
|
||||
})(),
|
||||
this.anyAmbiguousType(),
|
||||
(() => {
|
||||
let temp = MyGame.Example.unionToAnyAmbiguousAliases(this.anyAmbiguousType(), this.anyAmbiguous.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
return temp.unpack()
|
||||
})(),
|
||||
this.bb!.createScalarList(this.vectorOfEnums.bind(this), this.vectorOfEnumsLength()),
|
||||
this.signedEnum()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param MonsterT _o
|
||||
*/
|
||||
unpackTo(_o: MonsterT): void {
|
||||
_o.pos = (this.pos() !== null ? this.pos()!.unpack() : null);
|
||||
_o.mana = this.mana();
|
||||
_o.hp = this.hp();
|
||||
_o.name = this.name();
|
||||
_o.inventory = this.bb!.createScalarList(this.inventory.bind(this), this.inventoryLength());
|
||||
_o.color = this.color();
|
||||
_o.testType = this.testType();
|
||||
_o.test = (() => {
|
||||
let temp = MyGame.Example.unionToAny(this.testType(), this.test.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
return temp.unpack()
|
||||
})();
|
||||
_o.test4 = this.bb!.createObjList(this.test4.bind(this), this.test4Length());
|
||||
_o.testarrayofstring = this.bb!.createStringList(this.testarrayofstring.bind(this), this.testarrayofstringLength());
|
||||
_o.testarrayoftables = this.bb!.createObjList(this.testarrayoftables.bind(this), this.testarrayoftablesLength());
|
||||
_o.enemy = (this.enemy() !== null ? this.enemy()!.unpack() : null);
|
||||
_o.testnestedflatbuffer = this.bb!.createScalarList(this.testnestedflatbuffer.bind(this), this.testnestedflatbufferLength());
|
||||
_o.testempty = (this.testempty() !== null ? this.testempty()!.unpack() : null);
|
||||
_o.testbool = this.testbool();
|
||||
_o.testhashs32Fnv1 = this.testhashs32Fnv1();
|
||||
_o.testhashu32Fnv1 = this.testhashu32Fnv1();
|
||||
_o.testhashs64Fnv1 = this.testhashs64Fnv1();
|
||||
_o.testhashu64Fnv1 = this.testhashu64Fnv1();
|
||||
_o.testhashs32Fnv1a = this.testhashs32Fnv1a();
|
||||
_o.testhashu32Fnv1a = this.testhashu32Fnv1a();
|
||||
_o.testhashs64Fnv1a = this.testhashs64Fnv1a();
|
||||
_o.testhashu64Fnv1a = this.testhashu64Fnv1a();
|
||||
_o.testarrayofbools = this.bb!.createScalarList(this.testarrayofbools.bind(this), this.testarrayofboolsLength());
|
||||
_o.testf = this.testf();
|
||||
_o.testf2 = this.testf2();
|
||||
_o.testf3 = this.testf3();
|
||||
_o.testarrayofstring2 = this.bb!.createStringList(this.testarrayofstring2.bind(this), this.testarrayofstring2Length());
|
||||
_o.testarrayofsortedstruct = this.bb!.createObjList(this.testarrayofsortedstruct.bind(this), this.testarrayofsortedstructLength());
|
||||
_o.flex = this.bb!.createScalarList(this.flex.bind(this), this.flexLength());
|
||||
_o.test5 = this.bb!.createObjList(this.test5.bind(this), this.test5Length());
|
||||
_o.vectorOfLongs = this.bb!.createScalarList(this.vectorOfLongs.bind(this), this.vectorOfLongsLength());
|
||||
_o.vectorOfDoubles = this.bb!.createScalarList(this.vectorOfDoubles.bind(this), this.vectorOfDoublesLength());
|
||||
_o.parentNamespaceTest = (this.parentNamespaceTest() !== null ? this.parentNamespaceTest()!.unpack() : null);
|
||||
_o.vectorOfReferrables = this.bb!.createObjList(this.vectorOfReferrables.bind(this), this.vectorOfReferrablesLength());
|
||||
_o.singleWeakReference = this.singleWeakReference();
|
||||
_o.vectorOfWeakReferences = this.bb!.createScalarList(this.vectorOfWeakReferences.bind(this), this.vectorOfWeakReferencesLength());
|
||||
_o.vectorOfStrongReferrables = this.bb!.createObjList(this.vectorOfStrongReferrables.bind(this), this.vectorOfStrongReferrablesLength());
|
||||
_o.coOwningReference = this.coOwningReference();
|
||||
_o.vectorOfCoOwningReferences = this.bb!.createScalarList(this.vectorOfCoOwningReferences.bind(this), this.vectorOfCoOwningReferencesLength());
|
||||
_o.nonOwningReference = this.nonOwningReference();
|
||||
_o.vectorOfNonOwningReferences = this.bb!.createScalarList(this.vectorOfNonOwningReferences.bind(this), this.vectorOfNonOwningReferencesLength());
|
||||
_o.anyUniqueType = this.anyUniqueType();
|
||||
_o.anyUnique = (() => {
|
||||
let temp = MyGame.Example.unionToAnyUniqueAliases(this.anyUniqueType(), this.anyUnique.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
return temp.unpack()
|
||||
})();
|
||||
_o.anyAmbiguousType = this.anyAmbiguousType();
|
||||
_o.anyAmbiguous = (() => {
|
||||
let temp = MyGame.Example.unionToAnyAmbiguousAliases(this.anyAmbiguousType(), this.anyAmbiguous.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
return temp.unpack()
|
||||
})();
|
||||
_o.vectorOfEnums = this.bb!.createScalarList(this.vectorOfEnums.bind(this), this.vectorOfEnumsLength());
|
||||
_o.signedEnum = this.signedEnum();
|
||||
};
|
||||
}
|
||||
|
||||
export class MonsterT {
|
||||
/**
|
||||
* @constructor
|
||||
* @param MyGame.Example.Vec3T|null pos
|
||||
* @param number mana
|
||||
* @param number hp
|
||||
* @param string|Uint8Array|null name
|
||||
* @param (number)[] inventory
|
||||
* @param MyGame.Example.Color color
|
||||
* @param MyGame.Example.Any testType
|
||||
* @param MyGame.Example.MonsterT|MyGame.Example.TestSimpleTableWithEnumT|MyGame.Example2.MonsterT|null test
|
||||
* @param (MyGame.Example.TestT)[] test4
|
||||
* @param (string)[] testarrayofstring
|
||||
* @param (MyGame.Example.MonsterT)[] testarrayoftables
|
||||
* @param MyGame.Example.MonsterT|null enemy
|
||||
* @param (number)[] testnestedflatbuffer
|
||||
* @param MyGame.Example.StatT|null testempty
|
||||
* @param boolean testbool
|
||||
* @param number testhashs32Fnv1
|
||||
* @param number testhashu32Fnv1
|
||||
* @param flatbuffers.Long testhashs64Fnv1
|
||||
* @param flatbuffers.Long testhashu64Fnv1
|
||||
* @param number testhashs32Fnv1a
|
||||
* @param number testhashu32Fnv1a
|
||||
* @param flatbuffers.Long testhashs64Fnv1a
|
||||
* @param flatbuffers.Long testhashu64Fnv1a
|
||||
* @param (boolean)[] testarrayofbools
|
||||
* @param number testf
|
||||
* @param number testf2
|
||||
* @param number testf3
|
||||
* @param (string)[] testarrayofstring2
|
||||
* @param (MyGame.Example.AbilityT)[] testarrayofsortedstruct
|
||||
* @param (number)[] flex
|
||||
* @param (MyGame.Example.TestT)[] test5
|
||||
* @param (flatbuffers.Long)[] vectorOfLongs
|
||||
* @param (number)[] vectorOfDoubles
|
||||
* @param MyGame.InParentNamespaceT|null parentNamespaceTest
|
||||
* @param (MyGame.Example.ReferrableT)[] vectorOfReferrables
|
||||
* @param flatbuffers.Long singleWeakReference
|
||||
* @param (flatbuffers.Long)[] vectorOfWeakReferences
|
||||
* @param (MyGame.Example.ReferrableT)[] vectorOfStrongReferrables
|
||||
* @param flatbuffers.Long coOwningReference
|
||||
* @param (flatbuffers.Long)[] vectorOfCoOwningReferences
|
||||
* @param flatbuffers.Long nonOwningReference
|
||||
* @param (flatbuffers.Long)[] vectorOfNonOwningReferences
|
||||
* @param MyGame.Example.AnyUniqueAliases anyUniqueType
|
||||
* @param MyGame.Example.MonsterT|MyGame.Example.TestSimpleTableWithEnumT|MyGame.Example2.MonsterT|null anyUnique
|
||||
* @param MyGame.Example.AnyAmbiguousAliases anyAmbiguousType
|
||||
* @param MyGame.Example.MonsterT|null anyAmbiguous
|
||||
* @param (MyGame.Example.Color)[] vectorOfEnums
|
||||
* @param MyGame.Example.Race signedEnum
|
||||
*/
|
||||
constructor(
|
||||
public pos: MyGame.Example.Vec3T|null = null,
|
||||
public mana: number = 150,
|
||||
public hp: number = 100,
|
||||
public name: string|Uint8Array|null = null,
|
||||
public inventory: (number)[] = [],
|
||||
public color: MyGame.Example.Color = MyGame.Example.Color.Blue,
|
||||
public testType: MyGame.Example.Any = MyGame.Example.Any.NONE,
|
||||
public test: MyGame.Example.MonsterT|MyGame.Example.TestSimpleTableWithEnumT|MyGame.Example2.MonsterT|null = null,
|
||||
public test4: (MyGame.Example.TestT)[] = [],
|
||||
public testarrayofstring: (string)[] = [],
|
||||
public testarrayoftables: (MyGame.Example.MonsterT)[] = [],
|
||||
public enemy: MyGame.Example.MonsterT|null = null,
|
||||
public testnestedflatbuffer: (number)[] = [],
|
||||
public testempty: MyGame.Example.StatT|null = null,
|
||||
public testbool: boolean = false,
|
||||
public testhashs32Fnv1: number = 0,
|
||||
public testhashu32Fnv1: number = 0,
|
||||
public testhashs64Fnv1: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public testhashu64Fnv1: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public testhashs32Fnv1a: number = 0,
|
||||
public testhashu32Fnv1a: number = 0,
|
||||
public testhashs64Fnv1a: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public testhashu64Fnv1a: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public testarrayofbools: (boolean)[] = [],
|
||||
public testf: number = 3.14159,
|
||||
public testf2: number = 3.0,
|
||||
public testf3: number = 0.0,
|
||||
public testarrayofstring2: (string)[] = [],
|
||||
public testarrayofsortedstruct: (MyGame.Example.AbilityT)[] = [],
|
||||
public flex: (number)[] = [],
|
||||
public test5: (MyGame.Example.TestT)[] = [],
|
||||
public vectorOfLongs: (flatbuffers.Long)[] = [],
|
||||
public vectorOfDoubles: (number)[] = [],
|
||||
public parentNamespaceTest: MyGame.InParentNamespaceT|null = null,
|
||||
public vectorOfReferrables: (MyGame.Example.ReferrableT)[] = [],
|
||||
public singleWeakReference: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public vectorOfWeakReferences: (flatbuffers.Long)[] = [],
|
||||
public vectorOfStrongReferrables: (MyGame.Example.ReferrableT)[] = [],
|
||||
public coOwningReference: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public vectorOfCoOwningReferences: (flatbuffers.Long)[] = [],
|
||||
public nonOwningReference: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public vectorOfNonOwningReferences: (flatbuffers.Long)[] = [],
|
||||
public anyUniqueType: MyGame.Example.AnyUniqueAliases = MyGame.Example.AnyUniqueAliases.NONE,
|
||||
public anyUnique: MyGame.Example.MonsterT|MyGame.Example.TestSimpleTableWithEnumT|MyGame.Example2.MonsterT|null = null,
|
||||
public anyAmbiguousType: MyGame.Example.AnyAmbiguousAliases = MyGame.Example.AnyAmbiguousAliases.NONE,
|
||||
public anyAmbiguous: MyGame.Example.MonsterT|null = null,
|
||||
public vectorOfEnums: (MyGame.Example.Color)[] = [],
|
||||
public signedEnum: MyGame.Example.Race = MyGame.Example.Race.None
|
||||
){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const name = (this.name !== null ? builder.createString(this.name!) : 0);
|
||||
const inventory = Monster.createInventoryVector(builder, this.inventory);
|
||||
const test = builder.createObjectOffset(this.test);
|
||||
const test4 = builder.createStructOffsetList(this.test4, Monster.startTest4Vector);
|
||||
const testarrayofstring = Monster.createTestarrayofstringVector(builder, builder.createObjectOffsetList(this.testarrayofstring));
|
||||
const testarrayoftables = Monster.createTestarrayoftablesVector(builder, builder.createObjectOffsetList(this.testarrayoftables));
|
||||
const testnestedflatbuffer = Monster.createTestnestedflatbufferVector(builder, this.testnestedflatbuffer);
|
||||
const testarrayofbools = Monster.createTestarrayofboolsVector(builder, this.testarrayofbools);
|
||||
const testarrayofstring2 = Monster.createTestarrayofstring2Vector(builder, builder.createObjectOffsetList(this.testarrayofstring2));
|
||||
const testarrayofsortedstruct = builder.createStructOffsetList(this.testarrayofsortedstruct, Monster.startTestarrayofsortedstructVector);
|
||||
const flex = Monster.createFlexVector(builder, this.flex);
|
||||
const test5 = builder.createStructOffsetList(this.test5, Monster.startTest5Vector);
|
||||
const vectorOfLongs = Monster.createVectorOfLongsVector(builder, this.vectorOfLongs);
|
||||
const vectorOfDoubles = Monster.createVectorOfDoublesVector(builder, this.vectorOfDoubles);
|
||||
const vectorOfReferrables = Monster.createVectorOfReferrablesVector(builder, builder.createObjectOffsetList(this.vectorOfReferrables));
|
||||
const vectorOfWeakReferences = Monster.createVectorOfWeakReferencesVector(builder, this.vectorOfWeakReferences);
|
||||
const vectorOfStrongReferrables = Monster.createVectorOfStrongReferrablesVector(builder, builder.createObjectOffsetList(this.vectorOfStrongReferrables));
|
||||
const vectorOfCoOwningReferences = Monster.createVectorOfCoOwningReferencesVector(builder, this.vectorOfCoOwningReferences);
|
||||
const vectorOfNonOwningReferences = Monster.createVectorOfNonOwningReferencesVector(builder, this.vectorOfNonOwningReferences);
|
||||
const anyUnique = builder.createObjectOffset(this.anyUnique);
|
||||
const anyAmbiguous = builder.createObjectOffset(this.anyAmbiguous);
|
||||
const vectorOfEnums = Monster.createVectorOfEnumsVector(builder, this.vectorOfEnums);
|
||||
|
||||
return Monster.createMonster(builder,
|
||||
(this.pos !== null ? this.pos!.pack(builder) : 0),
|
||||
this.mana,
|
||||
this.hp,
|
||||
name,
|
||||
inventory,
|
||||
this.color,
|
||||
this.testType,
|
||||
test,
|
||||
test4,
|
||||
testarrayofstring,
|
||||
testarrayoftables,
|
||||
(this.enemy !== null ? this.enemy!.pack(builder) : 0),
|
||||
testnestedflatbuffer,
|
||||
(this.testempty !== null ? this.testempty!.pack(builder) : 0),
|
||||
this.testbool,
|
||||
this.testhashs32Fnv1,
|
||||
this.testhashu32Fnv1,
|
||||
this.testhashs64Fnv1,
|
||||
this.testhashu64Fnv1,
|
||||
this.testhashs32Fnv1a,
|
||||
this.testhashu32Fnv1a,
|
||||
this.testhashs64Fnv1a,
|
||||
this.testhashu64Fnv1a,
|
||||
testarrayofbools,
|
||||
this.testf,
|
||||
this.testf2,
|
||||
this.testf3,
|
||||
testarrayofstring2,
|
||||
testarrayofsortedstruct,
|
||||
flex,
|
||||
test5,
|
||||
vectorOfLongs,
|
||||
vectorOfDoubles,
|
||||
(this.parentNamespaceTest !== null ? this.parentNamespaceTest!.pack(builder) : 0),
|
||||
vectorOfReferrables,
|
||||
this.singleWeakReference,
|
||||
vectorOfWeakReferences,
|
||||
vectorOfStrongReferrables,
|
||||
this.coOwningReference,
|
||||
vectorOfCoOwningReferences,
|
||||
this.nonOwningReference,
|
||||
vectorOfNonOwningReferences,
|
||||
this.anyUniqueType,
|
||||
anyUnique,
|
||||
this.anyAmbiguousType,
|
||||
anyAmbiguous,
|
||||
vectorOfEnums,
|
||||
this.signedEnum
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -3087,5 +3809,99 @@ static createTypeAliases(builder:flatbuffers.Builder, i8:number, u8:number, i16:
|
||||
TypeAliases.addVf64(builder, vf64Offset);
|
||||
return TypeAliases.endTypeAliases(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns TypeAliasesT
|
||||
*/
|
||||
unpack(): TypeAliasesT {
|
||||
return new TypeAliasesT(
|
||||
this.i8(),
|
||||
this.u8(),
|
||||
this.i16(),
|
||||
this.u16(),
|
||||
this.i32(),
|
||||
this.u32(),
|
||||
this.i64(),
|
||||
this.u64(),
|
||||
this.f32(),
|
||||
this.f64(),
|
||||
this.bb!.createScalarList(this.v8.bind(this), this.v8Length()),
|
||||
this.bb!.createScalarList(this.vf64.bind(this), this.vf64Length())
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param TypeAliasesT _o
|
||||
*/
|
||||
unpackTo(_o: TypeAliasesT): void {
|
||||
_o.i8 = this.i8();
|
||||
_o.u8 = this.u8();
|
||||
_o.i16 = this.i16();
|
||||
_o.u16 = this.u16();
|
||||
_o.i32 = this.i32();
|
||||
_o.u32 = this.u32();
|
||||
_o.i64 = this.i64();
|
||||
_o.u64 = this.u64();
|
||||
_o.f32 = this.f32();
|
||||
_o.f64 = this.f64();
|
||||
_o.v8 = this.bb!.createScalarList(this.v8.bind(this), this.v8Length());
|
||||
_o.vf64 = this.bb!.createScalarList(this.vf64.bind(this), this.vf64Length());
|
||||
};
|
||||
}
|
||||
|
||||
export class TypeAliasesT {
|
||||
/**
|
||||
* @constructor
|
||||
* @param number i8
|
||||
* @param number u8
|
||||
* @param number i16
|
||||
* @param number u16
|
||||
* @param number i32
|
||||
* @param number u32
|
||||
* @param flatbuffers.Long i64
|
||||
* @param flatbuffers.Long u64
|
||||
* @param number f32
|
||||
* @param number f64
|
||||
* @param (number)[] v8
|
||||
* @param (number)[] vf64
|
||||
*/
|
||||
constructor(
|
||||
public i8: number = 0,
|
||||
public u8: number = 0,
|
||||
public i16: number = 0,
|
||||
public u16: number = 0,
|
||||
public i32: number = 0,
|
||||
public u32: number = 0,
|
||||
public i64: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public u64: flatbuffers.Long = flatbuffers.createLong(0, 0),
|
||||
public f32: number = 0.0,
|
||||
public f64: number = 0.0,
|
||||
public v8: (number)[] = [],
|
||||
public vf64: (number)[] = []
|
||||
){};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
*/
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const v8 = TypeAliases.createV8Vector(builder, this.v8);
|
||||
const vf64 = TypeAliases.createVf64Vector(builder, this.vf64);
|
||||
|
||||
return TypeAliases.createTypeAliases(builder,
|
||||
this.i8,
|
||||
this.u8,
|
||||
this.i16,
|
||||
this.u16,
|
||||
this.i32,
|
||||
this.u32,
|
||||
this.i64,
|
||||
this.u64,
|
||||
this.f32,
|
||||
this.f64,
|
||||
v8,
|
||||
vf64
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user