MCPcopy Create free account
hub / github.com/denoland/std / decodeFour

Function decodeFour

cbor/_common_decode.ts:175–205  ·  view source on GitHub ↗
(
  input: Uint8Array,
  aI: number,
  offset: number,
)

Source from the content-addressed store, hash-verified

173}
174
175function decodeFour(
176 input: Uint8Array,
177 aI: number,
178 offset: number,
179): [CborType[], number] {
180 if (aI <= 27) {
181 const x = calcLength(input, aI, offset);
182 // Can safely assume `x[0] < 2 ** 53` as JavaScript doesn't support an `Array` being that large.
183 const length = Number(x[0]);
184 offset = x[1];
185 const output: CborType[] = new Array(length);
186 for (let i = 0; i < length; ++i) {
187 const y = decode(input, offset);
188 output[i] = y[0];
189 offset = y[1];
190 }
191 return [output, offset];
192 }
193 if (aI === 31) {
194 const output: CborType[] = [];
195 while (input[offset] !== 0b111_11111) {
196 const x = decode(input, offset);
197 output.push(x[0]);
198 offset = x[1];
199 }
200 return [output, offset + 1];
201 }
202 throw new RangeError(
203 `Cannot decode value (0b100_${aI.toString(2).padStart(5, "0")})`,
204 );
205}
206
207function decodeFive(
208 input: Uint8Array,

Callers 1

decodeFunction · 0.85

Calls 4

calcLengthFunction · 0.85
decodeFunction · 0.70
pushMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected