Module binary
read and write (little endian) binary.
This is apart of the LEEF-filesystem module.
reading binary inputs
read_single (read_byte) | read an IEEE 754 single precision (32-bit) floating point number |
read_double (read_byte) | read an IEEE 754 double-precision (64-bit) floating point number |
read_uint (read_byte, bytes) | read an unsigned integer of any given length |
read_uint (read_byte, bytes) | read a signed integer of any given length |
writing binary
write_int (write_byte, int, bytes) | write an int |
write_uint (write_byte, uint, bytes) | write a uint |
write_single (write_byte, number) | write a single |
write_double (write_byte, number) | write a double |
misc binary helpers
fround (number) | "returns nearest 32-bit single precision float representation of a number" (or something) |
expected function inputs
read_byte () | read_byte is a param name which refers to a function which reads the next byte- returning a whole number between 0-255. |
write_byte () | write_byte is similar to read_byte, however it is given an input and expected to write it to the file. |
reading binary inputs
read a binary inputs using a
read_byte
function.
- read_single (read_byte)
-
read an IEEE 754 single precision (32-bit) floating point number
Parameters:
- read_byte function read_byte
Returns:
-
number
- read_double (read_byte)
-
read an IEEE 754 double-precision (64-bit) floating point number
Parameters:
- read_byte function read_byte
Returns:
-
number
- read_uint (read_byte, bytes)
-
read an unsigned integer of any given length
Parameters:
- read_byte function read_byte
- bytes number length in bytes of unsigned integer
Returns:
-
number
- read_uint (read_byte, bytes)
-
read a signed integer of any given length
Parameters:
- read_byte function read_byte
- bytes number length in bytes of integer
Returns:
-
number
writing binary
writing binary using a
write_byte
function.
- write_int (write_byte, int, bytes)
-
write an int
Parameters:
- write_byte function write_byte
- int number integer to write
- bytes number bytes number of bytes to write
- write_uint (write_byte, uint, bytes)
-
write a uint
Parameters:
- write_byte function write_byte
- uint number unsigned integer to write
- bytes number number of bytes to write
- write_single (write_byte, number)
-
write a single
Parameters:
- write_byte function write_byte
- number number single precision float to write
- write_double (write_byte, number)
-
write a double
Parameters:
- write_byte function write_byte
- number number double precision float to write
misc binary helpers
- fround (number)
-
"returns nearest 32-bit single precision float representation of a number" (or something)
Parameters:
- number
Returns:
-
nearest 32-bit single precision float representation of a number
expected function inputs
functions will expect either a
read_byte
or write_byte
function as inputs
- read_byte ()
-
read_byte
is a param name which refers to a function which reads the next byte- returning a whole number between 0-255.function byte() left = left - 1 return assert(file_handle:read(1):byte()) --reads the next chracter, and converts it to a "numerical code" using string.byte() --it's important that this function moves forward in the file stream (as :read(1) does) end
Returns:
-
a bytecode (an int between 0 and 255.)
- write_byte ()
-
write_byte
is similar to read_byte, however it is given an input and expected to write it to the file. (example needed)