saluki_io/deser/framing/mod.rs
1use snafu::Snafu;
2
3/// Framing error.
4#[derive(Debug, Snafu, Eq, PartialEq)]
5#[snafu(context(suffix(false)))]
6pub enum FramingError {
7 /// An invalid frame was received.
8 ///
9 /// This generally occurs if the frame is corrupted in some way, due to a bug in how the frame was encoded or
10 /// sent/received. For example, if a length-delimited frame indicates that the frame is larger than the buffer can
11 /// handle, it generally indicates that frame was created incorrectly by not respecting the maximum frame length
12 /// limitations, or the buffer is corrupt and spurious bytes are contributing to a decoded frame length that's
13 /// nonsensical.
14 #[snafu(display("invalid frame (frame length: {}, {})", frame_len, reason))]
15 InvalidFrame { frame_len: usize, reason: &'static str },
16
17 /// Failed to read frame due to a partial frame after reaching EOF.
18 ///
19 /// This generally only occurs if the peer closes their connection before sending the entire frame, or if a partial
20 /// write occurs on a connectionless stream, such as UDP, perhaps due to fragmentation.
21 #[snafu(display(
22 "partial frame after EOF (needed {} bytes, but only {} bytes remaining)",
23 needed,
24 remaining
25 ))]
26 PartialFrame { needed: usize, remaining: usize },
27}