From: Logan Capaldo Date: 2006-02-22T04:50:16+09:00 Subject: Re: Question about String.unpack --Apple-Mail-2--964562428 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Feb 21, 2006, at 2:19 PM, Jacob Repp wrote: > I'm curious about binary protocol parsing in ruby and have scratched > around for some kind of BinaryReader-ish interface for strings. Seems > like you could solve this if you know that your struct is in a string > you could say: > > str = fd.sysread(n) > name = str.read_str(30) > size = str.read_double > age = str.read_int > stuff = str.read_c > > I was going to write a native extension to do this after I finish my > current Ruby/AIO extension project. Unless there is something that > does this already (maybe in a cleaner/more ruby-ish way?) This is pretty much exactly what unpack does anyway., except its one method that uses a format string. If you wanted a more stream oriented wrapper around this, you certainly could write one fairly easily. ri String#unpack --Apple-Mail-2--964562428--