decode_format の指定
書式制御ストリングは、それぞれの相対位置に対する引数の型を示す一連の文字で構成されています。encode 関数の書式制御文字は以下のとおりです。
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 formatA および N 以外のすべてのフォーマット・タイプでは、書式制御文字の後に数値を指定して、そのタイプを特定の回数繰り返すことができます。
A および N のオプションは、他のオプションとは異なる振る舞いをします。両方とも、常に単一固定幅入力値を生成または消費するのみです。固定長フォーマット A および N では、encode 関数は、フィールドの指定された幅より長い場合、値を切り捨てます。
フォーマット「i10」は、10 個の整数を意味し、一方で「A10」は 10 文字幅の 1 個の固定幅ストリングを意味します。「N5」は、5 文字幅の固定幅 table.maxndecnumber を意味します。
Lua の数字フォーマットは、数字の格納に 53 ビットを使用し、指数の格納に 11 ビットを使用している倍精度 (double) であるため、l および L (long long) のフォーマットは 53 ビットの情報をサポートするのみです。
< and > 演算子は、単一書式制御文字に適用されます。書式制御ストリング「i>ii<」は、ビッグ・エンディアンを使用して最初の整数をエンコードし、ネイティブ・エンコード方式 (デフォルト) を使用して 2 番目をエンコードし、リトル・エンディアン・フォーマットを使用して 3 番目の数値をエンコードします。書式制御ストリング「i10>」は、ビッグ・エンディアン・フォーマットを使用して 10 個の整数をエンコードすることを指定します。