From: Joel VanderWerf Date: 2006-07-30T01:06:54+09:00 Subject: Re: How can I parse binary files? Daniel Martin wrote: > Actually, going through this exercise has pointed up some features > that I would like to add to BitStruct, since in many cases it almost > but not quite completely was exactly what the poster wanted. It would > be nice to have an easy, obvious, and supported way to define extra > padding in a structure (as we needed to here). It would be nice to > have an easier, supported syntax for reading a structure from a binary > file. Finally, it would be nice to allow an easy way to define data > wrappers, as was done with the date property. 1. Padding. You can use "char" fields, but that puts extra junk in the inspect output. I'll add an "ignore" or "pad" field type in the next release, which will behave like char but will not define accessors and will not show up in inspect. (Pad fields will have to show up in #to_s output, in order to preserve alignment, of course.) 2. Reading BitStructs from a file. I'm not sure there's an easier way to do it than in your code, Daniel, but I'm open to suggestions. All of ruby's IO (including sockets) uses Strings, so we always have to read a String and then construct a BitStruct from that string using BitStruct.new. 3. Defining data wrappers. Hm.... I've needed that too. I'll think about it. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407