lt_rs/alerts/
protocol_version.rs

1/// BitTorrent version enumerator
2#[cfg_attr(feature = "safe_enums", derive(num_enum::FromPrimitive))]
3#[repr(u8)]
4pub enum ProtocolVersion {
5    /// The original BitTorrent version, using SHA-1 hashes
6    V1,
7    /// Version 2 of the BitTorrent protocol, using SHA-256 hashes
8    V2,
9    #[cfg(feature = "safe_enums")]
10    #[num_enum(default)]
11    Unknown,
12}
13
14impl ProtocolVersion {
15    pub(crate) fn from_u8(v: u8) -> Self {
16        cfg_if::cfg_if! {
17            if #[cfg(feature = "safe_enums")] {
18                v.into()
19            } else {
20                unsafe { std::mem::transmute(v) }
21            }
22        }
23    }
24}