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

Function encodeDecode

encoding/varint_test.ts:14–24  ·  view source on GitHub ↗
(i: number | bigint)

Source from the content-addressed store, hash-verified

12} from "./varint.ts";
13
14function encodeDecode(i: number | bigint) {
15 const [buf, n] = encodeVarint(i, new Uint8Array(MaxVarintLen64));
16 const fn = (typeof i === "bigint") ? decodeVarint : decodeVarint32;
17 const [j, m] = fn(buf);
18 assertEquals(i, j, `${fn.name}(encodeVarint(${i})): ${i} !== ${j}`);
19 assertEquals(
20 n,
21 m,
22 `${fn.name}(encodeVarint(${i})): buffer lengths ${n} !== ${m}`,
23 );
24}
25
26Deno.test("decodeVarint() handles empty buff", () => {
27 assertThrows(() => decodeVarint(Uint8Array.of()), RangeError);

Callers 1

varint_test.tsFile · 0.85

Calls 3

encodeVarintFunction · 0.90
assertEqualsFunction · 0.90
fnFunction · 0.70

Tested by

no test coverage detected