import { BinaryClassUpgrader } from "../../../ecs/storage/binary/BinaryClassUpgrader.js";

export class PathSerializationUpgrader_1_2 extends BinaryClassUpgrader {
    constructor() {
        super();

        this.__startVersion = 1;
        this.__targetVersion = 2;
    }

    upgrade(source, target) {
        //write interpolation type
        const interpolation = source.readUint8();

        source.readUintVar(); // marker index - ignore
        source.readFloat32(); // marker offset - ignore

        const numPoints = source.readUintVar();

        const point_data_size = numPoints * 3;
        const point_data = new Float32Array(point_data_size);

        source.readFloat32Array(point_data, 0, point_data_size);


        target.writeUint8(interpolation);

        target.writeUintVar(numPoints);
        target.writeUintVar(3); //elements per point

        target.writeFloat32Array(point_data, 0, point_data_size);
    }
}
