"use strict";
// automatically generated by the FlatBuffers compiler, do not modify
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatsT = exports.Stats = void 0;
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
const flatbuffers = require("flatbuffers");
const stats_data_1 = require("../../fbs/rtp-stream/stats-data");
class Stats {
    bb = null;
    bb_pos = 0;
    __init(i, bb) {
        this.bb_pos = i;
        this.bb = bb;
        return this;
    }
    static getRootAsStats(bb, obj) {
        return (obj || new Stats()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
    }
    static getSizePrefixedRootAsStats(bb, obj) {
        bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
        return (obj || new Stats()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
    }
    dataType() {
        const offset = this.bb.__offset(this.bb_pos, 4);
        return offset ? this.bb.readUint8(this.bb_pos + offset) : stats_data_1.StatsData.NONE;
    }
    data(obj) {
        const offset = this.bb.__offset(this.bb_pos, 6);
        return offset ? this.bb.__union(obj, this.bb_pos + offset) : null;
    }
    static startStats(builder) {
        builder.startObject(2);
    }
    static addDataType(builder, dataType) {
        builder.addFieldInt8(0, dataType, stats_data_1.StatsData.NONE);
    }
    static addData(builder, dataOffset) {
        builder.addFieldOffset(1, dataOffset, 0);
    }
    static endStats(builder) {
        const offset = builder.endObject();
        builder.requiredField(offset, 6); // data
        return offset;
    }
    static createStats(builder, dataType, dataOffset) {
        Stats.startStats(builder);
        Stats.addDataType(builder, dataType);
        Stats.addData(builder, dataOffset);
        return Stats.endStats(builder);
    }
    unpack() {
        return new StatsT(this.dataType(), (() => {
            const temp = (0, stats_data_1.unionToStatsData)(this.dataType(), this.data.bind(this));
            if (temp === null) {
                return null;
            }
            return temp.unpack();
        })());
    }
    unpackTo(_o) {
        _o.dataType = this.dataType();
        _o.data = (() => {
            const temp = (0, stats_data_1.unionToStatsData)(this.dataType(), this.data.bind(this));
            if (temp === null) {
                return null;
            }
            return temp.unpack();
        })();
    }
}
exports.Stats = Stats;
class StatsT {
    dataType;
    data;
    constructor(dataType = stats_data_1.StatsData.NONE, data = null) {
        this.dataType = dataType;
        this.data = data;
    }
    pack(builder) {
        const data = builder.createObjectOffset(this.data);
        return Stats.createStats(builder, this.dataType, data);
    }
}
exports.StatsT = StatsT;
