Sha256: 1773b98c8a6e63c04c5f560d7399fed370bfdf1d87a17b77788ea69ab7c1bc34

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

= 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. 

= Installation

  $ sudo gem install bindata

  -or-

  $ sudo ruby setup.rb

= Documentation

  http://bindata.rubyforge.org/

  -or-

  $ rake manual

= Contact

If you have any queries / bug reports / suggestions, please contact me
(Dion Mendel) via email at dion@lostrealm.com

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bindata-1.4.5 README
bindata-1.4.4 README
bindata-1.4.3 README
bindata-1.4.2 README
bindata-1.4.1 README
bindata-1.4.0 README
bindata-1.3.1 README
bindata-1.2.2 README
bindata-1.2.1 README
bindata-1.2.0 README