Comments (6)
If the overall struct is 4096 bytes I think it makes sense to better split it up into different components. Not the entire thing must be wrapped in a #[modular_bitfield]
proc. macro. I won't dig into the linked PDF and search for all the information required but generally you only need bitfields in cases where bits are stored in chunks that do not align with 8 bits. Storing an array probably won't need a modular bitfield - and if so I'd recommend you to rethink the data structure. It would only need a bitfield if the array is not aligned to 8 bits.
If you want you can paste the structure here with information as in:
Bits | Field | Type |
---|---|---|
0..5 | some_flag |
i8 |
5..6 | is_alive |
bool |
etc. | etc. | etc. |
And we sure will find some proper solution.
from modular-bitfield.
I'm not sure why you can't look up the figures I indicated. The primary figure I'm speaking about is figure 251, in section 5.15.2.2. The one with reserved bits is also within that figure, bytes 95:92. That has the following layout:
Bits | Description | Type |
---|---|---|
31:15 | Reserved | u16 |
14 | Endurance Group Event Aggregate Log Page Change Notices event supported | bool |
13 | LBA Status Information Notices event supported | bool |
12 | Predictable Latency Event Aggregate Log Change Notices event supported | bool |
11 | Sending Asymmetric Namespace Access Change Notices supported | bool |
10 | Reserved | bool |
9 | Firmware activation notices event supported | bool |
8 | Namespace Attribute Notices event and Changed Namespace List log page supported | bool |
7:0 | Reserved | [bool; 8] |
I could probably just make a recursive bitfield out of this, come to think of it.
from modular-bitfield.
Hi, sorry I completely forgot about this thread.
From what it looks you can easily represent all the sub parts of the entire structure as you have just laid out 32 bits of one.
The reserved bits in 7:0
should probably be represented as a single u8
instead of a [bool; 8]
field.
However, your suggestion to maybe add [bool; 8]
is legit and might even be possible, however only with some conversion overhead I suppose since bool
is not really a 1 bit width type.
So to answer your original question: Yes this crate should be sufficient for your needs from what it looks like on the surface.
Of course trust yourself always the most. Use u8
or other small types such as BN
instead of arrays for reserved holes.
from modular-bitfield.
from modular-bitfield.
I think it is a better decision to use this crate's modular bitfields only for well defined subsets of your structs with giant reserved voids. So just have your entire struct and within the struct have reserved fields that simply use some arrays or whatever you used before and for the well defined subsets use this crate's modular bitfield structs as fields. This should work very efficiently as long as your reserved data is 8 bit aligned. (I hope it is.)
from modular-bitfield.
from modular-bitfield.
Related Issues (20)
- Support for `to_u32()` conversion to `u32` and similar
- #[bitfield] on empty struct causes compilation error
- Feature Request: Ability to specify default value for field
- Is this crate maintained? HOT 1
- Implement serde derives replacement HOT 2
- Feature request: Array support HOT 3
- Into<uN> and TryFrom<uN> for uN bitfields HOT 2
- `with_*` methods should have `#[must_use]` annotation HOT 2
- Help: CheckFillsUnalignedBits unsatisfied HOT 2
- Support rust union structs HOT 1
- Feature request: Allow naming fields "Bytes" HOT 1
- Question: Array of bitfields HOT 1
- #[repr(...)] for unfilled bitfields?
- Generic structs not supported HOT 7
- [Question] Polymorphic bitfileds HOT 1
- Support for byte arrays
- `#[non_exhaustive]` enum support HOT 9
- const fn support for getters (and setters if possible) HOT 1
- How to implement signed 10 bit number? HOT 8
- [Feature Request] Better Note for (Size % 8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modular-bitfield.