Module el.bytes
Manage raw byte arrays.
Info:
- Author: Michael Fisher
Functions
new (size) | Create a new byte array. |
free (bytes) | Free used memory. |
get (obj, index) | Get a byte from the array. |
rawget (data, index) | Get a byte from a raw memory block. |
set (obj, index, value) | Set a byte in the array. |
rawset (data, index, value) | Set a byte in the array. |
toraw (obj) | Get the raw data as lightuserdata. |
size (obj) | Returns the size in bytes. |
pack (b1, b2, b3, b4) | Pack 4 bytes in a 64bit integer. |
Functions
- new (size)
-
Create a new byte array.
Parameters:
- size int Size in bytes to allocate
Returns:
-
el.Bytes
The new byte array.
- free (bytes)
-
Free used memory.
Parameters:
- bytes The array to free
- get (obj, index)
-
Get a byte from the array.
Parameters:
- obj el.Bytes The Bytes to retrieve from
- index int Index in the array
- rawget (data, index)
-
Get a byte from a raw memory block.
Parameters:
- data lightuserdata Raw data pointer.
- index int Index in the array
Usage:
-- Raw access is useful when reading MIDI data like SysEx. local msg = get_the_message() -- msg is a `el.MidiMessage` if msg:isSysEx() then local data, _ = msg:sysExData() -- its "1 + .." because MIDI channels start at one, and the data is zero indexed local sysexValue = bytes.rawget (data, 5) -- special sysex handling follows... end
- set (obj, index, value)
-
Set a byte in the array.
Parameters:
- obj el.Bytes The Bytes object to modify
- index int Index in the array
- value int Value to set in the range 0x00 to 0xFF inclusive
- rawset (data, index, value)
-
Set a byte in the array.
Sets a byte in a raw data buffer.
Parameters:
- data lightuserdata Target bytes to modify
- index int Index in the array
- value int Value to set in the range 0x00 to 0xFF inclusive
- toraw (obj)
-
Get the raw data as lightuserdata.
Parameters:
- obj el.Bytes The byte array to get raw data from.
Returns:
-
el.Bytes
The new byte array.
- size (obj)
-
Returns the size in bytes.
Parameters:
- obj el.Bytes The Bytes object to check.
Returns:
-
int
The size in bytes.
- pack (b1, b2, b3, b4)
-
Pack 4 bytes in a 64bit integer.
Undefined params are treated as zero. This function does not check arguments
and therefor can crash if client code passes in bad data.
Parameters:
- b1 int First byte
- b2 int Second byte
- b3 int Third byte
- b4 int Fourth byte
Returns:
-
int
Packed lua_Integer