pub struct ReportAccumulator { /* private fields */ }Expand description
Accumulates attribute reports across chunked ReportData messages and
produces the final concrete (path, value) set.
Replaceitems set the attribute’s value; the newestDataVersionwins when the same attribute is replaced more than once.Appenditems (ListIndex= null) push one element onto the attribute’s list, starting from an empty list if none was seen.
First-seen attribute order is preserved by finish.
This accumulator enforces an in-crate total-size ceiling as
defense-in-depth: push returns
ImError::AccumulatorOverflow once the number of distinct accumulated
elements or the estimated total byte size would exceed the configured caps
(DEFAULT_MAX_ELEMENTS / DEFAULT_MAX_BYTES, or the values given to
with_limits). This bounds memory even when the
accumulator is driven directly from an untrusted peer streaming an
unbounded chunked read/report set; a caller may still layer its own
chunk-count / wire-byte cap on top (the read-transaction layer does).
§Examples
use matter_interaction::{parse_report_data, ReportAccumulator};
let mut acc = ReportAccumulator::new();
for chunk in chunk_bytes {
acc.push(parse_report_data(chunk)?)?; // errors if the ceiling is exceeded
}
let attributes = acc.finish(); // every attribute across all chunksImplementations§
Source§impl ReportAccumulator
impl ReportAccumulator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty accumulator with the default total-size ceiling
(DEFAULT_MAX_ELEMENTS / DEFAULT_MAX_BYTES).
Sourcepub fn with_limits(max_elements: usize, max_bytes: usize) -> Self
pub fn with_limits(max_elements: usize, max_bytes: usize) -> Self
Create an empty accumulator with explicit caps on the number of distinct accumulated elements and the estimated total byte size.
Use this to tighten the ceiling for a constrained transport, or to
loosen it for an unusually large device. Prefer new
unless you have a concrete reason to override the defaults.
Sourcepub fn push(&mut self, report: ReportData) -> Result<(), ImError>
pub fn push(&mut self, report: ReportData) -> Result<(), ImError>
Merge one parsed ReportData chunk’s items into the accumulated state.
§Errors
Returns ImError::AccumulatorOverflow if merging would push the
number of distinct accumulated elements above the configured element
cap, or the estimated total accumulated byte size above the configured
byte cap. On overflow the offending item is not merged and the
accumulator is left holding only the items accepted before the cap was
reached; the caller should treat the report set as truncated and
discard the transaction.
Sourcepub fn finish(self) -> Vec<(AttributePath, Value)>
pub fn finish(self) -> Vec<(AttributePath, Value)>
Consume the accumulator, yielding (path, value) in first-seen order.
Each Value is moved out of the consumed accumulator rather than
cloned: self.order records every accumulated path exactly once (a path
is pushed only on the first insert for its key — see push),
so a single HashMap::remove per path drains the map without aliasing.
This avoids a full deep copy of every attribute subtree on the
chunked-read / subscription completion path.