parse static method
Parses a filter starting at offset; next reports the end offset.
Implementation
static ({BloomFilter filter, int next}) parse(
Uint8List source, [
int offset = 0,
]) {
if (offset + 5 > source.length) {
throw VxsFormatException('bloom filter header truncated', offset: offset);
}
final bitCount = VxsLe.u32(source, offset);
final hashCount = source[offset + 4];
final byteLength = (bitCount + 7) >> 3;
final start = offset + 5;
final end = start + byteLength;
if (bitCount == 0 || end > source.length) {
throw VxsFormatException('bloom filter is truncated', offset: offset);
}
if (hashCount == 0 || hashCount > 32) {
throw VxsFormatException(
'invalid bloom probe count $hashCount',
offset: offset + 4,
);
}
return (
filter: BloomFilter._(
Uint8List.sublistView(source, start, end),
hashCount,
),
next: end,
);
}