class Ronin::Support::Binary::CTypes::Type

Base class for all types.

@api private

@since 1.0.0

Attributes

pack_string[R]

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

new(pack_string: ) click to toggle source

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

[](length=nil) click to toggle source

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
align(new_alignment) click to toggle source

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
alignment() click to toggle source

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
dequeue_value(values) click to toggle source

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
enqueue_value(values,value) click to toggle source

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
pack(value) click to toggle source

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
size() click to toggle source

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
uninitialized_value() click to toggle source

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
unpack(data) click to toggle source

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