Binary parsing

Hi all,

I have a quick query relating to parsing binary data. In python you are
able to specify in your code

DataA is bytes 10 to 35
DataB is bytes 36 to 40
etc etc

What is the equivalent in Ruby? I essentially will be reading in binary
data and reading it in specific chunks as data in a range of bytes
equates to one things, other bytes are another. Generally the data is
consistently structured.

Many thanks

···

--
Posted via http://www.ruby-forum.com/.

`ri String#unpack`

···

On Oct 21, 2011, at 14:02 , Stuart C. wrote:

Hi all,

I have a quick query relating to parsing binary data. In python you are
able to specify in your code

DataA is bytes 10 to 35
DataB is bytes 36 to 40
etc etc

What is the equivalent in Ruby? I essentially will be reading in binary
data and reading it in specific chunks as data in a range of bytes
equates to one things, other bytes are another. Generally the data is
consistently structured.

There is String#unpack

and Array#pack for the other direction

And then there are gems and libraries, for example
http://raa.ruby-lang.org/project/bindata/
http://raa.ruby-lang.org/project/bit-struct/
http://raa.ruby-lang.org/project/packstruct/

Found via
http://raa.ruby-lang.org/search.rhtml?search=binary

Kind regards

robert

···

On Fri, Oct 21, 2011 at 11:02 PM, Stuart C. <stuart_clarke86@yahoo.com> wrote:

I have a quick query relating to parsing binary data. In python you are
able to specify in your code

DataA is bytes 10 to 35
DataB is bytes 36 to 40
etc etc

What is the equivalent in Ruby? I essentially will be reading in binary
data and reading it in specific chunks as data in a range of bytes
equates to one things, other bytes are another. Generally the data is
consistently structured.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Thanks I will give that a try.

···

--
Posted via http://www.ruby-forum.com/.