Expand description
Zero-copy parsing of WhatsApp’s binary-node encoding.
wa-wire carries a stanza across the boundary exactly as the engine decoded
it — nothing is re-encoded, so the frame in an envelope is still in
WhatsApp’s own format. This crate is what turns that frame into something
navigable, host-side, and only when something actually asked for it.
§Nothing is copied
A NodeRef borrows the frame and re-walks it on demand; the encoding is
self-delimiting, so a node never needs to know where it ends. Tokens are
borrowed from the table. Raw payloads are sub-slices of the frame.
The two forms whose text exists nowhere in the buffer — packed digit runs and JIDs — stay in parts rather than being joined, and compare and render on demand:
// No allocation: the comparison walks the parts.
let is_text = node.attr_eq("type", "text");§The token table is a parameter
WhatsApp’s dictionaries move with the client version. Under RFC-009 that is a matter of provenance, not of contract version, so the table is passed in rather than compiled in. The bundled one is generated and committed, so a protocol change arrives as a reviewable diff.
use wa_wire_codec::{Parser, TokenTable, tokens};
let parser = Parser::new(tokens::TABLE); // the bundled table
let custom = Parser::new(TokenTable::new(&[], &[])); // or your own§Paths line up with envelopes
A plaintext entry in a wa-wire-contract envelope addresses its node by a
path of child indices. NodeRef::at_path walks exactly that path, which
is how a decrypted payload is matched back to the <enc> it came from.
§Validation
Parser::parse validates the entire tree, so every accessor on the result
is infallible. Malformed input is rejected up front and specifically enough
to tell a protocol change apart from corruption.
Re-exports§
pub use error::ParseError;pub use jid::Jid;pub use jid::User;pub use node::Attrs;pub use node::Children;pub use node::Content;pub use node::DEFAULT_MAX_DEPTH;pub use node::NodeRef;pub use node::Parser;pub use packed::Alphabet;pub use packed::Packed;pub use token::TokenTable;pub use value::Value;
Modules§
- error
- Parse failures.
- jid
- JIDs, kept in parts rather than joined.
- node
- Parsing a frame into a navigable node tree.
- packed
- Packed digit runs — nibble and hex.
- token
- Tag bytes and the token dictionaries they index into.
- tokens
- Bundled WhatsApp binary-protocol token dictionaries.
- value
- A decoded scalar, in whatever form the frame carried it.