-
Notifications
You must be signed in to change notification settings - Fork 18
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
pack/unpack a bilge
struct to/from &[u8]
#33
Comments
Uhh, where in the readme did you find this? Besides that, let my_struct = MyStruct::from(0);
uN::from(my_struct).to_le_bytes(); (limited to multiples of a byte) |
I might have found this in the tests and examples as well 😅
Sure Isn't using |
on le:
yeah, not sure how this is supposed to work otherwise... do you want a stream of bytes - when does it stop? should it only be possible for multiples of bytes? |
Hum .. so Likewise, assuming I have I'm asking all this coming from crates |
See to_le_bytes and to_le.
The author of the struct would need to provide a method to do that. I only found generic usage here: https://github.com/ethercrab-rs/ethercrab/blob/9b55183df07691c00465ebe7e253a4eb71c27b0a/src/generate.rs#L28 |
In ethercrab, There is also the traits
Well, okay. |
Yes. I also would be up to provide a feature-gated thing to do this. impl ByteArray for Struct
where
Struct: Bitsized,
{
fn to_le_bytes(self) -> [u8; Self::BITS >> 3] { // the size needs to be calculated differently for non byte-multiples
// arbitrary-int just provides these for byte-multiples, otherwise it's not clear how to fill up e.g. u4's 4 missing bits
Self::ArbitraryInt::from(self).to_le_bytes()
// self.value.to_le_bytes() //would also work
}
} |
We will solve this together with #7. @jimy-byerley Since we'll add this based on a |
Good news ! By the way, I'm using |
@jimy-byerley haha nice, I looked into |
Hello, that's me again
What is the best way to safely pack/unpack a bilge struct to/from a byte slice ?
I have found the following in the readme, but not exactly what I am looking for:
Did I missed something for safely doing the same with byte slices or byte arrays ?
The text was updated successfully, but these errors were encountered: