...

Text file src/github.com/google/flatbuffers/tests/ts/my-game/example/test-simple-table-with-enum.ts

Documentation: github.com/google/flatbuffers/tests/ts/my-game/example

     1// automatically generated by the FlatBuffers compiler, do not modify
     2
     3import * as flatbuffers from 'flatbuffers';
     4
     5import { Color } from '../../my-game/example/color.js';
     6
     7
     8export class TestSimpleTableWithEnum implements flatbuffers.IUnpackableObject<TestSimpleTableWithEnumT> {
     9  bb: flatbuffers.ByteBuffer|null = null;
    10  bb_pos = 0;
    11  __init(i:number, bb:flatbuffers.ByteBuffer):TestSimpleTableWithEnum {
    12  this.bb_pos = i;
    13  this.bb = bb;
    14  return this;
    15}
    16
    17static getRootAsTestSimpleTableWithEnum(bb:flatbuffers.ByteBuffer, obj?:TestSimpleTableWithEnum):TestSimpleTableWithEnum {
    18  return (obj || new TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
    19}
    20
    21static getSizePrefixedRootAsTestSimpleTableWithEnum(bb:flatbuffers.ByteBuffer, obj?:TestSimpleTableWithEnum):TestSimpleTableWithEnum {
    22  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
    23  return (obj || new TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
    24}
    25
    26color():Color {
    27  const offset = this.bb!.__offset(this.bb_pos, 4);
    28  return offset ? this.bb!.readUint8(this.bb_pos + offset) : Color.Green;
    29}
    30
    31mutate_color(value:Color):boolean {
    32  const offset = this.bb!.__offset(this.bb_pos, 4);
    33
    34  if (offset === 0) {
    35    return false;
    36  }
    37
    38  this.bb!.writeUint8(this.bb_pos + offset, value);
    39  return true;
    40}
    41
    42static getFullyQualifiedName():string {
    43  return 'MyGame.Example.TestSimpleTableWithEnum';
    44}
    45
    46static startTestSimpleTableWithEnum(builder:flatbuffers.Builder) {
    47  builder.startObject(1);
    48}
    49
    50static addColor(builder:flatbuffers.Builder, color:Color) {
    51  builder.addFieldInt8(0, color, Color.Green);
    52}
    53
    54static endTestSimpleTableWithEnum(builder:flatbuffers.Builder):flatbuffers.Offset {
    55  const offset = builder.endObject();
    56  return offset;
    57}
    58
    59static createTestSimpleTableWithEnum(builder:flatbuffers.Builder, color:Color):flatbuffers.Offset {
    60  TestSimpleTableWithEnum.startTestSimpleTableWithEnum(builder);
    61  TestSimpleTableWithEnum.addColor(builder, color);
    62  return TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder);
    63}
    64
    65serialize():Uint8Array {
    66  return this.bb!.bytes();
    67}
    68
    69static deserialize(buffer: Uint8Array):TestSimpleTableWithEnum {
    70  return TestSimpleTableWithEnum.getRootAsTestSimpleTableWithEnum(new flatbuffers.ByteBuffer(buffer))
    71}
    72
    73unpack(): TestSimpleTableWithEnumT {
    74  return new TestSimpleTableWithEnumT(
    75    this.color()
    76  );
    77}
    78
    79
    80unpackTo(_o: TestSimpleTableWithEnumT): void {
    81  _o.color = this.color();
    82}
    83}
    84
    85export class TestSimpleTableWithEnumT implements flatbuffers.IGeneratedObject {
    86constructor(
    87  public color: Color = Color.Green
    88){}
    89
    90
    91pack(builder:flatbuffers.Builder): flatbuffers.Offset {
    92  return TestSimpleTableWithEnum.createTestSimpleTableWithEnum(builder,
    93    this.color
    94  );
    95}
    96}

View as plain text