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

Added parsing ZFO and ZTG messages #87

Merged
merged 6 commits into from
May 14, 2023
Merged

Conversation

/// The number of milliseconds in a hour.
const MILLISECS_PER_HOUR: i64 = 3600000;

pub(crate) fn parse_duration_hms(i: &str) -> IResult<&str, Duration> {
Copy link
Member

Choose a reason for hiding this comment

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

From what I see, all values can be negative and we should check this case.

Another thing that would be good to do is avoid using i64 and only when creating the Duration to cast the value to i64.

This will give us only 1 place where we should check if we can cast e.g. u32, u64 to i64.

pub(crate) fn parse_duration_hms(i: &str) -> IResult<&str, Duration> {
map_res(
tuple((
map_res(take(2usize), parse_num::<i64>),
Copy link
Member

Choose a reason for hiding this comment

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

  • Please use a different value for the number, e.g. u8 will also be sufficient.

Copy link
Author

Choose a reason for hiding this comment

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

i64 makes easier following conversion to Duration (as Duration accepts i64).

Copy link
Member

Choose a reason for hiding this comment

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

It would be better to fail value parsing as early as possible.

And Yes, Duration takes i64, however, we could easily convert it with From: https://doc.rust-lang.org/std/primitive.i64.html#impl-From%3Cu8%3E-for-i64

It's better to parse a mostly correct value, instead of very wrong value. parsing i64 could also take longer and can have bigger impact on constraint device since this first parser can actually succeed event with e.g. negative value.

Even if the architecture is 32 bit, 64 bit numbers are still supported but not by the hardware itself, so are less performant.

Comment on lines 76 to 75
if sec >= 60. {
return Err("Invalid time: sec >= 60");
}
Copy link
Member

Choose a reason for hiding this comment

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

src/sentences/utils.rs Outdated Show resolved Hide resolved
src/sentences/zfo.rs Show resolved Hide resolved
src/sentences/zfo.rs Outdated Show resolved Hide resolved
src/sentences/ztg.rs Outdated Show resolved Hide resolved
src/sentences/ztg.rs Show resolved Hide resolved
@elpiel
Copy link
Member

elpiel commented Apr 17, 2023

Thank you for your PR! I've left some improvements notes, which should be reviewed and applied to the rest of the sentences as well.

@codecov
Copy link

codecov bot commented Apr 28, 2023

Codecov Report

Patch coverage: 79.54% and project coverage change: +0.04 🎉

Comparison is base (d8f668b) 80.22% compared to head (2fd41b3) 80.26%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
+ Coverage   80.22%   80.26%   +0.04%     
==========================================
  Files          31       33       +2     
  Lines        1153     1196      +43     
==========================================
+ Hits          925      960      +35     
- Misses        228      236       +8     
Impacted Files Coverage Δ
src/parser.rs 78.51% <0.00%> (-0.62%) ⬇️
src/sentences/mod.rs 0.00% <ø> (ø)
src/sentences/zfo.rs 83.33% <83.33%> (ø)
src/sentences/ztg.rs 83.33% <83.33%> (ø)
src/parse.rs 73.86% <100.00%> (+1.24%) ⬆️
src/sentences/utils.rs 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@elpiel
Copy link
Member

elpiel commented May 14, 2023

Thank you once again for your contributions @taavit !

@elpiel elpiel merged commit 2d30392 into AeroRust:main May 14, 2023
13 of 14 checks passed
@taavit taavit deleted the zfo-ztg-message branch May 14, 2023 11:01
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.

None yet

2 participants