async function encodeWeights(tensors, group) {
    // TODO(adarob, cais): Support quantization.
    const specs = [];
    const dataPromises = [];
    const names = Array.isArray(tensors) ? tensors.map((tensor)=>tensor.name) : Object.keys(tensors);
    for(let i = 0; i < names.length; ++i){
        const name = names[i];
        const t = Array.isArray(tensors) ? tensors[i].tensor : tensors[name];
        if (t.dtype !== "float32" && t.dtype !== "int32" && t.dtype !== "bool" && t.dtype !== "string" && t.dtype !== "complex64") throw new Error(`Unsupported dtype in weight '${name}': ${t.dtype}`);
        const spec = {
            name,
            shape: t.shape,
            dtype: t.dtype
        };
        if (t.dtype === "string") {
            const utf8bytes = new Promise(async (resolve)=>{
                const vals = await t.bytes();
                const totalNumBytes = vals.reduce((p, c)=>p + c.length, 0) + NUM_BYTES_STRING_LENGTH * vals.length;
                const bytes = new Uint8Array(totalNumBytes);
                let offset = 0;
                for(let i = 0; i < vals.length; i++){
                    const val = vals[i];
                    const bytesOfLength = new Uint8Array(new Uint32Array([
                        val.length
                    ]).buffer);
                    bytes.set(bytesOfLength, offset);
                    offset += NUM_BYTES_STRING_LENGTH;
                    bytes.set(val, offset);
                    offset += val.length;
                }
                resolve(bytes);
            });
            dataPromises.push(utf8bytes);
        } else dataPromises.push(t.data());
        if (group != null) spec.group = group;
        specs.push(spec);
    }
    const tensorValues = await Promise.all(dataPromises);
    return {
        data: concatenateTypedArrays(tensorValues),
        specs
    };
}
Number of bytes reserved for the length of the string. (32bit integer).