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

Function decodeRunSlot

packages/effect/src/encoding/SchemaBinary.ts:4902–4945  ·  view source on GitHub ↗
(
  plan: RunPlan,
  tables: Array<Array<unknown> | undefined>,
  slot: RunSlot,
  out: Record<string, unknown>,
  r: Reader
)

Source from the content-addressed store, hash-verified

4900
4901// Returns the field index this slot filled, or -1.
4902function decodeRunSlot(
4903 plan: RunPlan,
4904 tables: Array<Array<unknown> | undefined>,
4905 slot: RunSlot,
4906 out: Record<string, unknown>,
4907 r: Reader
4908): number {
4909 const code = r.uvarint()
4910 if ((code & 1) === 1) {
4911 if (slot === null || slot === undefined) return -1
4912 const table = tables[slot.index]
4913 const ref = (code - 1) / 2
4914 if (table === undefined || ref >= table.length) {
4915 invalid("a known back-reference", undefined, r.options)
4916 }
4917 const value = table[ref]
4918 if (value === ABSENT) return -1
4919 assignProperty(out, slot.name, value)
4920 return slot.index
4921 }
4922 const saved = r.enter(code / 2)
4923 if (slot === null) {
4924 decodeExtraPairs(plan.struct, r, out)
4925 r.exit(saved)
4926 return -1
4927 }
4928 if (slot === undefined) {
4929 r.exit(saved)
4930 return -1
4931 }
4932 const kind = plan.intern[slot.index]
4933 if (kind === INTERN_ELEMENTS || kind === INTERN_KEYS) {
4934 r.intern = tables[slot.index] ??= []
4935 }
4936 issuePath[issuePathLen++] = slot.name
4937 const value = decodeChecked(slot.layout, r)
4938 issuePathLen--
4939 r.intern = undefined
4940 r.exit(saved)
4941 if (kind === INTERN_SELF) (tables[slot.index] ??= []).push(value)
4942 if (value === ABSENT) return -1
4943 assignProperty(out, slot.name, value)
4944 return slot.index
4945}
4946
4947function decodeArray(layout: ArrayLayout, r: Reader): unknown {
4948 const elementLen = layout.elements.length

Callers 1

decodeRunRowFunction · 0.85

Calls 8

assignPropertyFunction · 0.90
decodeExtraPairsFunction · 0.85
decodeCheckedFunction · 0.85
enterMethod · 0.80
exitMethod · 0.80
invalidFunction · 0.70
pushMethod · 0.65
uvarintMethod · 0.45

Tested by

no test coverage detected