class Ronin::Support::Binary::CTypes::Type
Base class for all types.
@api private
@since 1.0.0
Attributes
The String
for ‘Array#pack` or `String#unpack`.
@return [String, nil]
@note
May return `nil` if the type does not map to a Ruby pack-string.
Public Class Methods
Initializes the type.
@param [String, nil] pack_string
The String for `Array#pack` or `String#unpack`.
# File lib/ronin/support/binary/ctypes/type.rb, line 46 def initialize(pack_string: ) @pack_string = pack_string end
Public Instance Methods
Creates an Array
type around the scalar type.
@param [Integer, nil] length
The length of the Array.
@return [ArrayType, UnboundedArrayType]
The new Array type or an unbounded Array type if `length` was not given.
# File lib/ronin/support/binary/ctypes/type.rb, line 60 def [](length=nil) if length then ArrayType.new(self,length) else UnboundedArrayType.new(self) end end
Creates a copy of the type with a different {#alignment}.
@param [Integer] new_alignment
The new alignment for the new type.
@return [Type]
The new type.
@abstract
@api public
# File lib/ronin/support/binary/ctypes/type.rb, line 117 def align(new_alignment) raise(NotImplementedError,"#{self.class}##{__method__} was not implemented") end
The alignment, in bytes, for the type.
@return [Integer]
@abstract
@api public
# File lib/ronin/support/binary/ctypes/type.rb, line 100 def alignment raise(NotImplementedError,"#{self.class}##{__method__} was not implemented") end
Dequeues a value from the flat list of values.
@param [Array] values
The flat array of values.
@return [Object]
The dequeued value.
@abstract
@api private
# File lib/ronin/support/binary/ctypes/type.rb, line 185 def dequeue_value(values) raise(NotImplementedError,"#{self.class}##{__method__} was not implemented") end
Enqueues a value onto the flat list of values.
@param [Array] values
The flat array of values.
@param [Object] value
The value to enqueue.
@abstract
@api private
# File lib/ronin/support/binary/ctypes/type.rb, line 168 def enqueue_value(values,value) raise(NotImplementedError,"#{self.class}##{__method__} was not implemented") end
Packs the value into the type’s binary format.
@param [Object] value
The value to pack.
@return [String]
The packed binary data.
@abstract
@api public
# File lib/ronin/support/binary/ctypes/type.rb, line 134 def pack(value) raise(NotImplementedError,"#{self.class}##{__method__} was not implemented") end
The size of the type.
@return [Integer]
The size of the type in bytes.
@abstract
@api public
# File lib/ronin/support/binary/ctypes/type.rb, line 87 def size raise(NotImplementedError,"#{self.class}##{__method__} was not implemented") end
The default uniniitalized value for the type.
@return [nil]
@abstract
# File lib/ronin/support/binary/ctypes/type.rb, line 73 def uninitialized_value nil end
Unpacks the binary data.
@param [String] data
The binary data to unpack.
@return [Object]
The unpacked value.
@abstract
@api public
# File lib/ronin/support/binary/ctypes/type.rb, line 151 def unpack(data) raise(NotImplementedError,"#{self.class}##{__method__} was not implemented") end