MCPcopy Create free account
hub / github.com/Effect-TS/effect / decodeStructPositional

Function decodeStructPositional

packages/effect/src/encoding/SchemaBinary.ts:4707–4753  ·  view source on GitHub ↗
(layout: StructLayout, r: Reader)

Source from the content-addressed store, hash-verified

4705}
4706
4707function 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
4755function decodeExtraPairs(
4756 layout: StructLayout,

Callers 1

decodeValueUncheckedFunction · 0.85

Calls 9

assignPropertyFunction · 0.90
decodeSlotFunction · 0.85
decodeSizedFunction · 0.85
missingKeyIssueFunction · 0.85
throwMissingKeysFunction · 0.85
decodeExtraPairFunction · 0.85
invalidFunction · 0.70
pushMethod · 0.65
uvarintMethod · 0.45

Tested by

no test coverage detected