class Ronin::Support::Binary::CTypes::ArrayObjectType

Represents a {Binary::Array} in memory.

@api private

@since 1.0.0

Attributes

array_type[R]

The type used for packing literal {::Array} values.

@return [ArrayType]

Public Class Methods

new(array_type) click to toggle source

Initializes the memory-mapped array type.

@param [ArrayType] array_type

The array type.
Calls superclass method
# File lib/ronin/support/binary/ctypes/array_object_type.rb, line 46
def initialize(array_type)
  @array_type = array_type

  super(@array_type.size)
end

Public Instance Methods

align(new_alignment) click to toggle source

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

@param [Integer] new_alignment

The new alignment for the new array object type.

@return [ArrayObjectType]

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

The alignment, in bytes, of the memory-mapped array type.

@return [Integer]

# File lib/ronin/support/binary/ctypes/array_object_type.rb, line 75
def alignment
  @array_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 [Binary::Array]

The dequeued memory-mapped array object.
# File lib/ronin/support/binary/ctypes/array_object_type.rb, line 156
def dequeue_value(values)
  Binary::Array.new(@array_type.type,values.shift)
end
enqueue_value(values,array) click to toggle source

Enqueues the memory-mapped array into the list of values.

@param [Binary::Array, ::Array] values

The flat array of values.

@param [Binary::Array, ::Array] array

The memory-mapped array object to enqueue.
# File lib/ronin/support/binary/ctypes/array_object_type.rb, line 138
def enqueue_value(values,array)
  case array
  when Binary::Array
    values.push(array.to_s)
  when ::Array
    values.push(@array_type.pack(array))
  end
end
length() click to toggle source

The number of elements in the memory-mapped array type.

@return [Integer]

# File lib/ronin/support/binary/ctypes/array_object_type.rb, line 66
def length
  @array_type.length
end
pack(array) click to toggle source

Packs the memory-mapped array.

@param [Binary::Array, ::Array] array

The memory-mapped array.

@return [String]

The underlying binary data for the memory object.

@raise [ArgumentError]

The given value was not a {Binary::Array} or {::Array}.
# File lib/ronin/support/binary/ctypes/array_object_type.rb, line 105
def pack(array)
  case array
  when Binary::Array
    array.to_s
  when ::Array
    @array_type.pack(array)
  else
    raise(ArgumentError,"value must be either a #{Binary::Array} or an #{::Array}: #{array.inspect}")
  end
end
type() click to toggle source

The type of the element in the memory-mapped array type.

@return [Type]

# File lib/ronin/support/binary/ctypes/array_object_type.rb, line 57
def type
  @array_type.type
end
unpack(data) click to toggle source

Unpacks the memory-mapped array.

@param [String] data

The raw binary data to unpack.

@return [Binary::Array]

the memory-mapped Array.
# File lib/ronin/support/binary/ctypes/array_object_type.rb, line 125
def unpack(data)
  Binary::Array.new(@array_type.type,data)
end