-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add to_slice #461
Add to_slice #461
Conversation
Benchmark for f979437Click to view benchmark
|
src/lib.rs
Outdated
DekuWriter::to_writer(self, &mut __deku_writer, ()).unwrap(); | ||
__deku_writer.finalize().unwrap(); |
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.
Is it okay to use unwrap()
here? to_bytes
is using ?
to propagate the errors to the caller.
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.
Changed from unwrap
359ab28
to
b0d662a
Compare
Benchmark for 5be88f4Click to view benchmark
|
Benchmark for 15f0828Click to view benchmark
|
DekuWriter::to_writer(self, &mut __deku_writer, ())?; | ||
__deku_writer.finalize()?; | ||
|
||
Ok(__deku_writer.bits_written / 8) |
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.
There might be a corner case here. Would it handle the following case?
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
#[deku(endian = "big")]
struct DekuTest {
#[deku(bits = 4)]
field_a: u8,
field_b: u8,
}
Let's say serializing this struct results in bits_written = 12 which means we need two bytes to store them into. But bits_written / 8 = 1. So I'm thinking either (bit_written + 8) / 8
or ceil()
would be right way. What do you think?
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.
The above finalize
call will fill in bits until it hits the byte boundary to make sure everything is written. This follows the logic of to_bytes
.
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.
Thanks!
No description provided.