mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 22:22:18 +00:00
fixed invalid TS call and added test files (#6495)
e581013e3d broke TS generation - please don't use "replace" to refactor function names :)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum EnumInNestedNS{
|
||||
A = 0,
|
||||
B = 1,
|
||||
C = 2
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class StructInNestedNS {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):StructInNestedNS {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
a():number {
|
||||
return this.bb!.readInt32(this.bb_pos);
|
||||
}
|
||||
|
||||
mutate_a(value:number):boolean {
|
||||
this.bb!.writeInt32(this.bb_pos + 0, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
b():number {
|
||||
return this.bb!.readInt32(this.bb_pos + 4);
|
||||
}
|
||||
|
||||
mutate_b(value:number):boolean {
|
||||
this.bb!.writeInt32(this.bb_pos + 4, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'NamespaceA.NamespaceB.StructInNestedNS';
|
||||
}
|
||||
|
||||
static sizeOf():number {
|
||||
return 8;
|
||||
}
|
||||
|
||||
static createStructInNestedNS(builder:flatbuffers.Builder, a: number, b: number):flatbuffers.Offset {
|
||||
builder.prep(4, 8);
|
||||
builder.writeInt32(b);
|
||||
builder.writeInt32(a);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
|
||||
unpack(): StructInNestedNST {
|
||||
return new StructInNestedNST(
|
||||
this.a(),
|
||||
this.b()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: StructInNestedNST): void {
|
||||
_o.a = this.a();
|
||||
_o.b = this.b();
|
||||
}
|
||||
}
|
||||
|
||||
export class StructInNestedNST {
|
||||
constructor(
|
||||
public a: number = 0,
|
||||
public b: number = 0
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return StructInNestedNS.createStructInNestedNS(builder,
|
||||
this.a,
|
||||
this.b
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class TableInNestedNS {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):TableInNestedNS {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsTableInNestedNS(bb:flatbuffers.ByteBuffer, obj?:TableInNestedNS):TableInNestedNS {
|
||||
return (obj || new TableInNestedNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsTableInNestedNS(bb:flatbuffers.ByteBuffer, obj?:TableInNestedNS):TableInNestedNS {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new TableInNestedNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
foo():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
mutate_foo(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 'NamespaceA.NamespaceB.TableInNestedNS';
|
||||
}
|
||||
|
||||
static startTableInNestedNS(builder:flatbuffers.Builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
|
||||
static addFoo(builder:flatbuffers.Builder, foo:number) {
|
||||
builder.addFieldInt32(0, foo, 0);
|
||||
}
|
||||
|
||||
static endTableInNestedNS(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createTableInNestedNS(builder:flatbuffers.Builder, foo:number):flatbuffers.Offset {
|
||||
TableInNestedNS.startTableInNestedNS(builder);
|
||||
TableInNestedNS.addFoo(builder, foo);
|
||||
return TableInNestedNS.endTableInNestedNS(builder);
|
||||
}
|
||||
|
||||
unpack(): TableInNestedNST {
|
||||
return new TableInNestedNST(
|
||||
this.foo()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: TableInNestedNST): void {
|
||||
_o.foo = this.foo();
|
||||
}
|
||||
}
|
||||
|
||||
export class TableInNestedNST {
|
||||
constructor(
|
||||
public foo: number = 0
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return TableInNestedNS.createTableInNestedNS(builder,
|
||||
this.foo
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import { TableInNestedNS, TableInNestedNST } from '../../namespace-a/namespace-b/table-in-nested-n-s';
|
||||
|
||||
|
||||
export enum UnionInNestedNS{
|
||||
NONE = 0,
|
||||
TableInNestedNS = 1
|
||||
}
|
||||
|
||||
export function unionToUnionInNestedNS(
|
||||
type: UnionInNestedNS,
|
||||
accessor: (obj:TableInNestedNS) => TableInNestedNS|null
|
||||
): TableInNestedNS|null {
|
||||
switch(UnionInNestedNS[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'TableInNestedNS': return accessor(new TableInNestedNS())! as TableInNestedNS;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToUnionInNestedNS(
|
||||
type: UnionInNestedNS,
|
||||
accessor: (index: number, obj:TableInNestedNS) => TableInNestedNS|null,
|
||||
index: number
|
||||
): TableInNestedNS|null {
|
||||
switch(UnionInNestedNS[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'TableInNestedNS': return accessor(index, new TableInNestedNS())! as TableInNestedNS;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
77
tests/namespace_test/namespace-a/second-table-in-a.ts
Normal file
77
tests/namespace_test/namespace-a/second-table-in-a.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { TableInC, TableInCT } from '../namespace-c/table-in-c';
|
||||
|
||||
|
||||
export class SecondTableInA {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):SecondTableInA {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsSecondTableInA(bb:flatbuffers.ByteBuffer, obj?:SecondTableInA):SecondTableInA {
|
||||
return (obj || new SecondTableInA()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsSecondTableInA(bb:flatbuffers.ByteBuffer, obj?:SecondTableInA):SecondTableInA {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new SecondTableInA()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
referToC(obj?:TableInC):TableInC|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? (obj || new TableInC()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'NamespaceA.SecondTableInA';
|
||||
}
|
||||
|
||||
static startSecondTableInA(builder:flatbuffers.Builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
|
||||
static addReferToC(builder:flatbuffers.Builder, referToCOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, referToCOffset, 0);
|
||||
}
|
||||
|
||||
static endSecondTableInA(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createSecondTableInA(builder:flatbuffers.Builder, referToCOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
SecondTableInA.startSecondTableInA(builder);
|
||||
SecondTableInA.addReferToC(builder, referToCOffset);
|
||||
return SecondTableInA.endSecondTableInA(builder);
|
||||
}
|
||||
|
||||
unpack(): SecondTableInAT {
|
||||
return new SecondTableInAT(
|
||||
(this.referToC() !== null ? this.referToC()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: SecondTableInAT): void {
|
||||
_o.referToC = (this.referToC() !== null ? this.referToC()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class SecondTableInAT {
|
||||
constructor(
|
||||
public referToC: TableInCT|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return SecondTableInA.createSecondTableInA(builder,
|
||||
(this.referToC !== null ? this.referToC!.pack(builder) : 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
149
tests/namespace_test/namespace-a/table-in-first-n-s.ts
Normal file
149
tests/namespace_test/namespace-a/table-in-first-n-s.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { EnumInNestedNS } from '../namespace-a/namespace-b/enum-in-nested-n-s';
|
||||
import { StructInNestedNS, StructInNestedNST } from '../namespace-a/namespace-b/struct-in-nested-n-s';
|
||||
import { TableInNestedNS, TableInNestedNST } from '../namespace-a/namespace-b/table-in-nested-n-s';
|
||||
import { UnionInNestedNS, unionToUnionInNestedNS, unionListToUnionInNestedNS } from '../namespace-a/namespace-b/union-in-nested-n-s';
|
||||
|
||||
|
||||
export class TableInFirstNS {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):TableInFirstNS {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):TableInFirstNS {
|
||||
return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):TableInFirstNS {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
fooTable(obj?:NS8755221360535654258.TableInNestedNS):NS8755221360535654258.TableInNestedNS|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? (obj || new NS8755221360535654258.TableInNestedNS()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
fooEnum():EnumInNestedNS {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : EnumInNestedNS.A;
|
||||
}
|
||||
|
||||
mutate_foo_enum(value:EnumInNestedNS):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
fooUnionType():UnionInNestedNS {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb!.readUint8(this.bb_pos + offset) : UnionInNestedNS.NONE;
|
||||
}
|
||||
|
||||
fooUnion<T extends flatbuffers.Table>(obj:any):any|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
fooStruct(obj?:NS8755221360535654258.StructInNestedNS):NS8755221360535654258.StructInNestedNS|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 12);
|
||||
return offset ? (obj || new NS8755221360535654258.StructInNestedNS()).__init(this.bb_pos + offset, this.bb!) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'NamespaceA.TableInFirstNS';
|
||||
}
|
||||
|
||||
static startTableInFirstNS(builder:flatbuffers.Builder) {
|
||||
builder.startObject(5);
|
||||
}
|
||||
|
||||
static addFooTable(builder:flatbuffers.Builder, fooTableOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, fooTableOffset, 0);
|
||||
}
|
||||
|
||||
static addFooEnum(builder:flatbuffers.Builder, fooEnum:EnumInNestedNS) {
|
||||
builder.addFieldInt8(1, fooEnum, EnumInNestedNS.A);
|
||||
}
|
||||
|
||||
static addFooUnionType(builder:flatbuffers.Builder, fooUnionType:UnionInNestedNS) {
|
||||
builder.addFieldInt8(2, fooUnionType, UnionInNestedNS.NONE);
|
||||
}
|
||||
|
||||
static addFooUnion(builder:flatbuffers.Builder, fooUnionOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(3, fooUnionOffset, 0);
|
||||
}
|
||||
|
||||
static addFooStruct(builder:flatbuffers.Builder, fooStructOffset:flatbuffers.Offset) {
|
||||
builder.addFieldStruct(4, fooStructOffset, 0);
|
||||
}
|
||||
|
||||
static endTableInFirstNS(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): TableInFirstNST {
|
||||
return new TableInFirstNST(
|
||||
(this.fooTable() !== null ? this.fooTable()!.unpack() : null),
|
||||
this.fooEnum(),
|
||||
this.fooUnionType(),
|
||||
(() => {
|
||||
let temp = unionToUnionInNestedNS(this.fooUnionType(), this.fooUnion.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
return temp.unpack()
|
||||
})(),
|
||||
(this.fooStruct() !== null ? this.fooStruct()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: TableInFirstNST): void {
|
||||
_o.fooTable = (this.fooTable() !== null ? this.fooTable()!.unpack() : null);
|
||||
_o.fooEnum = this.fooEnum();
|
||||
_o.fooUnionType = this.fooUnionType();
|
||||
_o.fooUnion = (() => {
|
||||
let temp = unionToUnionInNestedNS(this.fooUnionType(), this.fooUnion.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
return temp.unpack()
|
||||
})();
|
||||
_o.fooStruct = (this.fooStruct() !== null ? this.fooStruct()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class TableInFirstNST {
|
||||
constructor(
|
||||
public fooTable: TableInNestedNST|null = null,
|
||||
public fooEnum: EnumInNestedNS = EnumInNestedNS.A,
|
||||
public fooUnionType: UnionInNestedNS = UnionInNestedNS.NONE,
|
||||
public fooUnion: TableInNestedNST|null = null,
|
||||
public fooStruct: StructInNestedNST|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const fooUnion = builder.createObjectOffset(this.fooUnion);
|
||||
|
||||
TableInFirstNS.startTableInFirstNS(builder);
|
||||
TableInFirstNS.addFooTable(builder, (this.fooTable !== null ? this.fooTable!.pack(builder) : 0));
|
||||
TableInFirstNS.addFooEnum(builder, this.fooEnum);
|
||||
TableInFirstNS.addFooUnionType(builder, this.fooUnionType);
|
||||
TableInFirstNS.addFooUnion(builder, fooUnion);
|
||||
TableInFirstNS.addFooStruct(builder, (this.fooStruct !== null ? this.fooStruct!.pack(builder) : 0));
|
||||
|
||||
return TableInFirstNS.endTableInFirstNS(builder);
|
||||
}
|
||||
}
|
||||
87
tests/namespace_test/namespace-c/table-in-c.ts
Normal file
87
tests/namespace_test/namespace-c/table-in-c.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { SecondTableInA, SecondTableInAT } from '../namespace-a/second-table-in-a';
|
||||
import { TableInFirstNS, TableInFirstNST } from '../namespace-a/table-in-first-n-s';
|
||||
|
||||
|
||||
export class TableInC {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):TableInC {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsTableInC(bb:flatbuffers.ByteBuffer, obj?:TableInC):TableInC {
|
||||
return (obj || new TableInC()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsTableInC(bb:flatbuffers.ByteBuffer, obj?:TableInC):TableInC {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new TableInC()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
referToA1(obj?:TableInFirstNS):TableInFirstNS|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? (obj || new TableInFirstNS()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
referToA2(obj?:SecondTableInA):SecondTableInA|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new SecondTableInA()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'NamespaceC.TableInC';
|
||||
}
|
||||
|
||||
static startTableInC(builder:flatbuffers.Builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
|
||||
static addReferToA1(builder:flatbuffers.Builder, referToA1Offset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(0, referToA1Offset, 0);
|
||||
}
|
||||
|
||||
static addReferToA2(builder:flatbuffers.Builder, referToA2Offset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, referToA2Offset, 0);
|
||||
}
|
||||
|
||||
static endTableInC(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
unpack(): TableInCT {
|
||||
return new TableInCT(
|
||||
(this.referToA1() !== null ? this.referToA1()!.unpack() : null),
|
||||
(this.referToA2() !== null ? this.referToA2()!.unpack() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: TableInCT): void {
|
||||
_o.referToA1 = (this.referToA1() !== null ? this.referToA1()!.unpack() : null);
|
||||
_o.referToA2 = (this.referToA2() !== null ? this.referToA2()!.unpack() : null);
|
||||
}
|
||||
}
|
||||
|
||||
export class TableInCT {
|
||||
constructor(
|
||||
public referToA1: TableInFirstNST|null = null,
|
||||
public referToA2: SecondTableInAT|null = null
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
TableInC.startTableInC(builder);
|
||||
TableInC.addReferToA1(builder, (this.referToA1 !== null ? this.referToA1!.pack(builder) : 0));
|
||||
TableInC.addReferToA2(builder, (this.referToA2 !== null ? this.referToA2!.pack(builder) : 0));
|
||||
|
||||
return TableInC.endTableInC(builder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user