pub struct Coverage { /* private fields */ }Expand description
A bitmap over discovery-block indices: bit i records whether block i
(bytes [i * DISCOVERY_BLOCK_BYTES, (i + 1) * DISCOVERY_BLOCK_BYTES)) is
covered.
Bit-packed as Vec<u8>: bit i lives at byte i / 8, bit position
i % 8 (little-endian within the byte). Serializes over postcard as a
length-prefixed byte vector — cheap on the wire and trivial to union/merge
byte-wise if a future caller needs to.
Carries no num_blocks field. A Coverage built locally (via
Self::from_block_indices / Self::full) leaves the trailing partial
byte’s unused high bits zero. A Coverage deserialized from untrusted
wire does not: the byte length only rounds the block count up to the next
multiple of 8, and nothing on the wire pins the exact count, so a peer may
set spurious high bits in that trailing byte. Self::covers and
Self::covered_blocks report the raw bits as-is, so such a bit makes
covers(i) true for an i past the blob’s real block count. Consumers MUST
clamp interpretation to the blob’s own num_blocks(total_bytes) — query
only i < num_blocks, and ignore any Self::covered_blocks index beyond
it. The signed size, not the bitmap, is the authority on how many blocks
exist.
Implementations§
Source§impl Coverage
impl Coverage
Sourcepub fn from_block_indices(
num_blocks: u32,
set: impl Iterator<Item = u32>,
) -> Self
pub fn from_block_indices( num_blocks: u32, set: impl Iterator<Item = u32>, ) -> Self
Builds a Coverage sized for num_blocks blocks with exactly the
indices from set covered. Indices >= num_blocks in set are
dropped rather than growing the bitmap past its declared size.
Sourcepub fn covered_blocks(&self) -> impl Iterator<Item = u32> + '_
pub fn covered_blocks(&self) -> impl Iterator<Item = u32> + '_
Iterates the covered block indices in ascending order. Reports raw set
bits: a Coverage from untrusted wire may yield indices past the blob’s
real block count (see the type doc), so a consumer bounds these against
its own num_blocks(total_bytes).