More control when specifying formats. #249
scott-griffiths
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So for example a trailing
r
to indicate that the bitstring should be bit-wise reversed before the interpretation is used:a, b = s.readlist('2*u4r') # Read two 4-bit bitstrings, reverse them and interpret as unsigned integers.
It would also have to work for
unpack
, but that should be fine.How about ordinary interpretations?:
a = s[0:4].ur
which I don't hate. so there would be
floatr
,uintr
,intr
,bytesr
,uer
,sier
,intner
,float16r
,float:64r
,hexr
,octr
,binr
, etc. etc.And for setting:
s.binr = '0001' # So s.bin =
1000`Also could possibly allow LSB0/MSB0 to be specified to override whatever the default has been set to be. How would that work?
a = s.read('u4msb0')
Fine, now s.pos = 4. So if we do another read but instead use lsb0:
b = s.read('u4lsb0')
where does it read from? Reading from pos=4 makes no sense as that is now relative to the other end of the bitstring. If we read from the same position then it will re-read the same bits which is a bit pointless. Overall I think that a bitstring's pos is invalidated by a change of LSB0/MSB0 so they can't be combined in this way or used in reads.
They could be used in
unpack
though as that deals with the whole bitstring.a, b = s.unpack('2*4u', lsb0=True)
So this overrides the default in much the same was as
bytealigned
works.This doesn't need to change interpretations as they don't care if it's LSB0 or MSB0.
Is there a way to override the default in slices? Instead of
s[0:4]
we actually could says[4:0]
but that's a big breaking change to change that meaning! And it would mean thats[0:4]
would always be the left-most bits irrespective of the LSB0 flag. So to switch you'd need to recode all your slice indices - not very helpful.Beta Was this translation helpful? Give feedback.
All reactions