Skip to main content

dlms_cosem_kit/cosem/
selective.rs

1//! Selective access: which part of an attribute a read or a write means.
2//!
3//! The selector's meaning belongs to the interface class, so this is object-model
4//! vocabulary; the application layer carries it (and re-exports it as
5//! `xdlms::SelectiveAccess`).
6
7use crate::axdr::Data;
8use crate::codec::{Decode, Encode, Reader, Result, Writer};
9
10/// A restriction on which part of an attribute is read or written.
11///
12/// The selector's meaning belongs to the interface class: for a profile generic,
13/// selector 1 is a range of entries by capture-object value and selector 2 a range by
14/// entry number.
15#[derive(Debug, Clone, Copy, PartialEq)]
16pub struct SelectiveAccess<'a> {
17    /// Which selector of the class.
18    pub selector: u8,
19    /// Its parameters.
20    pub parameters: Data<'a>,
21}
22
23impl Encode for SelectiveAccess<'_> {
24    fn encode(&self, w: &mut dyn Writer) -> Result<()> {
25        w.write_u8(self.selector)?;
26        self.parameters.encode(w)
27    }
28}
29
30impl<'a> Decode<'a> for SelectiveAccess<'a> {
31    fn decode(r: &mut Reader<'a>) -> Result<Self> {
32        Ok(Self { selector: r.u8()?, parameters: Data::decode(r)? })
33    }
34}