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

2009-08-07 Thread andrew cooke
On Aug 5, 10:46 am, "Martin P. Hellwig" wrote: > Hi List, > > On several occasions I have needed (and build) a parser that reads a > binary piece of data with custom structure. For example (bogus one): > > BE > +-+-+-+-+--++ > | Version | Command

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

2009-08-07 Thread Hendrik van Rooyen
On Thursday 06 August 2009 20:50:30 Martin P. Hellwig wrote: > Thanks all for your insights and suggestions. > It seems to me that there are a couple of ways to this bit manipulation > and a couple of foreign modules to assist you with that. > > Would it be worth the while to do a PEP on this? > Pe

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

2009-08-06 Thread Martin P. Hellwig
Thanks all for your insights and suggestions. It seems to me that there are a couple of ways to this bit manipulation and a couple of foreign modules to assist you with that. Would it be worth the while to do a PEP on this? Personally I think that it would be nice to have a standard module in

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

2009-08-06 Thread sgriffiths
On Aug 5, 3:46 pm, "Martin P. Hellwig" wrote: > Hi List, > > On several occasions I have needed (and build) a parser that reads a > binary piece of data with custom structure. For example (bogus one): > > BE > +-+-+-+-+--++ > | Version | Command

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

2009-08-06 Thread Hendrik van Rooyen
On Wednesday 05 August 2009 21:41:26 Martin P. Hellwig wrote: > 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 ;-) This is the first time I have been compared to the sand

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

2009-08-06 Thread Hendrik van Rooyen
On Wednesday 05 August 2009 20:12:05 Paul Rubin wrote: > "Martin P. Hellwig" writes: > > what I usually do is read the packet in binary mode, convert the > > output to a concatenated 'binary string'(i.e. '0101011000110') and > > Something wrong with reading the data words as an integer and using >

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

2009-08-06 Thread Hendrik van Rooyen
On Wednesday 05 August 2009 16:46:13 Martin P. Hellwig wrote: > Hi List, > > On several occasions I have needed (and build) a parser that reads a > binary piece of data with custom structure. For example (bogus one): > > BE > +-+-+-+-+--++ > > | V

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

2009-08-05 Thread Dave Angel
Paul Rubin wrote: "Martin P. Hellwig" 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? One warning to Martin: If you want your code portable across syste

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

2009-08-05 Thread Gabriel Genellina
En Wed, 05 Aug 2009 11:46:13 -0300, Martin P. Hellwig escribió: On several occasions I have needed (and build) a parser that reads a binary piece of data with custom structure. For example (bogus one): BE +-+-+-+-+--++ | Version | Command

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

2009-08-05 Thread Paul Rubin
"Martin P. Hellwig" 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? -- http://mail.python.org/mailman/listinfo/python-list

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

2009-08-05 Thread Jon Clements
On 5 Aug, 20:41, "Martin P. Hellwig" wrote: > Paul Rubin wrote: > > "Martin P. Hellwig" 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

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

2009-08-05 Thread Martin P. Hellwig
Paul Rubin wrote: "Martin P. Hellwig" 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 ac

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

2009-08-05 Thread Martin P. Hellwig
Paul Rubin wrote: "Martin P. Hellwig" writes: what I usually do is read the packet in binary mode, convert the output to a concatenated 'binary string'(i.e. '0101011000110') and Something wrong with reading the data words as an integer and using old fashioned shifts and masks to get at the bi

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

2009-08-05 Thread Paul Rubin
"Martin P. Hellwig" writes: > what I usually do is read the packet in binary mode, convert the > output to a concatenated 'binary string'(i.e. '0101011000110') and Something wrong with reading the data words as an integer and using old fashioned shifts and masks to get at the bit fields? -- http

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

2009-08-05 Thread Masklinn
On 5 Aug 2009, at 19:17 , Bearophile wrote: Have you tried Hachoir? (I think its name may be changed to Fusil, I don't know). Name hasn't been changed (I think fusil is a subproject, something like that) on the other hand the hachoir.org site is dead. But apparently Hachoir was moved to bitbu

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

2009-08-05 Thread Masklinn
On 5 Aug 2009, at 16:46 , Martin P. Hellwig wrote: Hi List, On several occasions I have needed (and build) a parser that reads a binary piece of data with custom structure. For example (bogus one): BE +-+-+-+-+--++ | Version | Command | Ins

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

2009-08-05 Thread Bearophile
Martin P. Hellwig: > On several occasions I have needed (and build) a parser that reads a > binary piece of data with custom structure. For example (bogus one): > > BE > +-+-+-+-+--++ > | Version | Command | Instruction | Data Length | Data | Fill

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

2009-08-05 Thread Martin P. Hellwig
Jon Clements wrote: IIRC (and I have my doubts) the BitVector module may be of use, but it's been about 3 years since I had to look at it. I think it used the C equiv. of short ints to do its work. Otherwise, maybe the array module, the struct module or even possibly ctypes. Not much use, but m

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

2009-08-05 Thread Jon Clements
On 5 Aug, 15:46, "Martin P. Hellwig" wrote: > Hi List, > > On several occasions I have needed (and build) a parser that reads a > binary piece of data with custom structure. For example (bogus one): > > BE > +-+-+-+-+--++ > | Version | Command |

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

2009-08-05 Thread Martin P. Hellwig
Hi List, On several occasions I have needed (and build) a parser that reads a binary piece of data with custom structure. For example (bogus one): BE +-+-+-+-+--++ | Version | Command | Instruction | Data Length | Data | Filler | +-+-