--- The Binary Data Library allows to pack and unpack to and from -- binary data. Encoding and decoding works by using a format -- string containing certain operator characters: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
OperatorDescription
Hhex string
Bbit string
xnull byte
zzero-terminated string
pstring preceded by 1-byte integer length
Pstring preceded by 2-byte integer length
astring preceded by 4-byte integer length
Astring
ffloat
ddouble
nLua number
cchar (1-byte integer)
Cbyte = unsigned char (1-byte unsigned integer)
sshort (2-byte integer)
Sunsigned short (2-byte unsigned integer)
iint (4-byte integer)
Iunsigned int (4-byte unsigned integer)
llong (8-byte integer)
Lunsigned long (8-byte unsigned integer)
<little endian modifier
>big endian modifier
=native endian modifier
-- Note that the endian operators work as modifiers to all the -- characters following them in the format string. module "bin" --- Packs values according to format string. -- Note: on Windows packing of 64 bit values > 2^63 currently -- results in packing exactly 2^63. --@param format Format string, used to pack following arguments --@return String containing packed data function bin.pack(format, ...) --- Unpacks values according to format string. --@param format Format string, used to unpack values out of data string --@param data String containing packed data --@param init Optional starting position within the string --@return First returned value is the position in the data string where unpacking stopped, following returned values are the unpacked values. function bin.unpack(format, data, init)