Class: Ronin::Support::Binary::CTypes::ArrayType Private
- Inherits:
-
AggregateType
- Object
- Type
- AggregateType
- Ronin::Support::Binary::CTypes::ArrayType
- Defined in:
- lib/ronin/support/binary/ctypes/array_type.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents a bounded array type.
Instance Attribute Summary collapse
-
#length ⇒ Integer
readonly
private
The length of the array type.
-
#size ⇒ Integer
readonly
private
The size of the array type.
-
#type ⇒ Type
readonly
private
The type of each element in the array type.
Attributes inherited from Type
Instance Method Summary collapse
-
#align(new_alignment) ⇒ ScalarType
private
Creates a copy of the array type with a different #alignment.
-
#alignment ⇒ Integer
private
The alignment, in bytes, for the array type.
-
#dequeue_value(values) ⇒ ::Array
private
Dequeues an array from the flat list of values.
-
#endian ⇒ :little, ...
private
The endianness of each element in the bounded array type.
-
#enqueue_value(values, array) ⇒ Object
private
Enqueues an array of values onto the flat list of values.
-
#initialize(type, length, alignment: nil) ⇒ ArrayType
constructor
private
Initializes the array type.
-
#pack(array) ⇒ String
Packs an array of values into the type's binary format.
-
#signed? ⇒ Boolean
private
Indicates whether each element is signed.
-
#uninitialized_value ⇒ ::Array
private
Initializes an Array of uninitialized values.
-
#unpack(data) ⇒ ::Array<Integer, Float, String, nil>
Unpacks an array of binary data.
-
#unsigned? ⇒ Boolean
private
Indicates whether each element is unsigned.
Methods inherited from Type
Constructor Details
#initialize(type, length, alignment: nil) ⇒ ArrayType
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the array type.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 62 def initialize(type,length, alignment: nil) if type.kind_of?(UnboundedArrayType) raise(ArgumentError,"cannot initialize an #{self.class} of #{UnboundedArrayType}") end @type = type @length = length @size = @type.size * @length @alignment = alignment super( pack_string: if @type.pack_string @type.pack_string * @length end ) end |
Instance Attribute Details
#length ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The length of the array type.
43 44 45 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 43 def length @length end |
#size ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The size of the array type.
48 49 50 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 48 def size @size end |
#type ⇒ Type (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The type of each element in the array type.
38 39 40 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 38 def type @type end |
Instance Method Details
#align(new_alignment) ⇒ ScalarType
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a copy of the array type with a different #alignment.
118 119 120 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 118 def align(new_alignment) self.class.new(@type,@length, alignment: new_alignment) end |
#alignment ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The alignment, in bytes, for the array type.
105 106 107 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 105 def alignment @alignment || @type.alignment end |
#dequeue_value(values) ⇒ ::Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Dequeues an array from the flat list of values.
222 223 224 225 226 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 222 def dequeue_value(values) ::Array.new(@length) do @type.dequeue_value(values) end end |
#endian ⇒ :little, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The endianness of each element in the bounded array type.
96 97 98 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 96 def endian @type.endian end |
#enqueue_value(values, array) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Enqueues an array of values onto the flat list of values.
203 204 205 206 207 208 209 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 203 def enqueue_value(values,array) @length.times do |index| value = array[index] || @type.uninitialized_value @type.enqueue_value(values,value) end end |
#pack(array) ⇒ String
Packs an array of values into the type's binary format.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 151 def pack(array) if @pack_string super(array) else buffer = String.new @length.times do |index| value = array[index] || @type.uninitialized_value buffer << @type.pack(value) end return buffer end end |
#signed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates whether each element is signed.
127 128 129 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 127 def signed? @type.signed? end |
#uninitialized_value ⇒ ::Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes an Array of uninitialized values.
85 86 87 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 85 def uninitialized_value ::Array.new(@length) { @type.uninitialized_value } end |
#unpack(data) ⇒ ::Array<Integer, Float, String, nil>
Unpacks an array of binary data.
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 178 def unpack(data) if @pack_string super(data) else type_size = @type.size ::Array.new(@length) do |index| offset = index * type_size @type.unpack(data.byteslice(offset,type_size)) end end end |
#unsigned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates whether each element is unsigned.
136 137 138 |
# File 'lib/ronin/support/binary/ctypes/array_type.rb', line 136 def unsigned? @type.unsigned? end |