Expand description
§abx — Android Binary XML parser
Parses the ABX (Android Binary XML) format produced by BinaryXmlSerializer
and read back by BinaryXmlPullParser in AOSP.
Not to be confused with AXML, the unrelated chunk-based binary format
used for compiled resources inside APKs (AndroidManifest.xml,
res/**/*.xml) — this crate does not read that format. See the crate
README’s “Not AXML” section for the comparison.
§Two parsers, one format
| Parser | Input | When to use |
|---|---|---|
AbxParser | &[u8] | Data already in memory |
AbxStreamParser | impl Read | Files, sockets, pipes — any reader |
§Format overview
Every file starts with the 4-byte magic ABX\0 (0x41 0x42 0x58 0x00).
After the magic each token is a single byte split into two nibbles:
high nibble (0xF0) → data-type (TYPE_STRING, TYPE_INT, …)
low nibble (0x0F) → event kind (START_TAG, ATTRIBUTE, …)Interned strings are prefixed with a u16 index; the sentinel value
0xFFFF means “new string follows as a length-prefixed UTF-8 blob”.
§Quick start
// Slice-based
use abx::AbxParser;
let data = std::fs::read("foo.abx")?;
let mut p = AbxParser::new(&data)?;
while let Some(ev) = p.next_event()? { println!("{ev:?}"); }
// Stream-based (no intermediate Vec)
use abx::AbxStreamParser;
let file = std::fs::File::open("foo.abx")?;
let mut p = AbxStreamParser::new(std::io::BufReader::new(file))?;
while let Some(ev) = p.next_event()? { println!("{ev:?}"); }
// Convenience helper
let mut p = abx::open_file("foo.abx")?;
let xml = p.to_xml()?;§Crate layout
error, wire, event, decode (in-memory + streaming parsers, see
stream), and de (serde support, behind the serialize feature)
are internal modules — everything is re-exported at the crate root, so
abx::Event etc. work regardless of which file it’s defined in.
Modules§
- stream
AbxStreamParser— pull parser over anyReadsource.
Structs§
- AbxParser
- Zero-allocation pull parser that works on an in-memory
&[u8]. - AbxParser
Owned - Heap-owning wrapper. Stores the raw bytes and hands out
AbxParserborrows without lifetime gymnastics on the call-site. - AbxStream
Parser - Pull parser that reads from any
R: Readsource. - AbxWriter
- Encodes
Events to anyW: Writesink.Vec<u8>covers the in-memory case (it implementsWrite); a file/socket/BufWritercovers streaming — unlike the decode side, writing has no ring-buffer/refill complexity to split across two types. - Attribute
- One XML attribute: a name plus its typed value.
Enums§
- AbxError
- Everything that can go wrong parsing, encoding, or deserializing ABX data.
- Attribute
Value - The typed payload of an XML attribute.
- Event
- One
XmlPullParser-style parse event, as read from (or written to) an ABX stream.
Constants§
- MAGIC
- Magic header bytes:
ABX\0
Functions§
- abx_
events - Parse ABX bytes and return all events.
- abx_
to_ xml - Convert ABX bytes to an XML string.
- events_
to_ abx - Encode a full
Eventstream to an in-memory ABX byte buffer. - from_
element - Deserialize a single element’s attributes (and optional text content)
into
T, honoring#[serde(rename = "...")],Option<T>for absent attributes, and numeric/bytes coercions. This convenience entry point has no child elements to offer — it’s meant for callers who already have anEvent::StartTag’s attributes in hand. Nested-child mapping is only available throughcrate::AbxParser::deserialize_nextandcrate::AbxStreamParser::deserialize_next, which build the child tree by walking the event stream. - from_
file - Open a file and deserialize its root element into
T. - from_
reader - Streaming equivalent of
from_slice: deserialize the root element of an ABX document read from anystd::io::Readsource. - from_
slice - Deserialize an entire in-memory ABX document into
T, using its root element. The one-shot entry point for “this whole document is one struct” — no parser to construct, no element name to spell out. Matches quick-xml’sfrom_str/serde_json’sfrom_slice: the root’s tag name is not checked againstTat all, so name your types however you like. - open_
file - Open a file and return a buffered
AbxStreamParserover it. - xml_
to_ abx - Encode XML text to ABX bytes.
Type Aliases§
- Interned
Str - A tag or attribute name read from the wire format’s interned-string
pool. The same handful of names (
pkg,name,version, …) repeat across every element in a typical document, so back-reference clones need to be cheap. - Result
- This crate’s
Resultalias, withAbxErroras the error type.