Parsing Binary Structures; Is there a better way / What is your way?

Jon Clements joncle at googlemail.com
Wed Aug 5 22:39:33 CEST 2009


On 5 Aug, 20:41, "Martin P. Hellwig" <martin.hell... at dcuktec.org>
wrote:
> Paul Rubin wrote:
> > "Martin P. Hellwig" <martin.hell... at dcuktec.org> writes:
> >> Is there an advantage using shifts and masks over my kitchen type solution?
>
> > Weren't you complaining about the 8-to-1 expansion from turning each bit
> > to an ascii char?
>
> Yes you are (of course) right, my 'dream' solution would be something
> that accepts slice indeces on bit level. Your reasoning did reveal some
> flaws in my approach though ;-)
>
> --
> MPHhttp://blog.dcuktec.com
> 'If consumed, best digested with added seasoning to own preference.'

Ahh huh -- found it...

ID: DLT119
Desc: datasyzygy misc. development, production and accounts.
Date: 2008-12-09
File: pybits.py
"""
Implements a python level interface to reading bit fields with an
associated type. Fields are accessed via __getitem__ and must be a
valid python name. eg:

class MyStructure:
    a = BitField(4, int)
    b = BitField(6, int)
    c = BitField(2, int)
    d = BitField(36, str)
"""

Ummm, seems I left the rest pretty vague, but I'm guessing that's what
you're after, and I'm fairly curious to see what I wrote... mind you,
not too hard to write again now that's jogged my memory! (although
after a couple at the pub, not going to do it tonight!)

Cheers,

Jon.




More information about the Python-list mailing list