std/encoding/varint.ts

Deno standard library
Go to Latest
import * as mod from "https://deno.land/std@0.145.0/encoding/varint.ts";

Functions

Decodes the given Uint8Array into a number with LEB128.

import { decodeU32 } from "./varint.ts";
const bytes = Uint8Array.from([221, 199, 1]);
const decodedValue = decodeU32(bytes);

Decodes the given Uint8Array into a BigInt with LEB128.

import { decodeU64 } from "./varint.ts";
const bytes = Uint8Array.from([221, 199, 1]);
const decodedValue = decodeU64(bytes);

Encodes the given number into Uint8Array with LEB128. The number needs to be in the range of 0 and 0xffffffff.

import { encodeU32 } from "./varint.ts";

Encodes the given BigInt into Uint8Array with LEB128. The number needs to be in the range of 0 and 0xffffffffffffffff.

import { encodeU64 } from "./varint.ts";