use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Encode, Decode)]
pub enum Protocol {
Tcp,
Udp,
Http,
Http2,
Ws, Custom(String), }
impl Protocol {
pub fn as_str(&self) -> &str {
match self {
Protocol::Tcp => "tcp",
Protocol::Udp => "udp",
Protocol::Http => "http",
Protocol::Http2 => "http2",
Protocol::Ws => "ws",
Protocol::Custom(s) => s.as_str(),
}
}
}
impl From<&str> for Protocol {
fn from(s: &str) -> Self {
match s.to_lowercase().as_str() {
"tcp" => Protocol::Tcp,
"udp" => Protocol::Udp,
"http" => Protocol::Http,
"http2" => Protocol::Http2,
"ws" => Protocol::Ws,
other => Protocol::Custom(other.to_string()),
}
}
}