Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/binary/core_ext/float.rb

Instance Method Summary collapse

Instance Method Details

#pack(argument, **kwargs) ⇒ String

Packs the Float into a String.

The desired architecture of the binary format.

The Operating System name to lookup.

Examples:

using Array#pack format string:

0.42.pack('F')
# => =\n\xD7>"

0x42.pack(:float_be)
# => ">\xD7\n="

Parameters:

Options Hash (**kwargs):

  • :endian (:little, :big, :net, nil)

    The desired endianness of the binary format.

  • :arch (:x86, :x86_64, :ppc, :ppc64, :mips, :mips_le, :mips_be, :mips64, :mips64_le, :mips64_be, :arm, :arm_le, :arm_be, :arm64, :arm64_le, :arm64_be)
  • :os (:linux, :macos, :windows, :bsd, :freebsd, :openbsd, :netbsd)

Returns:

  • (String)

    The packed float.

Raises:

  • (ArgumentError)

    The given argument was not a String, Symbol, or valid type name.

See Also:

Since:

  • 0.5.0



69
70
71
72
73
74
75
76
77
78
# File 'lib/ronin/support/binary/core_ext/float.rb', line 69

def pack(argument, **kwargs)
  case argument
  when String
    [self].pack(argument)
  else
    types = Ronin::Support::Binary::CTypes.platform(**kwargs)
    type  = types[argument]
    type.pack(self)
  end
end