Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: binder: Improve try_from vec #39

Merged
merged 1 commit into from
May 16, 2024

Conversation

patrickelectric
Copy link
Member

No description provided.

build/binder.rs Outdated
@@ -109,8 +109,20 @@ pub fn generate<W: Write>(modules: Vec<String>, out: &mut W) {
if !((buffer[0] == HEADER[0]) && (buffer[1] == HEADER[1])) {
return Err(format!("Message should start with \"BR\" ASCII sequence, received: [{0}({:0x}), {1}({:0x})]", buffer[0], buffer[1]));
}
if buffer.len() < 10 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can give this 10 offset a name defining it as a local const?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@RaulTrombin RaulTrombin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some suggestions

build/binder.rs Outdated
@@ -109,8 +109,20 @@ pub fn generate<W: Write>(modules: Vec<String>, out: &mut W) {
if !((buffer[0] == HEADER[0]) && (buffer[1] == HEADER[1])) {
return Err(format!("Message should start with \"BR\" ASCII sequence, received: [{0}({:0x}), {1}({:0x})]", buffer[0], buffer[1]));
}
if buffer.len() < 10 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if buffer.len() < 10 {
const MIN_MSG_SIZE : usize = 10;
if buffer.len() < MIN_MSG_SIZE {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

build/binder.rs Outdated
Comment on lines 118 to 126
if payload_length as usize + 10 != buffer.len() {
return Err(format!(
"Payload length does not match, expected: {}, received: {}",
payload_length,
buffer.len() - 10
));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if payload_length as usize + 10 != buffer.len() {
return Err(format!(
"Payload length does not match, expected: {}, received: {}",
payload_length,
buffer.len() - 10
));
}
if payload_length as usize + MIN_MSG_SIZE != buffer.len() {
let received_payload_lenght = buffer.len() - 10;
return Err(format!(
"Payload length does not match, expected: {payload_length}, received: {received_payload_lenght}"
));
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to use MIN_MSG_SIZE, I see not point of creating an intermediary variable for a print.

@patrickelectric patrickelectric force-pushed the add-more-tests branch 4 times, most recently from 0a81fd6 to 2f736f9 Compare May 16, 2024 15:45
Signed-off-by: Patrick José Pereira <[email protected]>
@patrickelectric patrickelectric merged commit 21ebe00 into bluerobotics:master May 16, 2024
3 checks passed
@patrickelectric patrickelectric deleted the add-more-tests branch May 16, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants