writeUint16 method

void writeUint16(
  1. int number
)

Writes number as Uint16 to the sink. If the number is outside valid Uint16 range, it is capped at the appropriate boundary before writing.

Implementation

void writeUint16(int number) {
  // Trim the number at Uint16 boundaries.
  var n = max<int>(0, number.sign * min<int>(number.abs(), (1 << 16) - 1));

  // Write the trimmed number to the sink.
  final byteData = ByteData(2);
  byteData.setUint16(0, n, Endian.little);
  writeBytes(List<int>.generate(
      byteData.lengthInBytes, (index) => byteData.getUint8(index)));
}