www.intensicode.net >>> Projects >>> BitStructEx

Info

Alternative "BitStruct" implementation with less features than bit-struct, but with support for unaligned nested structures.

The idea is to give you a simple DSL to specify bit structures like this:


class Flags < StructBase
	unsigned :direction, 4
	unsigned :multiplier, 2
	unsigned :offset, 2
end

class Entry < StructBase
	unsigned :offset, 4
	nested   :flags, Flags
	unsigned :address, 24
	unsigned :cache_id, 16
	text     :packet_name, 32
end
    

It is then possible to access byte data like this:


some_data = read_from_a_file_for_example

entry = Entry.new some_data
offset = entry.offset

flags = entry.flags
direction = flags.direction

puts entry.packet_name

etc.
    

The project is hosted on RubyForge.