import { BRACKET_LEFT, BRACKET_RIGHT } from "../../../custom/chars"; import { JSON } from "../../../"; export function deserializeStaticArrayArray>( srcStart: usize, srcEnd: usize, dst: usize, ): T { let count: i32 = 0; let depth: u32 = 0; let ptr = srcStart + 2; while (ptr < srcEnd - 2) { const code = load(ptr); if (code == BRACKET_LEFT && depth++ == 0) { // start of nested array } else if (code == BRACKET_RIGHT && --depth == 0) { count++; } ptr += 2; } const outSize = count * sizeof>(); const out = changetype>(dst || __new(outSize, idof())); // Second pass: populate values let index = 0; let lastIndex: usize = 0; depth = 0; srcStart += 2; while (srcStart < srcEnd - 2) { const code = load(srcStart); if (code == BRACKET_LEFT && depth++ == 0) { lastIndex = srcStart; } else if (code == BRACKET_RIGHT && --depth == 0) { unchecked( (out[index++] = JSON.__deserialize>( lastIndex, srcStart + 2, )), ); } srcStart += 2; } return out; }