Ship a working HexPigeon: typed binary parsing in Rust/WASM, a three-pane frontend, and unit tests covering the field types. Co-authored-by: Cursor <cursoragent@cursor.com>
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
export const EXAMPLE_SCHEMA = JSON.stringify(
|
|
{
|
|
name: 'Example Frame',
|
|
endian: 'big',
|
|
fields: [
|
|
{
|
|
name: 'magic',
|
|
type: 'uint8',
|
|
description: 'Protocol magic byte (0xFF)',
|
|
},
|
|
{
|
|
name: 'payload_len',
|
|
type: 'uint8',
|
|
description: 'Length of payload string',
|
|
},
|
|
{
|
|
name: 'payload',
|
|
type: 'string_fixed',
|
|
length: 5,
|
|
description: 'Fixed-length ASCII payload',
|
|
},
|
|
{
|
|
name: 'raw_data',
|
|
type: 'bytes',
|
|
length: 4,
|
|
description: 'Raw 4-byte data blob',
|
|
},
|
|
{
|
|
name: 'tag',
|
|
type: 'string_fixed',
|
|
length: 4,
|
|
description: 'ASCII tag (ABCD)',
|
|
},
|
|
{
|
|
name: 'checksum',
|
|
type: 'crc32',
|
|
checksum_range: [0, 11],
|
|
description: 'CRC-32 over bytes 0-10',
|
|
},
|
|
{
|
|
name: 'flags',
|
|
type: 'bitflags16',
|
|
description: 'Status flags',
|
|
flags: [
|
|
{ bit: 0, name: 'ACK', description: 'Acknowledge' },
|
|
{ bit: 1, name: 'SYN', description: 'Synchronise' },
|
|
{ bit: 2, name: 'FIN', description: 'Finished' },
|
|
{ bit: 7, name: 'ERR', description: 'Error' },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
null,
|
|
2,
|
|
)
|
|
|
|
/** Example frame with valid CRC-32 (ISO HDLC) over bytes 0-10 and flags ACK|SYN. */
|
|
export const EXAMPLE_HEX = [
|
|
'FF 05 48 65 6C 6C 6F',
|
|
'00 01 02 03',
|
|
'41 42 43 44',
|
|
'E8 6B B6 E1',
|
|
'00 03',
|
|
].join('\n')
|