// world state snapshot
const Position = list(
quantized(-16, 16, { step: 0.01 }),
3,
);
const Entity = object({
id: uint16(),
position: Position, // 6 bytes
rotation: quat(), // 7 bytes
});
const WorldSchema = object({
frame: uint32(),
entities: list(Entity),
});
const { pack, unpack } = build(WorldSchema);
const bytes = pack(state); // → Uint8Array
const back = unpack(bytes); // → WorldState
JSON.stringify
–
packcat
–
– smaller
JSON
packcat
–
serialize
–
–
–
deserialize
–
–