"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Tile
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.I3dmHeader = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const TileIO_1 = require("./TileIO");
/** Header preceding tile content in [i3dm](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/Instanced3DModel) format.
 * @internal
 */
class I3dmHeader extends TileIO_1.TileHeader {
    length;
    featureTableJsonPosition;
    featureTableJsonLength;
    featureTableBinaryLength;
    batchTableJsonLength;
    batchTableBinaryLength;
    gltfVersion;
    batchTableJson;
    get isValid() { return TileIO_1.TileFormat.I3dm === this.format; }
    constructor(stream) {
        super(stream);
        this.length = stream.readUint32();
        this.featureTableJsonLength = stream.readUint32();
        this.featureTableBinaryLength = stream.readUint32();
        this.batchTableJsonLength = stream.readUint32();
        this.batchTableBinaryLength = stream.readUint32();
        this.gltfVersion = stream.readUint32();
        this.featureTableJsonPosition = stream.curPos;
        stream.advance(this.featureTableJsonLength);
        stream.advance(this.featureTableBinaryLength);
        if (0 !== this.batchTableJsonLength) {
            const batchStrData = stream.nextBytes(this.batchTableJsonLength);
            const batchStr = (0, core_bentley_1.utf8ToString)(batchStrData);
            if (batchStr)
                this.batchTableJson = JSON.parse(batchStr);
        }
        stream.advance(this.batchTableBinaryLength);
        if (stream.isPastTheEnd)
            this.invalidate();
    }
}
exports.I3dmHeader = I3dmHeader;
//# sourceMappingURL=I3dmTileIO.js.map