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

import * as flatbuffers from 'flatbuffers';

import { RecordBatch } from './record-batch.js';


/**
 * For sending dictionary encoding information. Any Field can be
 * dictionary-encoded, but in this case none of its children may be
 * dictionary-encoded.
 * There is one vector / column per dictionary, but that vector / column
 * may be spread across multiple dictionary batches by using the isDelta
 * flag
 */
export class DictionaryBatch {
  bb: flatbuffers.ByteBuffer|null = null;
  bb_pos = 0;
  __init(i:number, bb:flatbuffers.ByteBuffer):DictionaryBatch {
  this.bb_pos = i;
  this.bb = bb;
  return this;
}

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

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

id():bigint {
  const offset = this.bb!.__offset(this.bb_pos, 4);
  return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0');
}

data(obj?:RecordBatch):RecordBatch|null {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? (obj || new RecordBatch()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

/**
 * If isDelta is true the values in the dictionary are to be appended to a
 * dictionary with the indicated id. If isDelta is false this dictionary
 * should replace the existing dictionary.
 */
isDelta():boolean {
  const offset = this.bb!.__offset(this.bb_pos, 8);
  return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
}

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

static addId(builder:flatbuffers.Builder, id:bigint) {
  builder.addFieldInt64(0, id, BigInt('0'));
}

static addData(builder:flatbuffers.Builder, dataOffset:flatbuffers.Offset) {
  builder.addFieldOffset(1, dataOffset, 0);
}

static addIsDelta(builder:flatbuffers.Builder, isDelta:boolean) {
  builder.addFieldInt8(2, +isDelta, +false);
}

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

}
