Skip to content

Primitives & padding

Packed integers and IEEE floats. Multi-byte types honor the endian passed to c.read / c.write ("little" default, or "big").

Primitive types

cstructC type (<stdint.h> / <stddef.h>)SizeJavaScript
u8uint8_t1number
u16uint16_t2number
u32uint32_t4number
u64uint64_t8bigint
i8int8_t1number
i16int16_t2number
i32int32_t4number
i64int64_t8bigint
f32float4number
f64double8number

Use these names in @c.field("u32"), c.enum("i8", …), c.bitfield("u32", …), and anywhere else a storage primitive is required. c.sizeof("u32") returns the size column in bytes.

For a one-byte true/false slot (not a single-bit flag), see c.Bool() in Boolean — typically uint8_t or bool in C, not a row in this table.

Field padding

Insert zero bytes around a field with pad_before / pad_after:

ts
@c.struct()
class Header {
  @c.field("u16")
  magic!: number;

  @c.field("u32", { pad_before: 2, pad_after: 4 })
  length!: number;
}

Reserve bytes inside the layout with c.pad(n):

ts
@c.struct()
class Slot {
  @c.field("u8")
  tag!: number;

  @c.field(c.pad(3))
  private _reserved!: never;
}

This matches common game formats — for example a 4-byte film metadata slot with i32 + 12 reserved bytes (see Example structures).