Posted By: Dion Mendel
Date: 2010-07-09 09:24
Summary: BinData 1.2.0
Project: BinData

= BinData is a declarative way to read and write structured binary data.

Most of the changes this release are behind the scenes improvements in execution time and memory usage.

The new user visible change is a new syntax sugar for creating nested records, arrays and choices. Here's a quick example:

class PointList < BinData::Record
. endian :big
. int32 :num
. array :points, :initial_length => :num do
. int16 :x
. int16 :y
. end
end

If you use BinData and have any comments, suggestions or questions, feel free to email me.

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

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 supports all the data types you expect, including; arbitrarily sized/signed/endian integers, floats, bitstrings, strings, null terminated strings, dependent fields, arrays, choices, nested structures, and user defined structures.

Latest News
TZInfo v1.0.0 and TZInfo::Data v1.2013.3 Released
    Philip Ross - 2013-06-02 17:12
icalendar 1.4.0 Released
    Ryan Ahearn - 2013-05-21 23:17
BinData 1.5.0 - source moved to github
    Dion Mendel - 2013-05-21 11:10
v13.5.0 Released !!
    id 774 - 2013-05-18 12:28
Runt v0.9.0 Released
    Matthew Lipper - 2013-05-17 00:11

 

Forums | Admin

Discussion Forums: bindata-1.2.0

Start New Thread Start New Thread

 

Topic Topic Starter Replies Last Post