// automatically generated by the FlatBuffers compiler, do not modify

/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */

import * as flatbuffers from 'flatbuffers';

export class Person {
  bb: flatbuffers.ByteBuffer | null = null;
  bb_pos = 0;
  __init(i: number, bb: flatbuffers.ByteBuffer): Person {
    this.bb_pos = i;
    this.bb = bb;
    return this;
  }

  static getRootAsPerson(bb: flatbuffers.ByteBuffer, obj?: Person): Person {
    return (obj || new Person()).__init(
      bb.readInt32(bb.position()) + bb.position(),
      bb,
    );
  }

  static getSizePrefixedRootAsPerson(
    bb: flatbuffers.ByteBuffer,
    obj?: Person,
  ): Person {
    bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
    return (obj || new Person()).__init(
      bb.readInt32(bb.position()) + bb.position(),
      bb,
    );
  }

  name(): string | null;
  name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
  name(optionalEncoding?: any): string | Uint8Array | null {
    const offset = this.bb!.__offset(this.bb_pos, 4);
    return offset
      ? this.bb!.__string(this.bb_pos + offset, optionalEncoding)
      : null;
  }

  age(): number {
    const offset = this.bb!.__offset(this.bb_pos, 6);
    return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0;
  }

  static startPerson(builder: flatbuffers.Builder) {
    builder.startObject(2);
  }

  static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) {
    builder.addFieldOffset(0, nameOffset, 0);
  }

  static addAge(builder: flatbuffers.Builder, age: number) {
    builder.addFieldInt16(1, age, 0);
  }

  static endPerson(builder: flatbuffers.Builder): flatbuffers.Offset {
    const offset = builder.endObject();
    return offset;
  }

  static finishPersonBuffer(
    builder: flatbuffers.Builder,
    offset: flatbuffers.Offset,
  ) {
    builder.finish(offset);
  }

  static finishSizePrefixedPersonBuffer(
    builder: flatbuffers.Builder,
    offset: flatbuffers.Offset,
  ) {
    builder.finish(offset, undefined, true);
  }

  static createPerson(
    builder: flatbuffers.Builder,
    nameOffset: flatbuffers.Offset,
    age: number,
  ): flatbuffers.Offset {
    Person.startPerson(builder);
    Person.addName(builder, nameOffset);
    Person.addAge(builder, age);
    return Person.endPerson(builder);
  }
}
