Class: Ronin::Support::Binary::CTypes::UnboundedArrayType Private
- Inherits:
-
AggregateType
- Object
- Type
- AggregateType
- Ronin::Support::Binary::CTypes::UnboundedArrayType
- Defined in:
- lib/ronin/support/binary/ctypes/unbounded_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 an unbounded array type.
Instance Attribute Summary collapse
-
#type ⇒ Type
readonly
private
The type of each element in the unbounded array type.
Attributes inherited from Type
Instance Method Summary collapse
-
#align(new_alignment) ⇒ ScalarType
private
Creates a copy of the unbounded array type with a different #alignment.
-
#alignment ⇒ Integer
private
The alignment, in bytes, for the unbounded array.
-
#dequeue_value(values) ⇒ Array
private
Dequeues an array from the flat list of values.
-
#endian ⇒ :little, ...
private
The endianness of each element in the unbounded array.
-
#enqueue_value(values, array) ⇒ Object
private
Enqueues an array of values onto the flat list of values.
-
#initialize(type, alignment: nil) ⇒ UnboundedArrayType
constructor
private
Initializes the unbounded array type.
-
#length ⇒ Float::INFINITY
private
The "length" of the unbounded 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.
-
#size ⇒ Float::INFINITY
private
The "size" in bytes of the unbounded array type.
-
#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, alignment: nil) ⇒ UnboundedArrayType
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 unbounded array type.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 49 def initialize(type, alignment: nil) if type.kind_of?(UnboundedArrayType) raise(ArgumentError,"cannot initialize a nested #{UnboundedArrayType}") end @type = type @alignment = alignment super( # "T*" syntax only works on individual pack-string codes, # so we only set #pack_string for scalar types that also have # a #pack_string. pack_string: if @type.kind_of?(ScalarType) && @type.pack_string "#{@type.pack_string}*" end ) end |
Instance Attribute Details
#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 unbounded array type.
38 39 40 |
# File 'lib/ronin/support/binary/ctypes/unbounded_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 unbounded array type with a different #alignment.
95 96 97 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 95 def align(new_alignment) self.class.new(@type, 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 unbounded array.
81 82 83 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 81 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.
218 219 220 221 222 223 224 225 226 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 218 def dequeue_value(values) array = [] until values.empty? array << @type.dequeue_value(values) end return array 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 unbounded array.
115 116 117 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 115 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.
201 202 203 204 205 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 201 def enqueue_value(values,array) array.each do |element| @type.enqueue_value(values,element) end end |
#length ⇒ Float::INFINITY
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 unbounded array type.
104 105 106 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 104 def length Float::INFINITY end |
#pack(array) ⇒ String
Packs an array of values into the type's binary format.
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 148 def pack(array) if @pack_string super(array) else buffer = String.new array.each do |element| buffer << @type.pack(element) 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.
124 125 126 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 124 def signed? @type.signed? end |
#size ⇒ Float::INFINITY
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" in bytes of the unbounded array type.
72 73 74 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 72 def size Float::INFINITY end |
#unpack(data) ⇒ Array<Integer, Float, String, nil>
Unpacks an array of binary data.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 173 def unpack(data) if @pack_string super(data) else case @type when StringType unpack_strings(data) else type_size = @type.size (0...data.bytesize).step(type_size).map do |offset| @type.unpack(data.byteslice(offset,type_size)) end 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.
133 134 135 |
# File 'lib/ronin/support/binary/ctypes/unbounded_array_type.rb', line 133 def unsigned? @type.unsigned? end |