struct(schema) compiles the schema tree once and reuses the compiled codec across calls — prefer it in hot paths.
Errors
Validation throws DataStructError with a code:
Code
When
VALUE_OUT_OF_RANGE
Numeric value outside the leaf's range or non-int
STRING_TOO_LONG
UTF-8 byte length exceeds 65535
BYTES_TOO_LONG
Bytes value exceeds the leaf's length cap
ARRAY_TOO_LONG
Array length exceeds 65535
BUFFER_UNDERFLOW
Decode would read past the end of the input
SCHEMA_MISMATCH
Value shape does not match the schema
INVALID_SCHEMA
Schema itself is malformed
Every error carries path (e.g. $.skills[1].description) and, for decode errors, offset.
Wire format
bool : 1 byte 0x00 = false, anything else = truei8/u8 : 1 bytei16/u16 : 2 bytes BEi32/u32 : 4 bytes BEf32/f64 : 4 / 8 bytes BEi64/u64 : 8 bytes BEstring : uint16 BE length || utf-8 bytesshortBytes : uint16 BE length || raw bytesbytes : uint32 BE length || raw bytesarray [E] : uint16 BE length || N encoded elementsobject {…} : fields encoded in declared key order, no header
LE variants (t.le.*) swap the byte order of length prefixes and the numeric payload.
Migration from 0.0.x
The 0.1.0 release is a full rewrite with a new API surface. The wire format is preserved, so buffers produced by older versions decode correctly under the new codecs.
Old
New
DataTypes.boolean
t.bool
DataTypes.int8 / uint8
t.i8 / t.u8
DataTypes.int16/uint16
t.i16 / t.u16
DataTypes.int32/uint32
t.i32 / t.u32
DataTypes.float
t.f32
DataTypes.double
t.f64
DataTypes.string
t.string
DataTypes.shortBuffer
t.shortBytes
DataTypes.buffer
t.bytes
The legacy DataTypes / DataReader / DataWriter exports are removed.
Development
npm installnpm run typechecknpm run lintnpm testnpm run benchnpm run build