Class: Hexdump::Type Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hexdump/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.

Since:

  • 1.0.0

Direct Known Subclasses

Float, Int, UInt

Defined Under Namespace

Classes: Char, Float, Float32, Float64, Int, Int16, Int32, Int64, Int8, UChar, UInt, UInt16, UInt32, UInt64, UInt8

Constant Summary collapse

NATIVE_ENDIAN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The native endian-ness.

Since:

  • 1.0.0

if [0x1].pack('I') == [0x1].pack('N')
  :big
else
  :little
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size:, endian: nil, signed:) ⇒ Type

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 type.

Parameters:

  • size (1, 2, 4, 8)

    The type's size in bytes.

  • endian (:little, :big, nil) (defaults to: nil)

    The endianness of the type. nil indicates the type has no endianness.

  • signed (Boolean)

    Indicates whether the type is signed or unsigned.

Raises:

  • (ArgumentError)

    Invalid endian: or size: values.

Since:

  • 1.0.0



34
35
36
37
38
# File 'lib/hexdump/type.rb', line 34

def initialize(size: , endian: nil, signed: )
  @endian = endian
  @size   = size
  @signed = signed
end

Instance Attribute Details

#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.

Returns:

  • (:little, :big, nil)

Since:

  • 1.0.0



12
13
14
# File 'lib/hexdump/type.rb', line 12

def endian
  @endian
end

#size1, ... (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.

Returns:

  • (1, 2, 4, 8)

Since:

  • 1.0.0



17
18
19
# File 'lib/hexdump/type.rb', line 17

def size
  @size
end

Instance Method Details

#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 type is signed.

Returns:

  • (Boolean)

Since:

  • 1.0.0



45
46
47
# File 'lib/hexdump/type.rb', line 45

def signed?
  @signed
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 type is unsigned.

Returns:

  • (Boolean)

Since:

  • 1.0.0



54
55
56
# File 'lib/hexdump/type.rb', line 54

def unsigned?
  !@signed
end