fix warning

This commit is contained in:
asxalex 2024-04-06 11:31:00 +08:00
parent 107a7f8161
commit bc63f284ff

View File

@ -46,16 +46,16 @@ impl<'a> Common<'a> {
}
pub fn from_slice(value: &'a [u8]) -> Result<(Common, &'a [u8])> {
const id_len: usize = 32;
const token_len: usize = 8;
const ID_LEN: usize = 32;
const TOKEN_LEN: usize = 8;
if value.len() < 7 + id_len + token_len {
if value.len() < 7 + ID_LEN + TOKEN_LEN {
return Err("common header length error".into());
}
let packet_id = u16::from_be_bytes(value[0..2].try_into().unwrap());
let version = value[2];
let v1 = &value[3..3 + id_len];
let v1 = &value[3..3 + ID_LEN];
let mut id = match std::str::from_utf8(v1) {
Ok(s) => s,
Err(e) => return Err(SDLanError::ConvertError(e.to_string())),
@ -64,14 +64,14 @@ impl<'a> Common<'a> {
id = id.trim_end_matches('\0');
let token = u64::from_be_bytes(
value[3 + id_len..3 + id_len + token_len]
value[3 + ID_LEN..3 + ID_LEN + TOKEN_LEN]
.try_into()
.unwrap(),
);
let ttl = value[3 + id_len + token_len];
let flags = BigEndian::read_u16(&value[4 + id_len + token_len..6 + id_len + token_len]);
let pc = value[6 + id_len + token_len];
let ttl = value[3 + ID_LEN + TOKEN_LEN];
let flags = BigEndian::read_u16(&value[4 + ID_LEN + TOKEN_LEN..6 + ID_LEN + TOKEN_LEN]);
let pc = value[6 + ID_LEN + TOKEN_LEN];
let common = Self {
packet_id,
@ -82,7 +82,7 @@ impl<'a> Common<'a> {
pc: pc.into(),
flags: flags,
};
Ok((common, &value[7 + id_len + token_len..]))
Ok((common, &value[7 + ID_LEN + TOKEN_LEN..]))
}
pub fn from_old_common(cmn: &'a Common) -> Self {