Files
flatbuffers/tests/union_vector/gadget.ts
Derek Bailey a66de58af9 Partial support for --ts-flat-files and --gen-all (#7446)
* Partial support for --ts-flat-files and --gen-all

* Add generated code changes

* remove some debugging code left over

* missed grpc files
2022-08-15 16:11:45 -07:00

38 lines
1.0 KiB
TypeScript

// 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;
}
}