import { JSON, JSONMode } from "../.."; import { deserializeArbitraryArray } from "../naive/array/arbitrary"; import { deserializeArrayArray } from "../naive/array/array"; import { deserializeBooleanArray } from "../naive/array/bool"; import { deserializeBoxArray } from "../naive/array/box"; import { deserializeFloatArray_NAIVE } from "../naive/array/float"; import { deserializeGenericArray } from "../naive/array/generic"; import { deserializeIntegerArray_NAIVE } from "../naive/array/integer"; import { deserializeMapArray } from "../naive/array/map"; import { deserializeObjectArray } from "../naive/array/object"; import { deserializeRawArray } from "../naive/array/raw"; import { deserializeStringArray_NAIVE } from "../naive/array/string"; import { deserializeStructArray } from "../naive/array/struct"; import { deserializeIntegerArray_SIMD } from "../simd/array/integer"; import { deserializeIntegerArray_SWAR } from "../swar/array/integer"; import { deserializeFloatArray_SWAR } from "../swar/array/float"; import { deserializeStringArray_SWAR } from "../swar/array/string"; export { deserializeArrayField, deserializeArrayField as deserializeArrayField_SWAR, } from "../swar/array"; export function deserializeArray( srcStart: usize, srcEnd: usize, dst: usize, ): T { if (isString>()) { // SWAR/SIMD routes through the same `Into` helper used by the // struct-field path; that helper carries the `null` token fast path // for `(string | null)[]`. NAIVE keeps the naive scanner, which // currently only handles non-nullable string arrays. The naive // variant's static `string[]` return type is bit-identical to // `(string | null)[]` so `changetype` is a runtime no-op. if (JSON_MODE == JSONMode.SWAR || JSON_MODE == JSONMode.SIMD) { return deserializeStringArray_SWAR(srcStart, srcEnd, dst); } return changetype(deserializeStringArray_NAIVE(srcStart, srcEnd, dst)); } else if (isBoolean>()) { return deserializeBooleanArray(srcStart, srcEnd, dst); } else if (isInteger>()) { if (JSON_MODE == JSONMode.SIMD) { // @ts-ignore: integer array branch return deserializeIntegerArray_SIMD(srcStart, srcEnd, dst); } else if (JSON_MODE == JSONMode.SWAR) { // @ts-ignore: integer array branch return deserializeIntegerArray_SWAR(srcStart, srcEnd, dst); } else { // @ts-ignore: integer array branch return deserializeIntegerArray_NAIVE(srcStart, srcEnd, dst); } } else if (isFloat>()) { if (JSON_MODE == JSONMode.SWAR || JSON_MODE == JSONMode.SIMD) { // @ts-ignore: float array branch return deserializeFloatArray_SWAR(srcStart, srcEnd, dst); } return deserializeFloatArray_NAIVE(srcStart, srcEnd, dst); } else if (isArray>()) { return deserializeArrayArray(srcStart, srcEnd, dst); } else if (isManaged>() || isReference>()) { const type = changetype>>(0); if (type instanceof JSON.Value) { return deserializeArbitraryArray(srcStart, srcEnd, dst) as T; } else if (type instanceof JSON.Box) { return deserializeBoxArray(srcStart, srcEnd, dst); } else if (type instanceof JSON.Obj) { return deserializeObjectArray(srcStart, srcEnd, dst); } else if (type instanceof JSON.Raw) { return deserializeRawArray(srcStart, srcEnd, dst) as T; } else if (type instanceof Date) { return deserializeGenericArray(srcStart, srcEnd, dst); } else if (type instanceof Set) { return deserializeGenericArray(srcStart, srcEnd, dst); } else if (type instanceof Map) { return deserializeMapArray(srcStart, srcEnd, dst); // @ts-ignore: defined by transform } else if (isDefined(type.__DESERIALIZE_CUSTOM)) { return deserializeStructArray(srcStart, srcEnd, dst); // @ts-ignore: defined by transform } else if ( isDefined(type.__DESERIALIZE_SLOW) || isDefined(type.__DESERIALIZE_FAST) ) { return deserializeStructArray(srcStart, srcEnd, dst); } throw new Error("Could not parse array of type " + nameof() + "!"); } else { throw new Error("Could not parse array of type " + nameof() + "!"); } }