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

import * as flatbuffers from 'flatbuffers';

import { NumericType } from '../foxglove/numeric-type.ts';


/**
 * A field present within each element in a byte array of packed elements.
 */
export class PackedElementField {
  bb: flatbuffers.ByteBuffer|null = null;
  bb_pos = 0;
  __init(i:number, bb:flatbuffers.ByteBuffer):PackedElementField {
  this.bb_pos = i;
  this.bb = bb;
  return this;
}

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

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

/**
 * Name of the field
 */
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;
}

/**
 * Byte offset from start of data buffer
 */
offset():number {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0;
}

/**
 * Type of data in the field. Integers are stored using little-endian byte order.
 */
type():NumericType {
  const offset = this.bb!.__offset(this.bb_pos, 8);
  return offset ? this.bb!.readUint8(this.bb_pos + offset) : NumericType.UNKNOWN;
}

static startPackedElementField(builder:flatbuffers.Builder) {
  builder.startObject(3);
}

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

static addOffset(builder:flatbuffers.Builder, offset:number) {
  builder.addFieldInt32(1, offset, 0);
}

static addType(builder:flatbuffers.Builder, type:NumericType) {
  builder.addFieldInt8(2, type, NumericType.UNKNOWN);
}

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

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

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

static createPackedElementField(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset, offset:number, type:NumericType):flatbuffers.Offset {
  PackedElementField.startPackedElementField(builder);
  PackedElementField.addName(builder, nameOffset);
  PackedElementField.addOffset(builder, offset);
  PackedElementField.addType(builder, type);
  return PackedElementField.endPackedElementField(builder);
}
}
