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

Function decodeSix

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

Source from the content-addressed store, hash-verified

263}
264
265function decodeSix(
266 input: Uint8Array,
267 aI: number,
268 offset: number,
269): [Date | bigint | Map<CborType, CborType> | CborTag<CborType>, number] {
270 if (aI > 27) {
271 throw new RangeError(
272 `Cannot decode value (0b110_${aI.toString(2).padStart(5, "0")})`,
273 );
274 }
275 const x = decodeZero(input, aI, offset);
276 switch (BigInt(x[0])) {
277 case 0n: {
278 const y = decode(input, x[1]);
279 if (typeof y[0] !== "string") {
280 throw new TypeError('Invalid TagItem: Expected a "text string"');
281 }
282 return [new Date(y[0]), y[1]];
283 }
284 case 1n: {
285 const y = decode(input, x[1]);
286 if (typeof y[0] !== "number" && typeof y[0] !== "bigint") {
287 throw new TypeError('Invalid TagItem: Expected a "integer" or "float"');
288 }
289 return [new Date(Number(y[0]) * 1000), y[1]];
290 }
291 case 2n: {
292 const y = decode(input, x[1]);
293 if (!(y[0] instanceof Uint8Array)) {
294 throw new TypeError('Invalid TagItem: Expected a "byte string"');
295 }
296 let z = 0n;
297 for (const byte of y[0]) z = (z << 8n) | BigInt(byte);
298 return [z, y[1]];
299 }
300 case 3n: {
301 const y = decode(input, x[1]);
302 if (!(y[0] instanceof Uint8Array)) {
303 throw new TypeError('Invalid TagItem: Expected a "byte string"');
304 }
305 let z = 0n;
306 for (const byte of y[0]) z = (z << 8n) | BigInt(byte);
307 return [-z - 1n, y[1]];
308 }
309 case 259n:
310 return decodeMap(input, x[1]);
311 default: {
312 const y = decode(input, x[1]);
313 return [new CborTag(x[0], y[0]), y[1]];
314 }
315 }
316}
317
318function decodeSeven(
319 input: Uint8Array,

Callers 1

decodeFunction · 0.85

Calls 4

decodeZeroFunction · 0.85
decodeFunction · 0.70
decodeMapFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected