-
Notifications
You must be signed in to change notification settings - Fork 33
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 an id method to all message structs #71
Conversation
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.
Nice, I was going to submit a PR to add this too. :)
@@ -351,6 +351,15 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D | |||
writeln!(&mut w, "}}")?; | |||
writeln!(w)?; | |||
|
|||
writeln!(&mut w, "/// Access message id")?; | |||
writeln!(&mut w, "pub fn id(&self) -> u32 {{",)?; |
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.
writeln!(&mut w, "pub fn id(&self) -> u32 {{",)?; | |
writeln!(&mut w, "pub fn message_id(&self) -> u32 {{",)?; |
For consistency with the constant name?
writeln!(&mut w, "pub fn id(&self) -> u32 {{",)?; | ||
{ | ||
let mut w = PadAdapter::wrap(&mut w); | ||
writeln!(&mut w, "Self::MESSAGE_ID & 0x1FFF_FFFF")?; |
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 curious, why does it need the bitwise AND? If MESSAGE_ID is bigger than 29-bits then shouldn't it fail somewhere else?
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.
What's the value of this over accessing the public constant?
If we decide to add this, please add a check that we don't conflict if there is a field called "id".
I can't speak for @JoNil, but what I was hoping to work towards is defining a trait over all messages that lets you access |
That’s a good idea, I’d merge in this trait :) this will add a teeny tiny
bit of a runtime crate though which we’d need to add as a dependency.
(Reminds me of #35)
…On Tue, 14 May 2024 at 01:09, Angus Gratton ***@***.***> wrote:
What's the value of this over accessing the public constant?
I can't speak for @JoNil <https://github.com/JoNil>, but what I was
hoping to work towards is defining a trait over all messages that lets you
access message_id and raw. With a goal to building things like a send<impl
that_trait>(&msg) function that sends an arbitrary message struct to a
CAN controller, for example.
—
Reply to this email directly, view it on GitHub
<#71 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAE4XZ4XRNXABIMXDIHHQTZCFB4NAVCNFSM6AAAAABHM5RWXOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBYHE2TMMBTHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
#82 adds impls for |
No description provided.