-
Notifications
You must be signed in to change notification settings - Fork 200
Description
I have a scenario where I have two bitfields of different size types subsequently
class BitFieldStruct { std::uint8_t a : 3; std::uint16_t b: 7; };
Note that the types of both bitfields are different. and the size of this class must be 2 bytes. The kaitai generated for such a class is as follows.
meta:
id: bitfieldstruct
endian: le
bit-endian: le
imports:
- /default/memory_chunk
seq:
- id: num_chunks
contents: [1]
- id: chunk_1
type: base_types__memory_chunk
instances:
payload:
io: _root.chunk_1.data._io
pos: 0
type: bitfieldstruct
-dynamic-type: "struct"
-cpp-datatype: "BitFieldStruct"
types:
bitfieldstruct:
seq:
- id: members
size: 2
type: bitfieldstruct_members
bitfieldstruct_members:
instances:
a:
pos: 0
type: b3
-dynamic-type: "primitive"
-cpp-datatype: "unsigned char"
-cpp-name: "a"
b:
pos: 0
type: b7
-dynamic-type: "primitive"
-cpp-datatype: "short unsigned int"
-cpp-name: "b"
Using this kaitai, we generated code using kaitai_struct_compiler for C++ (compiled using gcc 13.3.0). The bytes which we are trying to decode are 0x1D, 0x00
using the generated API's. Now, looking at the binary representation 00011101 00000000
, I expect decoded values as a = 5
and b = 3
. But the values I am getting is a = 5
and b = 35
. Upon close look, I see that the binary value of b
as 0100011
. It seems that for reading the last 7 bits, the read is happening at the same byte in a cyclic fashion, and the read is NOT moving over to the next byte as expected.
Am I missing something here or is this a known issue..??
Note that if both the bitfield types are same (Lets say std::uint8_t
), the decode is happening as expected from the generated API's