Skip to content

Commit

Permalink
add consts instead of hardcoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
MarwanMashaly1 committed May 1, 2024
1 parent 260ba19 commit 56ec50a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions libraries/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub mod sensor;
pub mod sensor_status;
pub mod state;

pub const MAX_SIZE: usize = 64;
pub const MAX_HEALTH_SIZE: usize = 47;
pub const MAX_SENSOR_SIZE: usize = 53;
pub const MAX_STATE_SIZE: usize = 13;
pub const MAX_LOGNCOMMAND_SIZE: usize = 15;

pub use logging::{ErrorContext, Event, Log, LogLevel};

Expand Down Expand Up @@ -70,7 +73,7 @@ impl Message {

#[cfg(test)]
mod test {
use crate::Message;
use crate::{Message, MAX_HEALTH_SIZE, MAX_LOGNCOMMAND_SIZE, MAX_SENSOR_SIZE, MAX_STATE_SIZE};
use proptest::prelude::*;

proptest! {
Expand All @@ -82,19 +85,19 @@ mod test {
// The size of the message should be less than or equal the maximum size.
match msg.data {
crate::Data::State(_) => {
assert!(dbg!(bytes.len()) <= 13);
assert!(dbg!(bytes.len()) <= MAX_STATE_SIZE);
}
crate::Data::Sensor(_) => {
assert!(dbg!(bytes.len()) <= 53);
assert!(dbg!(bytes.len()) <= MAX_SENSOR_SIZE);
}
crate::Data::Log(_) => {
assert!(dbg!(bytes.len()) <= 15);
assert!(dbg!(bytes.len()) <= MAX_LOGNCOMMAND_SIZE);
}
crate::Data::Command(_) => {
assert!(dbg!(bytes.len()) <= 15);
assert!(dbg!(bytes.len()) <= MAX_LOGNCOMMAND_SIZE);
}
crate::Data::Health(_) => {
assert!(dbg!(bytes.len()) <= 47);
assert!(dbg!(bytes.len()) <= MAX_HEALTH_SIZE);
}
}
}
Expand Down

0 comments on commit 56ec50a

Please sign in to comment.