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

export class MeshSerializationAdapter extends BinaryClassSerializationAdapter {

    klass = Mesh;
    version = 0;


    /**
     *
     * @param {BinaryBuffer} buffer
     * @param {Mesh} value
     */
    serialize(buffer, value) {
        buffer.writeUTF8String(value.url);
        buffer.writeUint8(value.castShadow ? 1 : 0);
        buffer.writeUint8(value.receiveShadow ? 1 : 0);

        buffer.writeUint8(0); // deprecated "center" flag

        buffer.writeFloat32(value.opacity);
    }

    /**
     *
     * @param {BinaryBuffer} buffer
     * @param {Mesh} value
     */
    deserialize(buffer, value) {
        value.url = buffer.readUTF8String();
        value.castShadow = buffer.readUint8() !== 0;
        value.receiveShadow = buffer.readUint8() !== 0;

        const deprecated_centerFlag = buffer.readUint8();

        value.opacity = buffer.readFloat32();
    }

}
