Skip to content

encodeKeyTuple(parts): Uint8Array

Defined in: packages/key-encoding/src/tuple.ts:219

Encode a composite key so that compareBytes orders encoded tuples lexicographically by part, each part in its own direction: the first part decides, the second breaks ties, and a tuple sorts before every longer tuple it is a prefix of.

Each part is a one-byte tag naming its kind and direction, then its payload: the fixed-width scalar encoding, or the escaped encoding for bytes and string. A descending part writes the bitwise complement of its ascending payload; because every payload is self-delimiting, that reverses its order exactly, including between byte strings of different lengths. Two tuples compare meaningfully only part by part over the same kinds, as in one index schema.

Runs in O(total payload bytes) and allocates the result once.

readonly KeyTuplePart[]

Uint8Array

INVALID_KEY_VALUE when parts is not an array, a part’s kind or direction is unknown, or its value is outside the kind’s domain, as the matching encode*Key would report.