🚀 Type-Safe
Full TypeScript support with automatic type inference from your specifications
Lightweight utility with powerful type inference
Experience the power of automatic type inference:
import type { CodecSpec, Infer } from 'binary-codec';
import { deserialize } from 'binary-codec';
const packetSpec = {
byteLength: 6,
fields: [
{
name: 'status',
type: 'number',
numberType: 'uint',
byteOffset: 0,
byteLength: 1
},
{
name: 'message',
type: 'string',
byteOffset: 1,
byteLength: 5
}
]
} as const satisfies CodecSpec;
// ✨ Hover over PacketType to see the inferred type
type PacketType = Infer<typeof packetSpec>;
const buffer = new Uint8Array(6);
// Hover over result to see the automatically inferred return type
const result = deserialize(packetSpec, buffer);