Comments (4)
Hi @bearbattle,
I think your mental model of the bitfields as well as endian setting is incorrect.
When you specify members of the <bitfield>
the order of the members is starting with the LSB first, so when you think of your AnnFlags
as a 16 bit number representation it is encoded as:
MSB -> [PXNum (4 bits) | UnitNum (4 bits) | Flags (8 bits)] <- LSB
The bit ordering of the <set>
is also always starting from LSB, i.e bit 0 has mask 0x1 (1 << 0
), bit 1 has mask 0x2 (1 << 1
), bit 2 has mask 0x4 (1 << 2
), etc...
In other words, if your Flags.F
is set to 1, UnitNum
is set to 2, and PXNum
is set to 3, then the 16 bit of the AnnField
is going to be 0x3201
.
The endian specifies the order of written bytes, not bits, i.e the two bytes above can be written in only 2 ways:
0x32 0x01
- for big endian0x01 0x32
- for little endian
That's all. If you need to serialize it in different way, then you need to re-order your <bitfield>
and/or use different idx
property value for your bits. For example if you need your bit F
to come first (be MSB), then it needs to have idx="7"
.
Hope it helps.
Regards,
Alex
from commsdsl.
Thank you. Will the library provide any methods to alter the bit order (i.e. from MSB to LSB)?
from commsdsl.
Hi @bearbattle,
Counting (indexing) bits from MSB is NOT a common practice in software engineering. I do not intend to do it. It will introduce too much complexity with too little benefit. Re-ordering of the bits is completely within your control when defining the protocol schema, just assign appropriate idx value, such as
<set name="Flags" ...>
<bit name="F" idx="7" />
<bit name="K" idx="6" />
<bit name="P" idx="5" />
<bit name="C" idx="4" />
</set>
Note that the order of the <bit>
-s definition doesn't have to be from lowest idx to the highest. It can be arbitrary, what important is setting the right idx value.
from commsdsl.
Thanks for your reply! I'm closing the issue.
from commsdsl.
Related Issues (20)
- Question: List without length and message size HOT 2
- ICD generation HOT 7
- Missing copyright holder in license HOT 5
- ASN.1 Parsing/Serialization HOT 2
- Adding constexpr to static const functions HOT 2
- `optional` field with `cond` depending on another `optional` field. HOT 7
- Field Extension Support in Lists with termSuffix HOT 4
- Need Help HOT 21
- Creating Frame with `id` that is less than one byte HOT 3
- Can a (serial) protocol with character escaping be realized using the custom code feature? HOT 2
- Schema name cannot start with a capital HOT 4
- Select variant based on value in the transport frame HOT 1
- noexcept error with gcc 9 HOT 5
- Unexpected max serialisation length HOT 4
- Dead links in the Readme HOT 1
- vcpkg integration HOT 16
- error when using COMMSDSL_NO_TESTS HOT 2
- Undefined behaviour on "out of range" values of ID layer. HOT 4
- "Unexpected max serialisation length" on variable length field inside variant HOT 6
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 commsdsl.