Skip to content
Dion Mendel edited this page Jun 25, 2023 · 5 revisions

Navigation


Alternatives

There are several alternatives to BinData. Below is a comparison between BinData and its alternatives.

The short form is that BinData is the best choice for most cases. It is the most full featured of all the alternatives. It is also arguably the most readable and easiest way to parse and write binary data.

If you only want to parse (not modify or write), then Kaitai Struct has a large library of binary formats pre-defined.


This is the only real alternative to BinData. It supports reading (not writing). It provides most of the same features as BinData. The main difference is that Kaitai definitions are designed to be machine readable, while BinData definitions are designed to be programmer readable.

The advantage that Kaitai has is self documenting definitions, a machine generated visualiser and a large library of pre-defined binary formats. It also has a large community as it targets multiple languages, while BinData only targets Ruby.

The main disadvantage is that it generates a parser, but the resultant data is not designed for modifying or writing.


The following is purely historic. All the alternatives to BinData are no longer actively maintained.

BitStruct is the most complete of all the alternatives. It is declarative and supports most of the same primitive types as BinData. Its special feature is a self documenting feature for report generation. BitStruct's design choice is to favour speed over flexibility.

The major limitation of BitStruct is that it does not support variable length fields and dependent fields. This makes it difficult to work with any non trivial file formats.

If speed is important and you are only dealing with simple binary data types then BitStruct might be a good choice. For non trivial data types, BinData is the better choice.

BinaryParse is a declarative style packer / unpacker. It provides the same primitives as Ruby's #pack, with the addition of date and time. Like BitStruct, it doesn't provide dependent or variable length fields.

BinStruct is an imperative approach to unpacking binary data. It does provide some declarative style syntax sugar. It provides support for the most common primitive types, as well as arbitrary length bitfields.

Its main focus is as a binary fuzzer, rather than as a generic decoding / encoding library.

Packable makes it much nicer to use Ruby's #pack and #unpack methods. Instead of having to remember that, for example "n" is the code to pack a 16 bit big endian integer, packable provides many convenient shortcuts. In the case of "n", {:bytes => 2, :endian => :big} may be used instead.

Using Packable improves the readability of #pack and #unpack methods, but explicitly calls to #pack and #unpack aren't as readable as a declarative approach.

Bitpack provides methods to extract big endian integers of arbitrary bit length from an octet stream.

The extraction code is written in C, so if speed is important and bit manipulation is all the functionality you require then this may be an alternative.