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

Add unchecked unsafe function to create data for frame #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Fomys
Copy link

@Fomys Fomys commented Sep 11, 2022

This addition allows the creation of Data without using slices.
It's useful when you already have the len and the [u8; 8].

Copy link

@talhaHavadar talhaHavadar left a comment

Choose a reason for hiding this comment

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

I am not fond of using unsafe functions but it seemed harmless to me. Lets see if there is an opposition about it

@jonas-schievink
Copy link
Contributor

Can you talk more about what this is useful for? Why do you want to avoid making a slice? I'm somewhat wary of adding unsafe APIs like this unless they pull their weight.

@Fomys
Copy link
Author

Fomys commented Feb 3, 2023

My specific case is to create a common interface for a protocol over can bus between a raspberry-pi and multiple stm32 (which use canfd and bxcan). I don't want to create multiple function to parse and create specific packet for each interface, it will be redundant and error prone if I have to do that three times, especially because my protocol may change with time.

So I created a function which transform my protocol into a tuple (size: u8, data: [u8;8]).
Actually, in the bxcan implementation I have to transform my tuple to a slice before creating the Data struct. As the Data struct contains already only those informations. I think the overhead brought by the slice and the copy is not necessary and can be avoided. I'm open to other solution, but I think it's a good way to do that.

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.

3 participants