(layout: ArrayLayout, r: Reader)
| 4945 | } |
| 4946 | |
| 4947 | function decodeArray(layout: ArrayLayout, r: Reader): unknown { |
| 4948 | const elementLen = layout.elements.length |
| 4949 | const count = layout.hasCount ? r.uvarint() : elementLen |
| 4950 | if (layout.rest.length === 0 && count > elementLen) { |
| 4951 | issuePath[issuePathLen++] = elementLen |
| 4952 | throw issueError(new SchemaIssue.UnexpectedKey(layout.ast, undefined, r.options)) |
| 4953 | } |
| 4954 | if (count < layout.minCount) { |
| 4955 | issuePath[issuePathLen++] = count |
| 4956 | throw issueError(new SchemaIssue.MissingKey(undefined)) |
| 4957 | } |
| 4958 | if (layout.hasCount) { |
| 4959 | const allocationLimit = layout.rest.length > 0 && isZeroWidthSlot(layout.rest[0]) |
| 4960 | ? ZERO_WIDTH_ARRAY_MAX |
| 4961 | : r.remaining + ARRAY_ALLOCATION_SLACK |
| 4962 | if (count > allocationLimit) invalid("array count within allocation limit", count, r.options) |
| 4963 | } |
| 4964 | if (count > 0) { |
| 4965 | const plan = runPlan(layout) |
| 4966 | if (plan !== null) return decodeStructRun(plan, count, r) |
| 4967 | } |
| 4968 | const out: Array<unknown> = new Array(count) |
| 4969 | const uniform = layout.uniform |
| 4970 | if (uniform !== undefined) { |
| 4971 | if (layout.uniformNumbers) return decodeNumberRun(out, count, r) |
| 4972 | // Only a run field holding an array of strings hands over an intern table. |
| 4973 | const table = r.intern |
| 4974 | r.intern = undefined |
| 4975 | if (table !== undefined) { |
| 4976 | for (let i = 0; i < count; i++) { |
| 4977 | issuePath[issuePathLen++] = i |
| 4978 | const value = decodeInterned(table, uniform, r) |
| 4979 | if (value === ABSENT) throw issueError(new SchemaIssue.MissingKey(undefined)) |
| 4980 | issuePathLen-- |
| 4981 | out[i] = value |
| 4982 | } |
| 4983 | return out |
| 4984 | } |
| 4985 | if (isSelfDelimiting(uniform)) { |
| 4986 | for (let i = 0; i < count; i++) { |
| 4987 | issuePath[issuePathLen++] = i |
| 4988 | out[i] = decodeValue(uniform, r) |
| 4989 | issuePathLen-- |
| 4990 | } |
| 4991 | return out |
| 4992 | } |
| 4993 | // Strings consume their whole region, so they skip the reader window. |
| 4994 | if (uniform._ === "string") { |
| 4995 | for (let i = 0; i < count; i++) { |
| 4996 | issuePath[issuePathLen++] = i |
| 4997 | out[i] = r.dict === undefined ? r.readUtf8(r.uvarint()) : decodeSized(uniform, r) |
| 4998 | issuePathLen-- |
| 4999 | } |
| 5000 | return out |
| 5001 | } |
| 5002 | const packed = layout.uniformPacked |
| 5003 | const inline = layout.uniformInline |
| 5004 | for (let i = 0; i < count; i++) { |
no test coverage detected