Skip to content

0.3.0 - Big refactor

Latest
Compare
Choose a tag to compare
@robik robik released this 26 Aug 16:22

This release features major breaking changes trying to make library more consistent.

Format Changes

  • Numbers in format strings mean static arrays. Thus 2c and cc 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 in BinaryWriter changes. E.g. dynamic array of type int 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 in Exception.
  • 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 to formatStringOf and no longer returns chars. It also adds type prefixes for dynamic and static arrays. For static arrays, array length is passed (e.g. formatStringOf!(char[5]) is 5c). Dynamic arrays are prefixed with *.
  • Invalid type passed to formatStringOf results in static assert failure.