This release features major breaking changes trying to make library more consistent.
Format Changes
-
Numbers in format strings mean static arrays. Thus
2c
andcc
are not the same any more.data.unpack!`2i` // tuple(int[2]) data.unpack!`ii` // tuple(int, int)
-
Added
*
as syntax for dynamic arrays. Details of serializing dynamic arrays are described inBinaryWriter
changes. E.g. dynamic array of typeint
is*i
. -
Arrays passed to pack with format string being single type are written as static arrays (without length).
pack!`<*h`([2,3]) // [2, 0, 0, 0, 2, 0, 3, 0] pack!`<h`([2,3]) // [2, 0, 3, 0]
Writer and Reader
BinaryWriter
- Dynamic arrays and strings are serialized as array length (always 4-byte uint) followed by array contents. Trying to write array with length bigger than
uint.max
results inException
. - Static arrays are serialized as-is, without terminator and length.
- Strings can be written with null terminator with
writeString
- Dynamic arrays can be written without length using
writeArray
BinaryReader
- Behavior changed to match
BinaryWriter
behavior.
More internal breakages
formatCharOf
is renamed toformatStringOf
and no longer returnschar
s. It also adds type prefixes for dynamic and static arrays. For static arrays, array length is passed (e.g.formatStringOf!(char[5])
is5c
). Dynamic arrays are prefixed with*
.- Invalid type passed to
formatStringOf
results in static assert failure.