From bc63f284ff4c7f4b9b4805759660a632106dffd0 Mon Sep 17 00:00:00 2001 From: asxalex Date: Sat, 6 Apr 2024 11:31:00 +0800 Subject: [PATCH] fix warning --- src/packet/common.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/packet/common.rs b/src/packet/common.rs index 5b1b483..1a1e9bb 100644 --- a/src/packet/common.rs +++ b/src/packet/common.rs @@ -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 {