class Ronin::Support::Binary::CTypes::UnionObjectType

Represents a {Binary::Union} type.

@api private

@since 1.0.0

Attributes

union_class[R]

The {Union} class.

@return [Union.class]

union_type[R]

The type used for packing literal ‘Hash` values.

@return [UnionType]

Public Class Methods

new(union_class,union_type) click to toggle source

Initializes the memory-mapped union type.

@param [Union.class] union_class

The {Union} class.

@param [UnionType] union_type

The union type for the union class.
# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 54
def initialize(union_class,union_type)
  @union_class = union_class
  @union_type  = union_type

  super(@union_type.size)
end

Public Instance Methods

align(new_alignment) click to toggle source

Creates a copy of the union object type with a different {#alignment}.

@param [Integer] new_alignment

The new alignment for the new union object type.

@return [ScalarType]

The new union object type.
# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 89
def align(new_alignment)
  self.class.new(@union_class,@union_type.align(new_alignment))
end
alignment() click to toggle source

The alignment, in bytes, of the memory-mapped {Union}.

@return [Integer]

# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 75
def alignment
  @union_type.alignment
end
dequeue_value(values) click to toggle source

Dequeues a memory object from the flat list of values.

@param [Array] values

The flat array of values.

@return [Union]

The dequued {Union} object.
# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 165
def dequeue_value(values)
  @union_class.new(values.shift)
end
enqueue_value(values,union) click to toggle source

Enqueues the memory-mapped {Union} into the list of values.

@param [Array] values

The flat array of values.

@param [Binary::Union, Hash] union

The {Union} object to enqueue.
# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 147
def enqueue_value(values,union)
  case union
  when Binary::Union
    values.push(union.to_s)
  when Hash
    values.push(@union_type.pack(union))
  end
end
members() click to toggle source

The members of the union type.

@return [Hash{Symbol => UnionType::Member}]

# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 98
def members
  @union_type.members
end
pack(union) click to toggle source

Packs the memory-mapped {Union}.

@param [Binary::Union, Hash] union

The memory-mapped {Union} object.

@return [String]

The underlying binary data for the memory object.

@raise [ArgumentError]

The given value was not a {Binary::Union} or `Hash`.
# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 114
def pack(union)
  case union
  when Binary::Union
    union.to_s
  when Hash
    @union_type.pack(union)
  else
    raise(ArgumentError,"value must be either a #{Binary::Union} or an #{Hash}: #{union.inspect}")
  end
end
size() click to toggle source

The size of the union type.

@return [Integer, Float::INFINITY]

# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 66
def size
  @union_type.size
end
unpack(data) click to toggle source

Unpacks the memory-mapped {Union}.

@param [String] data

The raw binary data to unpack.

@return [Binary::Union]

the unpacked {Union} object.
# File lib/ronin/support/binary/ctypes/union_object_type.rb, line 134
def unpack(data)
  @union_class.unpack(data)
end