nextUint32 method

int nextUint32()

Extracts a big-endian 32-bit unsigned integer from the range.

Returns the value represented by the first four bytes of the range and removes those four bytes from the range.

Throws a BadEncoding if there are insufficient bytes in the range.

Implementation

int nextUint32() {
  if (_end < _begin + 4) {
    // Less than 4 bytes left: not enough for a 32-bit value
    throw KeyBad('data incomplete (for 32-bit unsigned integer)');
  }

  final a = Uint8List.fromList([
    _bytes[_begin + 3],
    _bytes[_begin + 2],
    _bytes[_begin + 1],
    _bytes[_begin]
  ]);
  final value = a.buffer.asUint32List().first;

  _begin += 4;

  return value;
}