Skip to content

Binary CodecTypeScript Binary Data Library

Lightweight utility with powerful type inference

Quick Preview

Experience the power of automatic type inference:

ts
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
);

Released under the MIT License.