pub struct DataVersions<const N: usize> { /* private fields */ }Expand description
A fixed-capacity table of §7.10.3’s cluster data versions.
N is how many cluster instances the node has — endpoints times the clusters on each, which
is const data, so the number is known when the node is designed. A table that fills stops
tracking new instances rather than evicting a live one: an evicted version would be handed
out again later and tell a client its cache is current when it is not, which is worse than
having no version at all.
Implementations§
Source§impl<const N: usize> DataVersions<N>
impl<const N: usize> DataVersions<N>
Sourcepub fn new(seed: u32) -> Self
pub fn new(seed: u32) -> Self
An empty table whose first version is derived from seed.
§7.10.3: “A cluster data version SHALL be initialized randomly when it is first
published.” seed should come from Rng. Starting every cluster
at zero on every boot is what lets a client keep a cache across a device’s restart and be
wrong about it: the versions match, the data does not.
Sourcepub fn drain_changes(&self) -> Vec<(EndpointId, ClusterId), N>
pub fn drain_changes(&self) -> Vec<(EndpointId, ClusterId), N>
The cluster instances whose data changed since this was last called, and clears them.
Drained rather than read, because the caller is expected to hand each one to
SubscriptionTable::note_cluster_change
and a change reported twice is a report sent twice.
This is the seam between “a cluster changed” and “a subscriber is owed a report”. Writes
that arrive through the interaction model land here on their own; a cluster that changes
on its own — a sensor reading, a switch somebody pressed — is the one that has to call
DataVersionSource::touch, which §7.10.3 requires of it regardless.