MCPcopy Create free account
hub / github.com/denoland/std / #decodeTwo

Method #decodeTwo

cbor/sequence_decoder_stream.ts:264–303  ·  view source on GitHub ↗
(
    aI: number,
  )

Source from the content-addressed store, hash-verified

262 }
263
264 async #decodeTwo(
265 aI: number,
266 ): Promise<Uint8Array | [CborByteDecodedStream, lock: Promise<unknown>]> {
267 if (aI < 24) return await this.#read(aI, true);
268 if (aI <= 27) {
269 const bytes = arrayToNumber(
270 (await this.#read(2 ** (aI - 24), true)).buffer,
271 true,
272 );
273 if (typeof bytes === "bigint") {
274 let releaseLock: ReleaseLock = () => {};
275 const lock = new Promise((x) => releaseLock = x);
276 return [
277 new CborByteDecodedStream(this.#readGen(bytes), releaseLock),
278 lock,
279 ];
280 } else return await this.#read(bytes, true);
281 }
282 if (aI === 31) {
283 let releaseLock: ReleaseLock = () => {};
284 const lock = new Promise((x) => releaseLock = x);
285 return [
286 new CborByteDecodedStream(
287 async function* (gen) {
288 for await (const x of gen) {
289 if (x instanceof Uint8Array) yield x;
290 else if (x instanceof CborByteDecodedStream) {
291 for await (const y of x) yield y;
292 } else throw new TypeError("Unexpected type in CBOR byte string");
293 }
294 }(this.#readIndefinite(true, "")),
295 releaseLock,
296 ),
297 lock,
298 ];
299 }
300 throw new RangeError(
301 `Cannot decode value (0b010_${aI.toString(2).padStart(5, "0")})`,
302 );
303 }
304
305 async #decodeThree(
306 aI: number,

Callers 1

#decodeMethod · 0.95

Calls 5

#readMethod · 0.95
#readGenMethod · 0.95
#readIndefiniteMethod · 0.95
arrayToNumberFunction · 0.90
toStringMethod · 0.45

Tested by

no test coverage detected