RAA - bindata/1.4.5

bindata / 1.4.5

Short description: A declarative way to read and write structured binary data
Category: Library/Datastructure
Status: stable
Created: 2009-09-14 05:17:21 GMT
Last update: 2012-07-24 05:21:40 GMT
Owner: Dion Mendel (Projects of this owner)
Homepage: http://bindata.rubyforge.org
Download: http://rubyforge.org/projects/bindata
License: Ruby's
Dependency:
None
Description:

What is BinData?

Do you ever find yourself writing code like this?

  io = File.open(...)
  len = io.read(2).unpack("v")
  name = io.read(len)
  width, height = io.read(8).unpack("VV")
  puts "Rectangle #{name} is #{width} x #{height}"

It’s ugly, violates DRY and feels like you’re writing Perl, not Ruby.

There is a better way. Here’s how you’d write the above using BinData.

  class Rectangle < BinData::Record
    endian :little
    uint16 :len
    string :name, :read_length => :len
    uint32 :width
    uint32 :height
  end

  io = File.open(...)
  r  = Rectangle.read(io)
  puts "Rectangle #{r.name} is #{r.width} x #{r.height}"

BinData makes it easy to create new data types. It supports all the common primitive datatypes that are found in structured binary data formats. Support for dependent and variable length fields is built in.

Versions: [1.4.5 (2012-07-24)] [1.4.4 (2012-06-21)] [1.4.0 (2011-06-14)] [1.3.1 (2011-01-24)] [1.3.0 (2011-01-24)] [1.2.2 (2010-12-14)] [1.2.0 (2010-07-09)] [1.1.0 (2009-12-01)] [1.0.0 (2009-09-14)]

Edit this project (for project owner)

back to RAA top