wtx 0.43.0

A collection of different transport implementations and related tools focused primarily on web technologies.
Documentation
use crate::{
  codec::Decode,
  database::client::mysql::{
    MysqlError,
    protocol::{Protocol, decode_wrapper_protocol::DecodeWrapperProtocol, lenenc::Lenenc},
  },
  misc::Usize,
};

pub(crate) struct LenencContent<'bytes>(pub(crate) &'bytes [u8]);

impl<'de, DO, E> Decode<'de, Protocol<DO, E>> for LenencContent<'de>
where
  E: From<crate::Error>,
{
  #[inline]
  fn decode(dw: &mut DecodeWrapperProtocol<'de, '_, DO>) -> Result<Self, E> {
    let len = Lenenc::decode(dw)?;
    let Some((lhs, rhs)) = dw.bytes.split_at_checked(*Usize::from(len.0)) else {
      return Err(E::from(MysqlError::InvalidLenencContentBytes.into()));
    };
    *dw.bytes = rhs;
    Ok(Self(lhs))
  }
}