(layout: StructLayout, r: Reader)
| 4705 | } |
| 4706 | |
| 4707 | function decodeStructPositional(layout: StructLayout, r: Reader): unknown { |
| 4708 | // Only a run field with index signatures hands over an intern table. Extras |
| 4709 | // decode after the fields here, so claim it before a nested field can. |
| 4710 | let keys: Array<unknown> | undefined |
| 4711 | if (layout.extra.length > 0) { |
| 4712 | keys = r.intern |
| 4713 | r.intern = undefined |
| 4714 | } |
| 4715 | const out: Record<string, unknown> = {} |
| 4716 | const bitmapBytes = (layout.optionalCount + 7) >> 3 |
| 4717 | let bitmap = 0 |
| 4718 | if (bitmapBytes > 0) { |
| 4719 | if (r.pos + bitmapBytes > r.end) invalid("complete value", undefined, r.options) |
| 4720 | bitmap = r.pos |
| 4721 | r.pos += bitmapBytes |
| 4722 | } |
| 4723 | const buf = r.buf |
| 4724 | const fields = layout.fields |
| 4725 | let optionalIndex = 0 |
| 4726 | let issues: Array<SchemaIssue.Issue> | undefined |
| 4727 | for (let i = 0; i < fields.length; i++) { |
| 4728 | const field = fields[i] |
| 4729 | if (field.optional) { |
| 4730 | const present = (buf[bitmap + (optionalIndex >> 3)] & (1 << (optionalIndex & 7))) !== 0 |
| 4731 | optionalIndex++ |
| 4732 | if (!present) continue |
| 4733 | } |
| 4734 | issuePath[issuePathLen++] = field.name |
| 4735 | const value = field.inline ? decodeSlot(field.layout, r) : decodeSized(field.layout, r) |
| 4736 | issuePathLen-- |
| 4737 | if (value !== ABSENT) assignProperty(out, field.name, value) |
| 4738 | else if (!field.optional) { |
| 4739 | ;(issues ??= []).push(missingKeyIssue(field)) |
| 4740 | if (r.options.errors !== "all") break |
| 4741 | } |
| 4742 | } |
| 4743 | if (issues !== undefined) throwMissingKeys(layout, issues) |
| 4744 | if (layout.extra.length > 0) { |
| 4745 | const count = r.uvarint() |
| 4746 | if (count > r.remaining) invalid("complete value", undefined, r.options) |
| 4747 | if (count > 0) { |
| 4748 | const seen: SeenKeys = { list: [], set: undefined } |
| 4749 | for (let i = 0; i < count; i++) decodeExtraPair(layout, r, out, seen, keys) |
| 4750 | } |
| 4751 | } |
| 4752 | return out |
| 4753 | } |
| 4754 | |
| 4755 | function decodeExtraPairs( |
| 4756 | layout: StructLayout, |
no test coverage detected