"use strict";
// automatically generated by the FlatBuffers compiler, do not modify
Object.defineProperty(exports, "__esModule", { value: true });
exports.RtpMappingT = exports.RtpMapping = 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 codec_mapping_1 = require("../../fbs/rtp-parameters/codec-mapping");
const encoding_mapping_1 = require("../../fbs/rtp-parameters/encoding-mapping");
class RtpMapping {
    bb = null;
    bb_pos = 0;
    __init(i, bb) {
        this.bb_pos = i;
        this.bb = bb;
        return this;
    }
    static getRootAsRtpMapping(bb, obj) {
        return (obj || new RtpMapping()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
    }
    static getSizePrefixedRootAsRtpMapping(bb, obj) {
        bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
        return (obj || new RtpMapping()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
    }
    codecs(index, obj) {
        const offset = this.bb.__offset(this.bb_pos, 4);
        return offset ? (obj || new codec_mapping_1.CodecMapping()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
    }
    codecsLength() {
        const offset = this.bb.__offset(this.bb_pos, 4);
        return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
    }
    encodings(index, obj) {
        const offset = this.bb.__offset(this.bb_pos, 6);
        return offset ? (obj || new encoding_mapping_1.EncodingMapping()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
    }
    encodingsLength() {
        const offset = this.bb.__offset(this.bb_pos, 6);
        return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
    }
    static startRtpMapping(builder) {
        builder.startObject(2);
    }
    static addCodecs(builder, codecsOffset) {
        builder.addFieldOffset(0, codecsOffset, 0);
    }
    static createCodecsVector(builder, data) {
        builder.startVector(4, data.length, 4);
        for (let i = data.length - 1; i >= 0; i--) {
            builder.addOffset(data[i]);
        }
        return builder.endVector();
    }
    static startCodecsVector(builder, numElems) {
        builder.startVector(4, numElems, 4);
    }
    static addEncodings(builder, encodingsOffset) {
        builder.addFieldOffset(1, encodingsOffset, 0);
    }
    static createEncodingsVector(builder, data) {
        builder.startVector(4, data.length, 4);
        for (let i = data.length - 1; i >= 0; i--) {
            builder.addOffset(data[i]);
        }
        return builder.endVector();
    }
    static startEncodingsVector(builder, numElems) {
        builder.startVector(4, numElems, 4);
    }
    static endRtpMapping(builder) {
        const offset = builder.endObject();
        builder.requiredField(offset, 4); // codecs
        builder.requiredField(offset, 6); // encodings
        return offset;
    }
    static createRtpMapping(builder, codecsOffset, encodingsOffset) {
        RtpMapping.startRtpMapping(builder);
        RtpMapping.addCodecs(builder, codecsOffset);
        RtpMapping.addEncodings(builder, encodingsOffset);
        return RtpMapping.endRtpMapping(builder);
    }
    unpack() {
        return new RtpMappingT(this.bb.createObjList(this.codecs.bind(this), this.codecsLength()), this.bb.createObjList(this.encodings.bind(this), this.encodingsLength()));
    }
    unpackTo(_o) {
        _o.codecs = this.bb.createObjList(this.codecs.bind(this), this.codecsLength());
        _o.encodings = this.bb.createObjList(this.encodings.bind(this), this.encodingsLength());
    }
}
exports.RtpMapping = RtpMapping;
class RtpMappingT {
    codecs;
    encodings;
    constructor(codecs = [], encodings = []) {
        this.codecs = codecs;
        this.encodings = encodings;
    }
    pack(builder) {
        const codecs = RtpMapping.createCodecsVector(builder, builder.createObjectOffsetList(this.codecs));
        const encodings = RtpMapping.createEncodingsVector(builder, builder.createObjectOffsetList(this.encodings));
        return RtpMapping.createRtpMapping(builder, codecs, encodings);
    }
}
exports.RtpMappingT = RtpMappingT;
