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

Function decodeValueUnchecked

packages/effect/src/encoding/SchemaBinary.ts:5145–5301  ·  view source on GitHub ↗
(layout: Layout, r: Reader)

Source from the content-addressed store, hash-verified

5143}
5144
5145function decodeValueUnchecked(layout: Layout, r: Reader): unknown {
5146 switch (layout._) {
5147 case "literal": {
5148 const value = decodeValue(layout.leaf, r)
5149 if (!hasLiteral(layout, value)) invalid(literalExpected(layout), value, r.options)
5150 return value
5151 }
5152 case "bool": {
5153 if (r.remaining !== 1) invalid("bool", undefined, r.options)
5154 const b = r.byte()
5155 if (b > 1) invalid("bool", undefined, r.options)
5156 return b === 1
5157 }
5158 case "null":
5159 if (r.remaining !== 0) invalid("empty", undefined, r.options)
5160 return null
5161 case "undefined":
5162 if (r.remaining !== 0) invalid("empty", undefined, r.options)
5163 return undefined
5164 case "number": {
5165 const len = r.remaining
5166 if (len === 8) return r.f64()
5167 if (len === 0 || len > NUMBER_VARINT_MAX_BYTES) invalid("f64", undefined, r.options)
5168 const value = r.numberVarint()
5169 if (r.remaining === 0) return value
5170 const scale = r.byte()
5171 if (r.remaining !== 0 || scale === 0 || scale > DECIMAL_SCALE_MAX) {
5172 invalid("decimal", undefined, r.options)
5173 }
5174 return value / POW10[scale]
5175 }
5176 case "int":
5177 return r.numberVarint()
5178 case "string": {
5179 const dict = r.dict
5180 return dict === undefined ? r.readUtf8(r.end - r.pos) : decodeString(dict, layout, r)
5181 }
5182 case "symbol":
5183 return globalThis.Symbol.for(r.readUtf8(r.end - r.pos))
5184 case "bytes":
5185 return r.takeCopy(r.end - r.pos)
5186 case "bigint":
5187 return r.zigzag()
5188 case "i32":
5189 if (r.remaining !== 4) invalid("a 32-bit integer", undefined, r.options)
5190 return r.i32le()
5191 case "u32":
5192 if (r.remaining !== 4) invalid("a 32-bit unsigned integer", undefined, r.options)
5193 return r.u32le()
5194 case "i64":
5195 if (r.remaining !== 8) invalid("a 64-bit integer", undefined, r.options)
5196 return r.i64()
5197 case "u64":
5198 if (r.remaining !== 8) invalid("a 64-bit unsigned integer", undefined, r.options)
5199 return r.u64()
5200 case "int64": {
5201 if (r.remaining !== 8) invalid("int64", undefined, r.options)
5202 const millis = Number(r.i64())

Callers 1

decodeValueFunction · 0.85

Calls 15

hasLiteralFunction · 0.85
literalExpectedFunction · 0.85
requirePresentFunction · 0.85
decodeCheckedFunction · 0.85
decodeReasonFunction · 0.85
decodeStructPositionalFunction · 0.85
decodeStructFunction · 0.85
decodeUnionPositionalFunction · 0.85
decodeUnionFunction · 0.85
issueErrorFunction · 0.85
readUtf8Method · 0.80
takeCopyMethod · 0.80

Tested by

no test coverage detected