From cbc111f90b5facc1f2a9dd79ced216279d6260af Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 19 Nov 2024 02:08:52 +0100 Subject: move files + rtp parser --- sip/src/encoding/method.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 sip/src/encoding/method.rs (limited to 'sip/src/encoding/method.rs') diff --git a/sip/src/encoding/method.rs b/sip/src/encoding/method.rs new file mode 100644 index 0000000..6d38cab --- /dev/null +++ b/sip/src/encoding/method.rs @@ -0,0 +1,39 @@ +use anyhow::bail; +use std::{fmt::Display, str::FromStr}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum Method { + Register, + Invite, + Ack, + Options, + Cancel, + Bye, +} + +impl Display for Method { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + Method::Register => "REGISTER", + Method::Invite => "INVITE", + Method::Ack => "ACK", + Method::Options => "OPTIONS", + Method::Cancel => "CANCEL", + Method::Bye => "BYE", + }) + } +} +impl FromStr for Method { + type Err = anyhow::Error; + fn from_str(s: &str) -> Result { + Ok(match s { + "REGISTER" => Method::Register, + "INVITE" => Method::Invite, + "ACK" => Method::Ack, + "OPTIONS" => Method::Options, + "CANCEL" => Method::Cancel, + "BYE" => Method::Bye, + _ => bail!("unknown method"), + }) + } +} -- cgit v1.2.3-70-g09d2