Method: CTypes::Bitfield::Builder#align

Defined in:
lib/ctypes/bitfield/builder.rb

#align(bits) ⇒ Object

Note:

#align cannot be mixed with calls to #field

set the alignment of the next field declared using #signed or #unsigned

Examples:

class MyBits < CTypes::Bitfield
  layout do
    unsigned :a       # single bit at offset 0
    align 4
    unsigned :b, 2    # two bits at offset 4
    align 4
    unsigned :c       # single bit at offset 8
  end
end

Parameters:

  • bits (Integer)

    bit alignment of the next field

Raises:



136
137
138
139
140
141
142
# File 'lib/ctypes/bitfield/builder.rb', line 136

def align(bits)
  raise Error, "cannot mix `#align` and `#field` in Bitfield layout" unless
      @offset
  @offset += bits - (@offset % bits)
  @layout << "align #{bits}"
  self
end