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?

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 martin.hell...@dcuktec.org 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 +-+-+-+-+--++ |

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

2009-08-06 Thread Dave Angel
Paul Rubin wrote: Martin P. Hellwig martin.hell...@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? One warning to Martin: If you want your

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 +-+-+-+-+--++ | Version |

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 martin.hell...@dcuktec.org 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

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

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 martin.hell...@dcuktec.org 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 +-+-+-+-+--++ |

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 |

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 martin.hell...@dcuktec.org 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 +-+-+-+-+--++ |

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

2009-08-05 Thread Martin P. Hellwig
Jon Clements wrote: cut 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,

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 | Filler |

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 |

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

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

2009-08-05 Thread Paul Rubin
Martin P. Hellwig martin.hell...@dcuktec.org 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

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 martin.hell...@dcuktec.org 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

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 martin.hell...@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

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 martin.hell...@dcuktec.org wrote: Paul Rubin wrote: Martin P. Hellwig martin.hell...@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

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 martin.hell...@dcuktec.org 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