Skip to main content

ReportAccumulator

Struct ReportAccumulator 

Source
pub struct ReportAccumulator { /* private fields */ }
Expand description

Accumulates attribute reports across chunked ReportData messages and produces the final concrete (path, value) set.

  • Replace items set the attribute’s value; the newest DataVersion wins when the same attribute is replaced more than once.
  • Append items (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 chunks

Implementations§

Source§

impl ReportAccumulator

Source

pub fn new() -> Self

Create an empty accumulator with the default total-size ceiling (DEFAULT_MAX_ELEMENTS / DEFAULT_MAX_BYTES).

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for ReportAccumulator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.