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

Function decodeArray

packages/effect/src/encoding/SchemaBinary.ts:4947–5036  ·  view source on GitHub ↗
(layout: ArrayLayout, r: Reader)

Source from the content-addressed store, hash-verified

4945}
4946
4947function 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++) {

Callers 4

decodeValueUncheckedFunction · 0.70
orderedFunction · 0.50

Calls 15

issueErrorFunction · 0.85
isZeroWidthSlotFunction · 0.85
runPlanFunction · 0.85
decodeStructRunFunction · 0.85
decodeNumberRunFunction · 0.85
decodeInternedFunction · 0.85
isSelfDelimitingFunction · 0.85
decodeSizedFunction · 0.85
decodeCheckedFunction · 0.85
arraySlotFunction · 0.85
decodeSlotFunction · 0.85
readUtf8Method · 0.80

Tested by

no test coverage detected