class FFI::StructLayoutBuilder

def add(name, type, offset = nil)

Other tags:
    Note: - Setting +offset+ to +nil+ or +-1+ is equivalent to +0+.

Returns:
  • (self) -

Parameters:
  • offset (Numeric, nil) --
  • type (Array, DataConverter, Struct, StructLayout::Field, Symbol, Type) -- type of the field
  • name (String, Symbol) -- name of the field
def add(name, type, offset = nil)
  if offset.nil? || offset == -1
    offset = @union ? 0 : align(@size, @packed ? [ @packed, type.alignment ].min : [ @min_alignment, type.alignment ].max)
  end
  #
  # If a FFI::Type type was passed in as the field arg, try and convert to a StructLayout::Field instance
  #
  field = type.is_a?(StructLayout::Field) ? type : field_for_type(name, offset, type)
  @fields << field
  @alignment = [ @alignment, field.alignment ].max unless @packed
  @size = [ @size, field.size + (@union ? 0 : field.offset) ].max
  return self
end