Skip to main content

bool array Type

Information

  • Stores an array of true or false, but unlike [t.bool], it packs 8 boolean values into 1 byte. This is especially efficient for storing large arrays of boolean.
  • Requires 1 byte for every 8 values.
  • Use boolean[] for assignment.

Example Usage

index.ts
import { Serializer, t } from "encodexx"
const serializer = new Serializer({
matrix: [t.boolArr],
})
serializer.encode({
matrix: [
Array.from({ length: 1e7 }, () => Math.random() > 0.5),
Array.from({ length: 1e7 }, () => Math.random() > 0.5),
Array.from({ length: 1e7 }, () => Math.random() > 0.5),
],
});

Info

Unlike [t.bool], this encoding will take 8 times less space. For example, the above example takes 3,662 KB, while using [[t.bool]] would take 29,296 KB. In JSON format, such a matrix would take 161,000 KB.