diff --git a/src/lib.rs b/src/lib.rs index 148180bee..f8c7ba5ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,8 +15,8 @@ pub struct PingMessagePack([u8; 1 + Self::HEADER_SIZE + PAYLOAD_SIZE + 2]); impl Default for PingMessagePack { fn default() -> Self { let mut new = Self([0; 1 + Self::HEADER_SIZE + PAYLOAD_SIZE + 2]); - new.0[0] = 'B' as u8; - new.0[1] = 'R' as u8; + new.0[0] = Self::HEADER[0]; + new.0[1] = Self::HEADER[1]; new } } @@ -41,7 +41,8 @@ impl TryFrom<&Vec> for Messages { fn try_from(buffer: &Vec) -> Result { // Parse start1 and start2 - if !((buffer[0] == b'B') && (buffer[1] == b'R')) { + if !((buffer[0] == PingMessagePack::HEADER[0]) && (buffer[1] == PingMessagePack::HEADER[1])) + { return Err("Message should start with \"BR\" ASCII sequence"); } @@ -93,6 +94,7 @@ impl PingMessagePack { */ const HEADER_SIZE: usize = 8; + const HEADER: [u8; 2] = ['B' as u8, 'R' as u8]; pub fn new() -> Self { Default::default()