use super::Flags;
use bytes::Buf;
use std::error::Error as StdError;
use std::fmt;
pub trait Decode {
type Value;
fn decode<B: Buf>(
bytes: &mut B,
stream_id: u32,
flags: Flags,
) -> Result<Self::Value, DecodeError>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DecodeError {
InComplete,
UnrecognizedFrameType(u16),
InvalidStreamId {
expected: &'static str,
found: u32,
},
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use DecodeError::*;
match self {
InComplete => write!(f, "incomplete frame"),
UnrecognizedFrameType(v) => {
write!(f, "unrecognized frame type {0:#x}", v)
}
InvalidStreamId { expected, found } => write!(
f,
"invalid stream ID (expected {}, found {})",
expected, found
),
}
}
}
impl StdError for DecodeError {}