diff options
Diffstat (limited to 'src/encoding/mod.rs')
-rw-r--r-- | src/encoding/mod.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/encoding/mod.rs b/src/encoding/mod.rs index a7dd227..f0796c8 100644 --- a/src/encoding/mod.rs +++ b/src/encoding/mod.rs @@ -1,3 +1,8 @@ +use std::{fmt::Display, str::FromStr}; + +use request::Request; +use response::Response; + pub mod headermap; pub mod headers; pub mod method; @@ -5,3 +10,28 @@ pub mod request; pub mod response; pub mod status; pub mod uri; + +#[derive(Debug, Clone)] +pub enum Message { + Request(Request), + Response(Response), +} + +impl Display for Message { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Message::Request(r) => write!(f, "{r}"), + Message::Response(r) => write!(f, "{r}"), + } + } +} +impl FromStr for Message { + type Err = anyhow::Error; + fn from_str(s: &str) -> Result<Self, Self::Err> { + if s.starts_with("SIP/") { + Response::from_str(s).map(Message::Response) + } else { + Request::from_str(s).map(Message::Request) + } + } +} |