Module: BinData::BitAligned

Defined in:
lib/bindata/alignment.rb

Overview

A monkey patch to force byte-aligned primitives to become bit-aligned. This allows them to be used at non byte based boundaries.

class BitString < BinData::String
  bit_aligned
end

class MyRecord < BinData::Record
  bit4       :preamble
  bit_string :str, length: 2
end

Defined Under Namespace

Classes: BitAlignedIO

Instance Method Summary collapse

Instance Method Details

#bit_aligned?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/bindata/alignment.rb', line 63

def bit_aligned?
  true
end

#do_num_bytesObject



71
72
73
# File 'lib/bindata/alignment.rb', line 71

def do_num_bytes
  super.to_f
end

#do_read(io) ⇒ Object



67
68
69
# File 'lib/bindata/alignment.rb', line 67

def do_read(io)
  super(BitAlignedIO.new(io))
end

#do_write(io) ⇒ Object



75
76
77
# File 'lib/bindata/alignment.rb', line 75

def do_write(io)
  super(BitAlignedIO.new(io))
end