RAA - bit-struct/0.6

bit-struct / 0.6

Short description: Class for packed binary data stored in ruby Strings.
Category: Library/Datastructure
Status: beta
Created: 2005-10-09 23:45:14 GMT
Last update: 2006-05-01 05:33:16 GMT
Owner: Joel VanderWerf (Projects of this owner)
Homepage: http://redshift.sourceforge.net/bit-struct
Download: http://redshift.sourceforge.net/bit-struct
License: Ruby's
Dependency:
None
Description:

BitStruct

Class for packed binary data stored in ruby Strings. BitStruct accessors, generated from user declared fields, use pack/unpack to treat substrings as fields with a specified portable format.

Field types include

  • signed and unsigned integer (1..16 bits, or 32 bits)
  • fixed point, with arbitrary scale factor
  • fixed length character array
  • null-terminated character array for printable text
  • octets (hex and decimal representation options; useful for IP and MAC addrs)
  • float
  • nested BitStruct
  • free-form "rest" field (e.g., for the variable-size payload of a packet)

Installation

  ruby install.rb config
  ruby install.rb setup
  ruby install.rb install

Uses

BitStruct is useful for defining packets used in network protocols. This is especially useful for raw IP—see examples/ping-recv.rb. All multibyte numeric fields are stored in network order (though this could be different for user-defined field classes).

BitStruct is most efficient when your data is primarily treated as a binary string, and only secondarily treated as a data structure. (For instance, you are routing packets from one socket to another, possibly looking at one or two fields as it passes through or munging some headers.) If accessor operations are a bottleneck, a better approach is to define a class that wraps an array and uses pack/unpack when the object needs to behave like a binary string.

Recent Changes:

bit-struct 0.6:

  • Added the :endian => :native option for numerical fields (signed, unsigned, float).
  • Fixed error message with 9..15 bit fields aligned on byte boundary.
  • The #initial_value is now inherited (before applying defaults).
  • New examples: raw.rb, native.rb.

bit-struct 0.5:

  • Integer fields may now cross byte boundaries, as long as the field fits within two whole bytes.
  • Support for YAML serialization of BitStruct instances.
  • BitStruct#to_a, BitStruct#to_h, BitStruct#inspect and BitStruct#inspect_detailed all include the rest field (if any), by default.
Versions: [0.10 (2007-01-15)] [0.9 (2006-09-20)] [0.8 (2006-05-27)] [0.7 (2006-05-21)] [0.6 (2006-05-01)] [0.5 (2006-04-01)] [0.3 (2006-01-17)] [0.2 (2005-10-09)]

Edit this project (for project owner)

back to RAA top