Class: Ronin::Support::Binary::CTypes::ScalarType Private
- Defined in:
- lib/ronin/support/binary/ctypes/scalar_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.
Base class for all scalar types.
Instance Attribute Summary collapse
-
#alignment ⇒ Integer
readonly
private
The alignment in bytes for the scalar type.
-
#endian ⇒ :little, ...
readonly
private
The endian-ness of the type.
-
#signed ⇒ Boolean
readonly
private
Indicates whether the type is signed.
-
#size ⇒ 1, ...
readonly
private
The size in bytes of the type.
Attributes inherited from Type
Instance Method Summary collapse
-
#align(new_alignment) ⇒ ScalarType
private
Creates a copy of the scalar type with a different #alignment.
-
#dequeue_value(values) ⇒ Integer, ...
private
Dequeues a scalar value from the flat list of values.
-
#enqueue_value(values, value) ⇒ Object
private
Enqueues a scalar value onto the flat list of values.
-
#initialize(size:, alignment: size, endian:, signed:, **kwargs) ⇒ ScalarType
constructor
private
Initializes the scalar type.
-
#pack(value) ⇒ String
Packs the value into the scalar type's binary format.
-
#signed? ⇒ Boolean
private
Whether the scalar type is signed.
-
#unpack(data) ⇒ Integer, ...
Unpacks the binary data.
-
#unsigned? ⇒ Boolean
private
Whether the scalar type is unsigned.
Methods inherited from Type
Constructor Details
#initialize(size:, alignment: size, endian:, signed:, **kwargs) ⇒ 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.
Initializes the scalar type.
76 77 78 79 80 81 82 83 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 76 def initialize(size: , alignment: size, endian: , signed: , **kwargs) super(**kwargs) @endian = endian @size = size @alignment = alignment @signed = signed end |
Instance Attribute Details
#alignment ⇒ 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 alignment in bytes for the scalar type.
42 43 44 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 42 def alignment @alignment end |
#endian ⇒ :little, ... (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 endian-ness of the type.
47 48 49 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 47 def endian @endian end |
#signed ⇒ Boolean (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.
Indicates whether the type is signed.
52 53 54 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 52 def signed @signed end |
#size ⇒ 1, ... (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 in bytes of the type.
37 38 39 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 37 def size @size 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 scalar type with a different #alignment.
112 113 114 115 116 117 118 119 120 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 112 def align(new_alignment) self.class.new( size: @size, alignment: new_alignment, endian: @endian, signed: @signed, pack_string: @pack_string ) end |
#dequeue_value(values) ⇒ 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.
Dequeues a scalar value from the flat list of values.
192 193 194 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 192 def dequeue_value(values) values.shift end |
#enqueue_value(values, value) ⇒ 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 a scalar value onto the flat list of values.
177 178 179 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 177 def enqueue_value(values,value) values.push(value) end |
#pack(value) ⇒ String
Packs the value into the scalar type's binary format.
136 137 138 139 140 141 142 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 136 def pack(value) if @pack_string [value].pack(@pack_string) else raise(NotImplementedError,"#{self.class} does not define a #pack_string") 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.
Whether the scalar type is signed.
90 91 92 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 90 def signed? @signed end |
#unpack(data) ⇒ Integer, ...
Unpacks the binary data.
158 159 160 161 162 163 164 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 158 def unpack(data) if @pack_string data.unpack1(@pack_string) else raise(NotImplementedError,"#{self.class} does not define a #pack_string") 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.
Whether the scalar type is unsigned.
99 100 101 |
# File 'lib/ronin/support/binary/ctypes/scalar_type.rb', line 99 def unsigned? !@signed end |