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

Function decodeRunRow

packages/effect/src/encoding/SchemaBinary.ts:4828–4899  ·  view source on GitHub ↗
(
  plan: RunPlan,
  shapes: Array<Array<RunSlot>>,
  tables: Array<Array<unknown> | undefined>,
  r: Reader
)

Source from the content-addressed store, hash-verified

4826}
4827
4828function decodeRunRow(
4829 plan: RunPlan,
4830 shapes: Array<Array<RunSlot>>,
4831 tables: Array<Array<unknown> | undefined>,
4832 r: Reader
4833): unknown {
4834 const struct = plan.struct
4835 const out: Record<string, unknown> = {}
4836 let presentMask = 0
4837 let presentWide: Set<number> | undefined
4838 const code = r.uvarint()
4839 let shape: Array<RunSlot> | undefined
4840 if (code === 0) {
4841 if (r.positional && plan.shapes) {
4842 shape = positionalRunShape(struct, r)
4843 shapes.push(shape)
4844 }
4845 } else {
4846 shape = shapes[code - 1]
4847 if (shape === undefined) invalid("a known row shape", undefined, r.options)
4848 }
4849 if (shape !== undefined) {
4850 for (let i = 0; i < shape.length; i++) {
4851 const filled = decodeRunSlot(plan, tables, shape[i], out, r)
4852 if (filled >= 0) {
4853 if (filled < 32) presentMask |= 1 << filled
4854 else (presentWide ??= new Set()).add(filled)
4855 }
4856 }
4857 if (r.pos !== r.end) invalid("no leftover bytes", undefined, r.options)
4858 } else {
4859 const declared: Array<RunSlot> | undefined = plan.shapes ? [] : undefined
4860 let seenMask = 0
4861 let seenWide: Set<number> | undefined
4862 let seenIds: Set<number> | undefined
4863 let seenExtra = false
4864 while (r.pos < r.end) {
4865 const id = r.uvarint()
4866 let slot: RunSlot
4867 if (id === 0) {
4868 if (seenExtra) invalid("unique field ids", undefined, r.options)
4869 seenExtra = true
4870 slot = null
4871 } else {
4872 slot = struct.byId.get(id)
4873 if (slot === undefined) {
4874 if (r.rejectUnknownFields) invalid("a known field id", id, r.options)
4875 if (seenIds === undefined) seenIds = new Set([id])
4876 else if (seenIds.has(id)) invalid("unique field ids", undefined, r.options)
4877 else seenIds.add(id)
4878 } else if (slot.index < 32) {
4879 if ((seenMask & (1 << slot.index)) !== 0) invalid("unique field ids", undefined, r.options)
4880 seenMask |= 1 << slot.index
4881 } else if (seenWide === undefined) {
4882 seenWide = new Set([slot.index])
4883 } else {
4884 if (seenWide.has(slot.index)) invalid("unique field ids", undefined, r.options)
4885 seenWide.add(slot.index)

Callers 1

decodeStructRunFunction · 0.85

Calls 9

positionalRunShapeFunction · 0.85
decodeRunSlotFunction · 0.85
checkRequiredFieldsFunction · 0.85
invalidFunction · 0.70
pushMethod · 0.65
addMethod · 0.65
getMethod · 0.65
hasMethod · 0.65
uvarintMethod · 0.45

Tested by

no test coverage detected