Array behavior (All examples in little endian)
Type spec. | Data | Description | Encoded
int(i) | [12, 21] | Written element by element | [0, 0, 0, 12, 0, 0, 0, 21] int[](*i) | [12, 21] | Length and elements written | [0, 0, 0, 2, 0, 0, 0, 12, 0, 0, 0, 21] int[2](2i) | [12, 21] | Written same as i | [0, 0, 0, 12, 0, 0, 0, 21] int[1](1i) | [12, 21] | Only 1 element is written | [0, 0, 0, 12]
Quick Notes: - s is an alias for Sx - To write strings like all other arrays use *c format. - In pack using #i on array of elements will write exacly # elements. If array is too big it is sliced, if too small range error is thrown.
Params: format = Format specifier endianess = Endianess to use, Endian.Native is default values... = Values to encode
Encodes data to binary.
This function packs all specified values into binary data and returns it. Any invalid character specified in format string results in static assert failure.
Available modifier characters
Character | Effect
c | char | 1 b | byte | 1 B | ubyte | 1 h | short | 2 H | ushort | 2 i | int | 4 I | uint | 4 p | ptrdiff_t| 4/8 P | size_t | 4/8 l | long | 8 L | ulong | 8 f | float | 4 d | double | 8 s | string | string length + nul S | string | string length x | - | 1 (zero byte) X | - | Skip/Pad to position