wtx 0.50.0

A collection of different transport implementations and related tools focused primarily on web technologies.
Documentation
use crate::{
  codec::{Decode, Encode},
  tls::{de::De, tls_decode_wrapper::TlsDecodeWrapper, tls_encode_wrapper::TlsEncodeWrapper},
};

create_enum! {
  #[derive(Clone, Copy, Debug, Eq, PartialEq)]
  /// TLS version
  pub enum ProtocolVersion<u16> {
    /// TLS 1.0
    Tls1 = (0x0301),
    /// TLS 1.1
    Tls11 = (0x0302),
    /// TLS 1.2
    Tls12 = (0x0303),
    /// TLS 1.3
    Tls13 = (0x0304)
  }
}

impl<'de> Decode<'de, De> for ProtocolVersion {
  #[inline]
  fn decode(dw: &mut TlsDecodeWrapper<'de>) -> crate::Result<Self> {
    Self::try_from(<u16 as Decode<De>>::decode(dw)?)
  }
}

impl Encode<De> for ProtocolVersion {
  #[inline]
  fn encode(&self, ew: &mut TlsEncodeWrapper<'_>) -> crate::Result<()> {
    ew.buffer().extend_from_copyable_slice(&u16::from(*self).to_be_bytes())?;
    Ok(())
  }
}