import { BinaryDataType } from "./BinaryDataType.js";

/**
 * @readonly
 * @enum {number}
 */
export const DataTypeByteSizes = {
    [BinaryDataType.Uint8]: 1,
    [BinaryDataType.Uint16]: 2,
    [BinaryDataType.Uint32]: 4,
    [BinaryDataType.Uint64]: 8,

    [BinaryDataType.Int8]: 1,
    [BinaryDataType.Int16]: 2,
    [BinaryDataType.Int32]: 4,
    [BinaryDataType.Int64]: 8,

    [BinaryDataType.Float16]: 2,
    [BinaryDataType.Float32]: 4,
    [BinaryDataType.Float64]: 8
};


/**
 *
 * @param {BinaryDataType} type
 * @return {number}
 */
export function dataTypeByteSize(type) {
    const size = DataTypeByteSizes[type];

    if (size === undefined) {
        throw new Error(`Unsupported type '${type}'`);
    }

    return size;
}
