Skip to content

Arrays and Tuples

Arrays

The items are encoded right next to each other. No need to store length information, as that is constant (built into the schema).

const Vector2 = bin.arrayOf(bin.f32, 2);
const Vector3 = bin.arrayOf(bin.f32, 3);
const Vector4 = bin.arrayOf(bin.f32, 4);
type Vector2 = bin.Parsed<typeof Vector2>; // number[]
type Vector3 = bin.Parsed<typeof Vector3>; // number[]
type Vector4 = bin.Parsed<typeof Vector4>; // number[]

Dynamic Arrays

First 4 bytes of encoding are the length of the array, then its items next to one another.

const IntArray = bin.dynamicArrayOf(bin.i32);
type IntArray = bin.Parsed<typeof IntArray>; // number[]

Tuple

Encodes an ordered set of schemas, one next to another.

const Vec3f = bin.tupleOf([bin.f32, bin.f32, bin.f32]);
type Vec3f = bin.Parsed<typeof Vec3f>; // [number, number, number]
const RecordEntry = bin.tupleOf([bin.string, Vec3f]);
type RecordEntry = bin.Parsed<typeof RecordEntry>; // [string, [number, number, number]]