#[non_exhaustive]pub enum DecodeError {
BadMagic,
VersionMismatch {
supported: u8,
received: u8,
},
UnknownMessageType(u8),
UnknownDurability(u8),
HeaderCrcMismatch {
expected: u32,
computed: u32,
},
PayloadCrcMismatch {
expected: u32,
computed: u32,
},
TruncatedFrame,
PayloadTooLarge {
len: usize,
cap: usize,
},
ReservedFlagsSet {
flags: u8,
},
TrailingBytes {
extra: usize,
},
}Expand description
All errors that can occur when decoding a weir wire frame.
Each variant identifies a specific frame-validation failure, and the daemon
maps it to a distinct Nack reason byte: VersionMismatch is kept separate from
BadMagic and HeaderCrcMismatch so the daemon can return its WIRE_VERSION
in the Nack payload. The variants are NOT declared in strict decode order — the
decoder validates magic → version → header CRC → message_type / durability →
payload fields (so e.g. UnknownMessageType only arises on an
already-CRC-valid header). Match on the variant, never on its position.
#[non_exhaustive]: the decode taxonomy is expected to grow (wire v1 already
gained ReservedFlagsSet and TrailingBytes during the 1.0 hardening), so
downstream matches must include a wildcard arm and adding a variant later is
not a breaking change.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
BadMagic
First four bytes are not b"WEIR". Not a weir frame or stream is desynced.
VersionMismatch
Version byte does not equal WIRE_VERSION. Carries both sides for error messaging.
Checked before header CRC so a version-mismatched frame from a newer client gets
VersionMismatch, not a confusing HeaderCrcMismatch.
Fields
UnknownMessageType(u8)
Message type byte has no known variant.
UnknownDurability(u8)
Durability byte has no known variant.
HeaderCrcMismatch
Header CRC32 (bytes [12..16]) does not match CRC of bytes [0..12].
PayloadCrcMismatch
Payload CRC32 (trailing 4 bytes) does not match CRC of the payload bytes.
Fields
TruncatedFrame
Buffer is shorter than the declared frame length.
PayloadTooLarge
payload_len exceeds the hard cap. Rejection happens before any heap allocation.
ReservedFlagsSet
The reserved flags byte was nonzero. In wire v1 flags must be zero; a
daemon rejects a frame that sets any flag bit rather than silently
ignoring it (F52). Carries the offending byte.
TrailingBytes
The buffer was longer than the single frame it declared. Envelope::decode
requires its input to be exactly one frame (HEADER_LEN + payload_len + 4
bytes): a longer buffer is rejected rather than decoding the first frame and
silently discarding the remainder, so the caller — not the codec — owns
framing and an over-long buffer surfaces as an error, not lost data (G18).
Trait Implementations§
Source§impl Debug for DecodeError
impl Debug for DecodeError
Source§impl Display for DecodeError
impl Display for DecodeError
impl Eq for DecodeError
Source§impl Error for DecodeError
impl Error for DecodeError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()