enhancementgood first issuehelp wantedpinnedsize/m
Repository metrics
- Stars
- (5 stars)
- PR merge metrics
- (PR metrics pending)
Description
I'd like to specify the following:
BinaryStruct.decode([
'L', :some_num,
'b', :flag1,
'b', :flag2,
'b', :flag3,
'L', :another_num,
])
Given that, I'd expect BinaryStruct.decode to extract a number, then on the next byte extract the first 3 bits as booleans stored in :flag1, :flag2, :flag3, then move ahead to the next byte and extract another number.
I'd probably be happy with having to align my definition to byte boundaries, so perhaps...
BinaryStruct.decode([
'L', :some_num,
'b', :flag1,
'b', :flag2,
'b', :flag3,
'b5', :unused, # ideally optional
'L', :another_num,
])
I would expect encode and size to handle similar structures.
Implementation wise, the 'b' identifier reads 1 bit then skips to the next byte, So, when building the decode string it will have to be aware of successive bits and then pack those into a b8.