readUnsignedShort method

Future<int> readUnsignedShort()

Reads and returns a 2-byte unsigned integer decoded with the current endian setting.

Throws EOFException if EOF is reached before the needed bytes are read.

Implementation

Future<int> readUnsignedShort() async {
  await _ensureNext();
  if (_curr!.length - _pos < 2) {
    // If we're on a buffer boundary
    // Keep it simple
    return (await readByteDataImmutable(2)).getUint16(0, endian);
  } else {
    final result = _curr!.buffer
        .asByteData()
        .getUint16(_pos + _curr!.offsetInBytes, endian);
    _pos += 2;
    return result;
  }
}