MCPcopy Create free account
hub / github.com/apache/fory / readDecimal

Function readDecimal

javascript/packages/core/lib/compatible/scalar.ts:148–171  ·  view source on GitHub ↗
(reader: BinaryReader)

Source from the content-addressed store, hash-verified

146}
147
148function readDecimal(reader: BinaryReader): Decimal {
149 const scale = reader.readVarInt32();
150 const header = reader.readVarUInt64();
151 if ((header & 1n) === 0n) {
152 return new Decimal(DecimalCodec.decodeZigZag64(header >> 1n), scale);
153 }
154 const meta = header >> 1n;
155 const length = Number(meta >> 1n);
156 if (length <= 0 || length > 0x7fffffff) {
157 throw new Error(`Invalid decimal magnitude length ${length}.`);
158 }
159 const magnitudeBytes = reader.buffer(length);
160 if (magnitudeBytes[length - 1] === 0) {
161 throw new Error(
162 "Non-canonical decimal magnitude bytes: trailing zero byte.",
163 );
164 }
165 const magnitude
166 = DecimalCodec.fromCanonicalLittleEndianMagnitude(magnitudeBytes);
167 if (magnitude === 0n) {
168 throw new Error("Big decimal encoding must not represent zero.");
169 }
170 return new Decimal((meta & 1n) === 0n ? magnitude : -magnitude, scale);
171}
172
173function pow10(exp: number): bigint {
174 let result = 1n;

Callers 1

readDecimalMethod · 0.85

Calls 6

NumberClass · 0.85
readVarInt32Method · 0.45
readVarUInt64Method · 0.45
decodeZigZag64Method · 0.45
bufferMethod · 0.45

Tested by

no test coverage detected