fire_stream/packet/
mod.rs1mod bytes;
2pub use self::bytes::*;
3
4mod body_bytes;
5pub use body_bytes::*;
6
7mod packet;
8pub use packet::*;
9
10#[cfg(test)]
11pub mod test;
12
13#[cfg(feature = "encrypted")]
14mod encrypted_bytes;
15#[cfg(feature = "encrypted")]
16#[cfg_attr(docsrs, doc(cfg(feature = "encrypted")))]
17pub use encrypted_bytes::*;
18
19#[cfg(feature = "connection")]
20pub(crate) mod builder;
21
22pub type Result<T> = std::result::Result<T, PacketError>;
23
24use std::fmt;
25use std::borrow::Cow;
26
27
28#[derive(Debug)]
29#[non_exhaustive]
30pub enum PacketError {
31 Header(Cow<'static, str>),
32 Body(Cow<'static, str>),
33 #[cfg(feature = "json")]
34 #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
35 Json(serde_json::Error),
36 #[cfg(feature = "fs")]
37 #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
38 Io(std::io::Error),
39 BodyLimitReached(u32),
41 #[cfg(feature = "encrypted")]
42 #[cfg_attr(docsrs, doc(cfg(feature = "encrypted")))]
43 MacNotEqual
44}
45
46impl fmt::Display for PacketError {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 match self {
49 Self::Header(s) => write!(f, "PacketError::Header: {}", s),
50 Self::Body(s) => write!(f, "PacketError::Body: {}", s),
51 #[cfg(feature = "json")]
52 Self::Json(s) => write!(f, "PacketError::Json: {}", s),
53 #[cfg(feature = "fs")]
54 Self::Io(s) => write!(f, "PacketError::Io: {}", s),
55 Self::BodyLimitReached(s) => {
56 write!(f, "PacketError::BodyLimitReached: {}", s)
57 },
58 #[cfg(feature = "encrypted")]
59 Self::MacNotEqual => write!(f, "PacketError::MacNotEqual")
60 }
61 }
62}
63
64#[cfg(feature = "json")]
65impl From<serde_json::Error> for PacketError {
66 fn from(e: serde_json::Error) -> Self {
67 Self::Json(e)
68 }
69}
70
71#[cfg(feature = "fs")]
72impl From<std::io::Error> for PacketError {
73 fn from(e: std::io::Error) -> Self {
74 Self::Io(e)
75 }
76}