nextBinary method

BinaryRange nextBinary()

Extracts an arbitrary length binary string from the range.

Extracts an uint32 which indicates the number of following bytes that make up the string value. The string does not have to be, and probably isn't, null terminated.

Returns a new binary range consisting of the string's bytes. The result shares the same underlying bytes. The bytes making up the length and the string are removed from the range.

This method is similar to nextString, except the contents are not interpreted as UTF-8.

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

Implementation

BinaryRange nextBinary() {
  final length = nextUint32();

  if (_end < _begin + length) {
    throw KeyBad('data incomplete (for $length byte binary data)');
  }

  final result = BinaryRange(_bytes, begin: _begin, end: _begin + length);

  _begin += length;

  return result;
}