readShort method

Future<int> readShort()

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

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

Implementation

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