aboutsummaryrefslogtreecommitdiff
path: root/sip/src/encoding/method.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sip/src/encoding/method.rs')
-rw-r--r--sip/src/encoding/method.rs39
1 files changed, 39 insertions, 0 deletions
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<Self, Self::Err> {
+ Ok(match s {
+ "REGISTER" => Method::Register,
+ "INVITE" => Method::Invite,
+ "ACK" => Method::Ack,
+ "OPTIONS" => Method::Options,
+ "CANCEL" => Method::Cancel,
+ "BYE" => Method::Bye,
+ _ => bail!("unknown method"),
+ })
+ }
+}