decode_format specification
The format string consists of a set of characters which indicate the type of argument for each relative position. The format characters for the encode function are:
a fixed width string, right padded with NULLs
A fixed width string, right padded with spaces
B bignum (encoded as a null terminated string)
d double (8 bytes)
h short (2 bytes, -32768 through 32767))
H unsigned short (2 bytes, 0 through 65535)
i integer (4 bytes, -2147483648 through 2147483647)
I unsigned integer (4 bytes, 0 through 4294967295)
l long long (8 bytes)
L unsigned long long (8 bytes)
N fixed width number (ascii encoded)
p position within the string (only valid for decode)
v variable length binary string up to 65535 bytes
V variable length binary string up to 4294967295 bytes
y byte (-128 through 127)
Y unsigned byte (0 through 255)
Z null terminated string
Modifiers
> encode number using big endian format
< encode number using little endian format
For all format types other than A and N, a number can be specified after the format character to repeat that type some number of times.
The A and N options behaves differently from the other options. Both will always only generate or consume a single fixed-width input value. For the fixed length formats A and N, the encode function will truncate the value if is larger than the specified width of the field.
Format 'i10' means 10 integers whereas format 'A10' means one fixed-width string that is 10 characters wide. 'N5' means a fixed-width table.maxndecnumber that is 5 characters wide.
The l and L (long long) formats only support 53 bits of information due to Lua's number format being a double which uses 53 bits to store the number and 11 bits to store the exponent.
The < and > operators apply to a single format character. The format string 'i>ii<' encodes the first integer using big endian, the second using native encoding (the default), and the third number using little endian format. The format string 'i10>' indicates to encode 10 integers using big endian format.