(ns, key, str)
| 55 | writeHeaderEntry(ns, type, 1, key, d8); |
| 56 | }; |
| 57 | const writeString = (ns, key, str) => { |
| 58 | const enc = new TextEncoder().encode(str); |
| 59 | const data = new Uint8Array(enc.length + 1); data.set(enc); // + null terminator |
| 60 | const datalen = data.length; // strlen + 1 |
| 61 | const dataEntries = ((datalen + 31) & ~31) / 32; |
| 62 | const d8 = new Uint8Array(8).fill(0xFF); |
| 63 | d8[0] = datalen & 0xFF; d8[1] = (datalen >> 8) & 0xFF; // size (incl. null) |
| 64 | const dcrc = zlibCrc32(data, CRC_SEED); |
| 65 | d8[4] = dcrc & 0xFF; d8[5] = (dcrc >> 8) & 0xFF; d8[6] = (dcrc >> 16) & 0xFF; d8[7] = (dcrc >>> 24) & 0xFF; |
| 66 | writeHeaderEntry(ns, T_STR, 1 + dataEntries, key, d8); |
| 67 | for (let de = 0; de < dataEntries; de++) { // raw data chunks (no per-entry CRC) |
| 68 | const o = off(slot); |
| 69 | for (let i = 0; i < 32; i++) { const di = de * 32 + i; buf[o + i] = di < data.length ? data[di] : 0xFF; } |
| 70 | markWritten(slot); slot++; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | for (const k of keys) { |
| 75 | if (k.type === 'namespace') writePrimitive(0, T_U8, k.key, [k.value & 0xFF]); |
no test coverage detected