use minicbor::{CborLen, Decode, Encode};
use ockam::tcp::TcpConnectionMode;
use std::fmt::{self, Display};
#[derive(Copy, Clone, Debug, Encode, Decode, CborLen, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
#[rustfmt::skip]
#[cbor(index_only)]
pub enum TransportType {
#[n(0)] Tcp,
#[n(1)] Ble,
#[n(2)] WebSocket,
}
impl Display for TransportType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Tcp => "TCP",
Self::Ble => "BLE",
Self::WebSocket => "Websocket",
})
}
}
#[derive(Copy, Clone, Debug, Encode, Decode, CborLen, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
#[rustfmt::skip]
pub enum TransportMode {
#[n(0)] Listen,
#[n(1)] Incoming,
#[n(2)] Outgoing,
}
impl From<TcpConnectionMode> for TransportMode {
fn from(value: TcpConnectionMode) -> Self {
match value {
TcpConnectionMode::Outgoing => Self::Outgoing,
TcpConnectionMode::Incoming => Self::Incoming,
}
}
}
impl Display for TransportMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Listen => "Listening",
Self::Incoming => "Incoming",
Self::Outgoing => "Outgoing",
})
}
}