class Ronin::Support::Binary::CTypes::StructType::Member

Represents a member within a struct.

@api private

@since 1.0.0

Attributes

offset[R]

The offset, in bytes, of the member from the beginning of the struct.

@return [Integer]

type[R]

The type of the member.

@return [Type]

Public Class Methods

new(offset,type) click to toggle source

Initializes the member.

@param [Integer] offset

The offset, in bytes, of the member from the beginning of the
struct.

@param [Type] type

The type of the member.
# File lib/ronin/support/binary/ctypes/struct_type.rb, line 64
def initialize(offset,type)
  @offset = offset
  @type   = type
end
pack_string_for(type,padding=0) click to toggle source

Calculates the pack string for the given type and optional padding.

@param [Type] type

@param [Integer] padding

@return [String]

The pack string for the member.

@api private

# File lib/ronin/support/binary/ctypes/struct_type.rb, line 99
def self.pack_string_for(type,padding=0)
  if padding > 0 then "#{'x' * padding}#{type.pack_string}"
  else                type.pack_string
  end
end
padding_for(offset,type) click to toggle source

Calculates padding for the given type at the given offset.

@param [Integer] offset

@param [Type] type

@return [Integer]

@api private

@see en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding

# File lib/ronin/support/binary/ctypes/struct_type.rb, line 82
def self.padding_for(offset,type)
  (type.alignment - (offset % type.alignment)) % type.alignment
end

Public Instance Methods

alignment() click to toggle source

The alignment, in bytes, of the member within the struct.

@return [Integer]

# File lib/ronin/support/binary/ctypes/struct_type.rb, line 119
def alignment
  @type.alignment
end
size() click to toggle source

The size, in bytes, of the member within the struct.

@return [Integer]

# File lib/ronin/support/binary/ctypes/struct_type.rb, line 110
def size
  @type.size
end