/** * Typed state codecs — the foundation of the World Stores layer. * * Every opaque base64 blob on the platform (actor replication `state`, voxel * `voxelState`, chunk `chunkState`, client event `state`, channel/actor * message `payload`, `UserAppState.state`, avatar public/private/app state) * is app-defined. A {@link StateCodec} names that definition ONCE: the dev * registers their custom type + encoder/decoder with a store, and the store * speaks typed values everywhere else. */ /** * A two-way codec between a typed value and the platform's base64 wire form. * Implement your own, or build one with {@link jsonCodec} (compact JSON), * {@link rawCodec} (pass-through base64), or {@link structCodec} (fixed-layout * binary — the right choice for high-rate replication state). */ export interface StateCodec { /** Encode a typed value into the base64 wire form. */ encode(value: T): string; /** Decode the base64 wire form back into the typed value. */ decode(data: string): T; } /** * JSON codec: `JSON.stringify` → UTF-8 → base64. Convenient for low-rate, * structured state (save blobs, avatar profiles, channel payloads). Do NOT * use it for per-tick actor replication — spatial packets have a ~1.1 KB * budget and JSON wastes most of it; use {@link structCodec} there. */ export declare function jsonCodec(): StateCodec; /** * Identity codec: the typed value IS the base64 string. Use it when the app * already has its own encoding pipeline and just wants the stores' lifecycle * management. */ export declare const rawCodec: StateCodec; /** * UTF-8 text codec: plain strings ↔ base64 (chat payloads, simple messages). */ export declare const textCodec: StateCodec; /** * One field of a {@link structCodec} layout. Build fields with the factory * helpers ({@link f32}, {@link u8}, …) rather than by hand. */ export interface StructField { /** Bytes this field occupies. */ size: number; read(view: DataView, offset: number, littleEndian: boolean): V; write(view: DataView, offset: number, value: V, littleEndian: boolean): void; /** True for {@link reserved} padding — excluded from the value type. */ skip?: boolean; } /** A struct layout: ordered named fields (insertion order = byte order). */ export type StructSpec = Record>; /** The typed value a {@link StructSpec} encodes (reserved fields omitted). */ export type StructValue = { [K in keyof S as S[K]['skip'] extends true ? never : K]: S[K] extends StructField ? V : never; }; /** 32-bit float field. */ export declare function f32(): StructField; /** 64-bit float field (e.g. epoch-milliseconds timestamps). */ export declare function f64(): StructField; /** Unsigned 8-bit int field (flags, small ids). */ export declare function u8(): StructField; /** Unsigned 16-bit int field. */ export declare function u16(): StructField; /** Unsigned 32-bit int field. */ export declare function u32(): StructField; /** Signed 8-bit int field. */ export declare function i8(): StructField; /** Signed 16-bit int field. */ export declare function i16(): StructField; /** Signed 32-bit int field. */ export declare function i32(): StructField; /** Boolean stored as one byte (0/1). */ export declare function bool8(): StructField; /** Fixed-length raw bytes field. */ export declare function bytes(length: number): StructField; /** Reserved padding bytes — occupies layout space, absent from the value type. */ export declare function reserved(length: number): StructField & { skip: true; }; /** A {@link StateCodec} produced by {@link structCodec}, exposing its byte size. */ export interface StructCodec extends StateCodec { /** The fixed encoded size in bytes (before base64). */ readonly byteLength: number; } /** * Build a fixed-layout binary codec from a declarative field spec — the * replication-state workhorse. Fields are laid out in declaration order, * little-endian by default (matching the platform's wire conventions). * * The Blocks-with-Friends 48-byte pose, declaratively: * * ```ts * const poseCodec = structCodec({ * x: f32(), y: f32(), z: f32(), * yaw: f32(), pitch: f32(), * vx: f32(), vy: f32(), vz: f32(), * flags: u8(), heldBlockId: u8(), _r0: reserved(2), * updatedAt: f64(), _r1: reserved(4), * }); // poseCodec.byteLength === 48 * ``` * * @throws {Error} at decode time when the payload is shorter than the layout. */ export declare function structCodec(spec: S, options?: { littleEndian?: boolean; }): StructCodec>; //# sourceMappingURL=codec.d.ts.map