-
Notifications
You must be signed in to change notification settings - Fork 4
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
build: binder: Improve try_from vec #39
Conversation
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if buffer.len() < 10 { | |
const MIN_MSG_SIZE : usize = 10; | |
if buffer.len() < MIN_MSG_SIZE { |
There was a problem hiding this comment.
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
if payload_length as usize + 10 != buffer.len() { | ||
return Err(format!( | ||
"Payload length does not match, expected: {}, received: {}", | ||
payload_length, | ||
buffer.len() - 10 | ||
)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}" | |
)); | |
} | |
There was a problem hiding this comment.
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.
0a81fd6
to
2f736f9
Compare
Signed-off-by: Patrick José Pereira <[email protected]>
2f736f9
to
649fa85
Compare
No description provided.