MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / writeString

Function writeString

rusense_flasher/js/nvs_gen.js:57–72  ·  view source on GitHub ↗
(ns, key, str)

Source from the content-addressed store, hash-verified

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]);

Callers 1

buildNvsPartitionFunction · 0.85

Calls 6

zlibCrc32Function · 0.85
writeHeaderEntryFunction · 0.85
offFunction · 0.85
markWrittenFunction · 0.85
setMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected