Skip to main content

Crate wa_wire_proto

Crate wa_wire_proto 

Source
Expand description

Zero-copy reader for the protobuf wire format.

The sibling of wa-wire-codec. That one parses the stanza; this one parses what the stanza’s <enc> children decrypt to, which is where every message body lives. Same rules: no_std, no dependencies, borrowing from the buffer rather than copying out of it.

use wa_wire_proto::{Reader, Value};

// field 1, length-delimited, "hi"
let buf = [0x0a, 0x02, b'h', b'i'];
let text = Reader::new(&buf)
    .find_last(1)?
    .and_then(Value::as_str);
assert_eq!(text, Some("hi"));

§What it does not do

It does not know any schema. A field is a number and some bytes, and what those mean is the caller’s business. That is deliberate: the payloads here come from a protocol that adds fields without asking, and a reader that refused an unknown field would fail on exactly the traffic worth looking at.

§Totality

Every byte sequence either yields fields or a reportable error, and no sequence panics. Once a read fails the reader stops, so a caller looping over Reader::next cannot spin on the same bad byte.

Structs§

Field
One field: its number and its value.
Reader
Walks a payload, one field at a time.

Enums§

Error
Why a payload could not be read.
Value
One field’s value, borrowed from the payload.