2 ms·
(I work with bcantrill) We use https://crates.io/crates/bitfield https://crates.io/crates/bitfield, and some of our dependencies use https://crates.io/crates/b
by steveklabnik 6y ago
(I work with bcantrill)
We use https://crates.io/crates/bitfield https://crates.io/crates/bitfield, and some of our dependencies use https://crates.io/crates/bitflags https://crates.io/crates/bitflags. They're not perfect, but they get the job done.
- boulos 6y agoDisclaimer: I haven’t used bitflags (but I don’t think it applies for my need). The nginx example in the above blog post seems like a bitfield! equivalent would be... unpleasant. For very small structs that are just only wire formats, I might use bitfield!. But encoding/decoding protocol headers (e.g., a VP8 header [1], which has a 19-bit “size” field) or interop with other systems where you’d like some checking a la serde, bitfield! seems more verbose than “fine, I’ll do it myself right here against the u8”. That is, even if that nginx example had a two-bit field in there, I’d take everything at the end and round up to a u8. Then read/write some of these “by hand”, rather than pollute the struct with lots and lots of macro “noise”. [1] https://tools.ietf.org/html/rfc6386#section-9.1 https://tools.ietf.org/html/rfc6386#section-9.1
- steveklabnik 6y agoYes, this is what I mean by "it's not perfect", there's totally things that could be better. All I'm saying is that this works out well enough for our particular needs generally, and isn't a giant pain point, so that's probably why it wasn't mentioned.