a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto
bluesky
typescript
npm
@atcute/varint#
protobuf-style LEB128 varint codec.
npm install @atcute/varint
import { encode, decode, encodingLength } from '@atcute/varint';
// encoding
const encoded: number[] = [];
const bytesWritten = encode(420, encoded);
// -> encoded: [164, 3]
// -> bytesWritten: 2
// decoding
const { value, nextOffset } = decode(encoded);
// -> value: 420
// -> nextOffset: 2
// check encoding length beforehand
encodingLength(420); // -> 2
encodingLength(16383); // -> 2
encodingLength(16384); // -> 3