Skip to content

Commit

Permalink
lib: Add variable for header
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Dec 24, 2023
1 parent fb84855 commit 5b8f49e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -41,7 +41,8 @@ impl TryFrom<&Vec<u8>> for Messages {

fn try_from(buffer: &Vec<u8>) -> Result<Self, Self::Error> {
// 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");
}

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5b8f49e

Please sign in to comment.