Skip to main content
Module

std/encoding/varint.ts

The Deno Standard Library
Latest
import * as mod from "https://deno.land/std@0.222.1/encoding/varint.ts";

Functions for encoding typed integers in array buffers.

import { encode, decode } from "https://deno.land/std@0.222.1/encoding/varint.ts";

const buf = new Uint8Array(10);
const [encoded, bytesWritten] = encode(42n, buf);
// [ Uint8Array(1) [ 42 ], 1 ];

decode(encoded); // [ 42n, 1 ];

Variables

Functions for encoding typed integers in array buffers.

Functions

f
decode
deprecated

Given a non empty buf, starting at offset (default: 0), begin decoding bytes as VarInt encoded bytes, for a maximum of 10 bytes (offset + 10). The returned tuple is of the decoded varint 32-bit number, and the new offset with which to continue decoding other data.

f
decode32
deprecated

Given a buf, starting at offset (default: 0), begin decoding bytes as VarInt encoded bytes, for a maximum of 5 bytes (offset + 5). The returned tuple is of the decoded varint 32-bit number, and the new offset with which to continue decoding other data.

Given a non empty buf, starting at offset (default: 0), begin decoding bytes as VarInt encoded bytes, for a maximum of 10 bytes (offset + 10). The returned tuple is of the decoded varint 32-bit number, and the new offset with which to continue decoding other data.

Given a buf, starting at offset (default: 0), begin decoding bytes as VarInt encoded bytes, for a maximum of 5 bytes (offset + 5). The returned tuple is of the decoded varint 32-bit number, and the new offset with which to continue decoding other data.

f
encode
deprecated

Takes unsigned number num and converts it into a VarInt encoded Uint8Array, returning a tuple consisting of a Uint8Array slice of the encoded VarInt, and an offset where the VarInt encoded bytes end within the Uint8Array.

Takes unsigned number num and converts it into a VarInt encoded Uint8Array, returning a tuple consisting of a Uint8Array slice of the encoded VarInt, and an offset where the VarInt encoded bytes end within the Uint8Array.