Skip to main content

abx/
wire.rs

1//! Wire-format protocol constants (mirrors AOSP's `BinaryXmlSerializer.java`
2//! exactly — see `CLAUDE.md`'s "FIXED" section for how the `TYPE_*` values
3//! were verified). Shared by both parsers (`src/parser.rs`, `src/stream.rs`).
4
5/// Magic header bytes: `ABX\0`
6pub const MAGIC: [u8; 4] = [0x41, 0x42, 0x58, 0x00];
7
8/// Sentinel in the interned-string index that signals a new string.
9pub(crate) const INTERNED_NEW: u16 = 0xFFFF;
10
11// Token command (low nibble)
12pub(crate) const CMD_START_DOCUMENT: u8 = 0x00;
13pub(crate) const CMD_END_DOCUMENT: u8 = 0x01;
14pub(crate) const CMD_START_TAG: u8 = 0x02;
15pub(crate) const CMD_END_TAG: u8 = 0x03;
16pub(crate) const CMD_TEXT: u8 = 0x04;
17pub(crate) const CMD_CDSECT: u8 = 0x05;
18pub(crate) const CMD_ENTITY_REF: u8 = 0x06;
19pub(crate) const CMD_IGNORABLE_WHITESPACE: u8 = 0x07;
20pub(crate) const CMD_PROCESSING_INSTRUCTION: u8 = 0x08;
21pub(crate) const CMD_COMMENT: u8 = 0x09;
22pub(crate) const CMD_DOCDECL: u8 = 0x0A;
23pub(crate) const CMD_ATTRIBUTE: u8 = 0x0F;
24
25// Data type (high nibble). Values match AOSP's BinaryXmlSerializer.java
26// exactly: `n << 4` for n = 1..=13 (high-nibble 0x00 is never used on the
27// wire — every token always OR's in an explicit type flag, even the
28// "absent value" case, TYPE_NULL).
29pub(crate) const TYPE_NULL: u8 = 0x10;
30pub(crate) const TYPE_STRING: u8 = 0x20;
31pub(crate) const TYPE_STRING_INTERNED: u8 = 0x30;
32pub(crate) const TYPE_BYTES_HEX: u8 = 0x40;
33pub(crate) const TYPE_BYTES_BASE64: u8 = 0x50;
34pub(crate) const TYPE_INT: u8 = 0x60;
35pub(crate) const TYPE_INT_HEX: u8 = 0x70;
36pub(crate) const TYPE_LONG: u8 = 0x80;
37pub(crate) const TYPE_LONG_HEX: u8 = 0x90;
38pub(crate) const TYPE_FLOAT: u8 = 0xA0;
39pub(crate) const TYPE_DOUBLE: u8 = 0xB0;
40pub(crate) const TYPE_BOOLEAN_TRUE: u8 = 0xC0;
41pub(crate) const TYPE_BOOLEAN_FALSE: u8 = 0xD0;