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

Function calcLength

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

Source from the content-addressed store, hash-verified

5import type { CborType } from "./types.ts";
6
7function calcLength(
8 input: Uint8Array,
9 aI: number,
10 offset: number,
11): [number | bigint, number] {
12 if (aI < 24) return [aI, offset];
13 const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
14 switch (aI) {
15 case 24:
16 return [view.getUint8(offset), offset + 1];
17 case 25:
18 return [view.getUint16(offset), offset + 2];
19 case 26:
20 return [view.getUint32(offset), offset + 4];
21 default: // Only possible for it to be 27
22 return [view.getBigUint64(offset), offset + 8];
23 }
24}
25
26export function decode(input: Uint8Array, offset: number): [CborType, number] {
27 const byte = input[offset++];

Callers 7

decodeZeroFunction · 0.85
decodeOneFunction · 0.85
decodeTwoFunction · 0.85
decodeThreeFunction · 0.85
decodeFourFunction · 0.85
decodeFiveFunction · 0.85
decodeMapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected