Skip to main content

Crate android_abx

Crate android_abx 

Source
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

ParserInputWhen to use
AbxParser&[u8]Data already in memory
AbxStreamParserimpl ReadFiles, 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 android_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 android_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 = android_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 android_abx::Event etc. work regardless of which file it’s defined in.

Modules§

stream
AbxStreamParser — pull parser over any Read source.

Structs§

AbxParser
Zero-allocation pull parser that works on an in-memory &[u8].
AbxParserOwned
Heap-owning wrapper. Stores the raw bytes and hands out AbxParser borrows without lifetime gymnastics on the call-site.
AbxStreamParser
Pull parser that reads from any R: Read source.
AbxWriter
Encodes Events to any W: Write sink. Vec<u8> covers the in-memory case (it implements Write); a file/socket/BufWriter covers 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.
AttributeValue
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 Event stream 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 an Event::StartTag’s attributes in hand. Nested-child mapping is only available through crate::AbxParser::deserialize_next and crate::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 any std::io::Read source.
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’s from_str/serde_json’s from_slice: the root’s tag name is not checked against T at all, so name your types however you like.
open_file
Open a file and return a buffered AbxStreamParser over it.
xml_to_abx
Encode XML text to ABX bytes.

Type Aliases§

InternedStr
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 Result alias, with AbxError as the error type.