decodeBound static method
Decodes a bound. lastTimestamp is the timestamp of the previously
decoded bound in the same message (0 at the start of every message).
Implementation
static (int timestamp, Uint8List idPrefix, int bytesConsumed) decodeBound(
Uint8List data, [
int offset = 0,
int lastTimestamp = 0,
]) {
var pos = offset;
final (encodedTimestamp, timestampBytes) = decodeVarint(data, pos);
pos += timestampBytes;
final int timestamp;
if (encodedTimestamp == 0) {
timestamp = infiniteTimestamp;
} else {
timestamp = lastTimestamp + encodedTimestamp - 1;
if (timestamp >= infiniteTimestamp) {
throw ArgumentError('Bound timestamp out of range');
}
}
final (prefixLength, lengthBytes) = decodeVarint(data, pos);
pos += lengthBytes;
if (prefixLength > idSize) {
throw ArgumentError('Bound ID prefix too long: $prefixLength');
}
if (pos + prefixLength > data.length) {
throw ArgumentError('Truncated bound ID prefix');
}
final idPrefix = Uint8List.fromList(data.sublist(pos, pos + prefixLength));
pos += prefixLength;
return (timestamp, idPrefix, pos - offset);
}