-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add data types for messages #13
Comments
And with some manual effort, it would even be possible to define a mapping of the units used in the default profile to pub struct Activity {
pub total_timer_time: Option<uom::si::f64::Time>,
pub num_sessions: Option<u16>,
pub r#type: Option<fitparser::profile::field_type::Activity>,
// ....
} |
Hey @robinkrahl I am glad this crate has been helpful to you! I use it fairly regularly myself in a run-tracking CLI app I built awhile back. I’ve thought about adding structs for the messages in the past but never have since this library simply decodes FIT messages into a generic “data transfer object” format. I like the idea of the messages themselves being better documented via the API docs alone. And it would be fairly straightforward to convert back and forth between the generic DTO struct and these new types. I try to be cognizant of the size of my dependency chain so I’ll have to do some looking into uom and weigh pros/cons. It might be more beneficial to avoid adding a new dependency and instead setup a way that unit info can be easily ingested into uom for the folks that want that added level of detail. (Although I have spent some time hacking around the units myself so maybe it would be worth it.) How else do you think adding specific types to the crate would make thing easier? I’d be curious to hear some other use cases! |
FYI, I’ve started working on an implementation an will hopefully be able to share that soon.
My use case is analyzing cycling logs. I ended up working on a separate crate that contains structs for the FIT messages and some utilities for parsing. All this code could be automatically generated from the profile. If I was able to directly access the data structures, I wouldn’t have to go back at the profile sheet and look for the messages and fields I want to use, and I would not have to manually write the parsing and conversion code. |
@robinkrahl great, I look forward to seeing it! Also I bumped the bundled FIT SDK version to 21.89 which is current as of today to help minimize the diff from your new code. |
If you want to avoid having pub struct Activity {
pub total_timer_time: Option<Time>,
}
pub struct Time(pub f64);
#[cfg(feature = "uom")]
impl From<Time> for uom::si::f64::Time {
fn from(time: Time) -> Self {
// ...
}
} |
#14 implemented types with I’m not sure what I prefer. On the one hand, I’d like the implementation to be as generic as possible. On the other hand, the main goal of these types is improved ergonomics so it should also be as simple as possible. |
That is an unfortunate consequence of the FIT profile being modifiable, although I never actually considered it's effect on this work until now. A couple thoughts:
|
In the initial implementation, we had a config option to determine whether unknown fields should return an error. Based on the discussion in [0], I think it is better to just collect unexpected fields in the message type and let the user decide how to handle them. [0] stadelmanma#13
In the initial implementation, we had a config option to determine whether unknown fields should return an error. Based on the discussion in [0], I think it is better to just collect unexpected fields in the message type and let the user decide how to handle them. [0] stadelmanma#13
After giving it some more thought and starting the implementation, I think the best approach would be to keep the fields as |
Thank you for this crate! It really takes the pain out of parsing my Garmin logs. 👍
I think it could be even more useful if it would contain structs for the message types, with each message field being a field of the struct. As you are already parsing the profile in
build.rs
and auto-generating code from it, I think this should not be too complicated. For example, a representation of anActivity
message could look like this:This would make it much easier to use the crate and also to discover the relevant message types and fields from the API docs. What are your thoughts on this?
The text was updated successfully, but these errors were encountered: