pub struct WireReader<'a> { /* private fields */ }Expand description
Decode a typed binary blob produced by WireWriter.
Implementations§
Source§impl<'a> WireReader<'a>
impl<'a> WireReader<'a>
Sourcepub fn new(
bytes: &'a [u8],
expected_magic: &[u8; 4],
expected_version: u32,
) -> Result<WireReader<'a>, EnvelopeError>
pub fn new( bytes: &'a [u8], expected_magic: &[u8; 4], expected_version: u32, ) -> Result<WireReader<'a>, EnvelopeError>
Begin a reader; validates the 8-byte magic + version header. Consumers MUST call this and propagate the error before reading any sections - sections after a bad header cannot be trusted.
§Errors
Returns EnvelopeError::Truncated for incomplete headers,
EnvelopeError::BadMagic for magic mismatches, or
EnvelopeError::VersionMismatch for stale/corrupt versions.
Sourcepub fn read_section(&mut self) -> Result<&'a [u8], EnvelopeError>
pub fn read_section(&mut self) -> Result<&'a [u8], EnvelopeError>
Read a length-prefixed byte section.
§Errors
Returns EnvelopeError::Truncated when the length prefix or section
bytes exceed the remaining input.
Sourcepub fn read_words(&mut self) -> Result<Vec<u32>, EnvelopeError>
pub fn read_words(&mut self) -> Result<Vec<u32>, EnvelopeError>
Read a length-prefixed u32 word array.
§Errors
Returns EnvelopeError::Truncated when the length prefix or encoded
words exceed the remaining input.
Sourcepub fn read_u32(&mut self) -> Result<u32, EnvelopeError>
pub fn read_u32(&mut self) -> Result<u32, EnvelopeError>
Read a single little-endian u32 (no length prefix).
§Errors
Returns EnvelopeError::Truncated when fewer than four bytes remain.