Skip to content

Petrichor.Bits#

require("Petrichor.Bits") implements 6-bit ASCII bit packing. Mods use it for compact settings strings and other binary payloads that need to survive copy and paste.

API#

Function Description
Bits.CHARSET 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_
Bits.toBits(n, width) Integer to zero-padded binary string
Bits.encode(bitString) Binary string → 6-bit ASCII
Bits.decode(encoded) 6-bit ASCII → binary string
Bits.decodeInt(encoded) Single encoded character(s) → integer
Bits.newProcessor(bits) Stateful reader with :nextInt(n), :nextBool(), :remaining()
local Bits = require("Petrichor.Bits")

local packed = Bits.encode("101100")
local bits = Bits.decode(packed)

local proc = Bits.newProcessor("01011")
local flag = proc:nextBool()
local value = proc:nextInt(4)
import * as Bits from "Petrichor.Bits"

const packed = Bits.encode("101100")
const bits = Bits.decode(packed)

const proc = Bits.newProcessor("01011")
const flag = proc.nextBool()
const value = proc.nextInt(4)

Field layouts for a specific mod stay in that mod. This module only handles the shared encode and decode primitives.