technocreatives / dbc-codegen

Generate Rust structs for messages from a dbc (CAN bus definition) file.
Apache License 2.0
43 stars 23 forks source link

Prepend x to rust keywords #13

Closed andresv closed 3 years ago

andresv commented 3 years ago

There are cases where some fields in in dbc can be Rust keywords. This PR prepends x to such fields. So type would become xtype etc.

killercup commented 3 years ago

Now these could actually be raw identifiers! Want to keep the x prefix for consistency?

andresv commented 3 years ago

Yes. From user perspective something::r#type looks cumbersome. I also documented this behavior in readme so it should not surprise users.

andresv commented 3 years ago

No it is not yet quite right. I try to add proper tests under can-messages.lib. Is it intended that One starts from offset 15?

BO_ 512 Bar: 8 Ipsum
 SG_ One : 15|2@0+ (1,0) [0|3] "" Dolor
 SG_ Two : 7|8@0+ (0.39,0) [0.00|100] "%" Dolor
 SG_ Three : 13|3@0+ (1,0) [0|7] "" Dolor
 SG_ Four : 10|2@0+ (1,0) [0|3] "" Dolor
 SG_ Type : 30|1@0+ (1,0) [0|1] "boolean" Dolor
andresv commented 3 years ago

It seems overlapping bits are allowed in dbc and this message is meant for testing https://github.com/technocreatives/dbc-codegen/blob/main/testing/rust-integration/tests/compare_to_socketcan.rs#L23

killercup commented 3 years ago

Yeah that;s supposed to test an edge case :)

This look good -- I'll merge it. Feel free to submit more PRs with fixes if you want to cover other cases or improve our weird test messages!