BinaryRange class

Helper class for decoding binary data.

A binary range represents a sequence of bytes to be decoded. As bytes are processed, they are removed from the beginning of the sequence.

The binary range maintains a reference to the bytes. It does not make a copy of them. Therefore, the program should not modify the bytes until after the binary range is no longer needed.

Methods are available to remove bytes from the beginning of the binary range.

For length-value pairs, which are represented by a 32-bit unsigned length (i.e. four bytes) followed by that number of bytes for the value:

  • nextBinary - sequence of bytes
  • nextMPInt - multiple precision integer (BigInt)
  • nextString - sequence of bytes interpreted as a UTF-8 encoded string
  • nextUint32 - big-ending 32-bit unsigned integer

For removing a sequence of bytes (without using the next four bytes as the length), use nextRawBytes or allRawBytes.

The amount of bytes remaining can be determined using isEmpty, isNotEmpty and length.

Constructors

BinaryRange(Uint8List bytes, {int? begin, int? end})
Creates a new binary range from the bytes, starting at the begin offset and ending at the end offset.
BinaryRange.copy(BinaryRange original)
Creates a new binary range with the same values as another binary range.

Properties

hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Tests if there are zero bytes in the range.
no setter
isNotEmpty bool
Tests if there are one or more bytes in the range.
no setter
length int
Number of bytes in the range.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

allRawBytes() Uint8List
Returns a copy of all the bytes in the range.
nextBinary() BinaryRange
Extracts an arbitrary length binary string from the range.
nextMPInt() BigInt
Extracts a multiple precision integer from the range.
nextRawBytes(int length) Uint8List
Extract a sequence of bytes from the range.
nextString({Encoding encoding = utf8}) String
Extracts an arbitrary length UTF-8 string from the range.
nextUint32() int
Extracts a big-endian 32-bit unsigned integer from the range.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited