#![allow(
clippy::all,
clippy::pedantic,
dead_code,
unreachable_pub,
unused_imports
)]
use crate::datatypes::SemanticTagStruct;
use crate::error::ClusterError;
use crate::types::Nullable;
use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};
pub const CLUSTER_ID: u32 = 0x0101;
pub const CLUSTER_REVISION: u16 = 10;
pub mod command_id {
pub const LOCK_DOOR: u32 = 0x00;
pub const UNLOCK_DOOR: u32 = 0x01;
pub const UNLOCK_WITH_TIMEOUT: u32 = 0x03;
pub const SET_WEEK_DAY_SCHEDULE: u32 = 0x0B;
pub const GET_WEEK_DAY_SCHEDULE: u32 = 0x0C;
pub const GET_WEEK_DAY_SCHEDULE_RESPONSE: u32 = 0x0C;
pub const CLEAR_WEEK_DAY_SCHEDULE: u32 = 0x0D;
pub const SET_YEAR_DAY_SCHEDULE: u32 = 0x0E;
pub const GET_YEAR_DAY_SCHEDULE: u32 = 0x0F;
pub const GET_YEAR_DAY_SCHEDULE_RESPONSE: u32 = 0x0F;
pub const CLEAR_YEAR_DAY_SCHEDULE: u32 = 0x10;
pub const SET_HOLIDAY_SCHEDULE: u32 = 0x11;
pub const GET_HOLIDAY_SCHEDULE: u32 = 0x12;
pub const GET_HOLIDAY_SCHEDULE_RESPONSE: u32 = 0x12;
pub const CLEAR_HOLIDAY_SCHEDULE: u32 = 0x13;
pub const SET_USER: u32 = 0x1A;
pub const GET_USER: u32 = 0x1B;
pub const GET_USER_RESPONSE: u32 = 0x1C;
pub const CLEAR_USER: u32 = 0x1D;
pub const SET_CREDENTIAL: u32 = 0x22;
pub const SET_CREDENTIAL_RESPONSE: u32 = 0x23;
pub const GET_CREDENTIAL_STATUS: u32 = 0x24;
pub const GET_CREDENTIAL_STATUS_RESPONSE: u32 = 0x25;
pub const CLEAR_CREDENTIAL: u32 = 0x26;
pub const UNBOLT_DOOR: u32 = 0x27;
}
pub mod attribute_id {
pub const LOCK_STATE: u32 = 0x0000;
pub const LOCK_TYPE: u32 = 0x0001;
pub const ACTUATOR_ENABLED: u32 = 0x0002;
pub const DOOR_STATE: u32 = 0x0003;
pub const DOOR_OPEN_EVENTS: u32 = 0x0004;
pub const DOOR_CLOSED_EVENTS: u32 = 0x0005;
pub const OPEN_PERIOD: u32 = 0x0006;
pub const NUMBER_OF_TOTAL_USERS_SUPPORTED: u32 = 0x0011;
pub const NUMBER_OF_PIN_USERS_SUPPORTED: u32 = 0x0012;
pub const NUMBER_OF_RFID_USERS_SUPPORTED: u32 = 0x0013;
pub const NUMBER_OF_WEEK_DAY_SCHEDULES_SUPPORTED_PER_USER: u32 = 0x0014;
pub const NUMBER_OF_YEAR_DAY_SCHEDULES_SUPPORTED_PER_USER: u32 = 0x0015;
pub const NUMBER_OF_HOLIDAY_SCHEDULES_SUPPORTED: u32 = 0x0016;
pub const MAX_PIN_CODE_LENGTH: u32 = 0x0017;
pub const MIN_PIN_CODE_LENGTH: u32 = 0x0018;
pub const MAX_RFID_CODE_LENGTH: u32 = 0x0019;
pub const MIN_RFID_CODE_LENGTH: u32 = 0x001A;
pub const CREDENTIAL_RULES_SUPPORT: u32 = 0x001B;
pub const NUMBER_OF_CREDENTIALS_SUPPORTED_PER_USER: u32 = 0x001C;
pub const LANGUAGE: u32 = 0x0021;
pub const LED_SETTINGS: u32 = 0x0022;
pub const AUTO_RELOCK_TIME: u32 = 0x0023;
pub const SOUND_VOLUME: u32 = 0x0024;
pub const OPERATING_MODE: u32 = 0x0025;
pub const SUPPORTED_OPERATING_MODES: u32 = 0x0026;
pub const DEFAULT_CONFIGURATION_REGISTER: u32 = 0x0027;
pub const ENABLE_LOCAL_PROGRAMMING: u32 = 0x0028;
pub const ENABLE_ONE_TOUCH_LOCKING: u32 = 0x0029;
pub const ENABLE_INSIDE_STATUS_LED: u32 = 0x002A;
pub const ENABLE_PRIVACY_MODE_BUTTON: u32 = 0x002B;
pub const LOCAL_PROGRAMMING_FEATURES: u32 = 0x002C;
pub const WRONG_CODE_ENTRY_LIMIT: u32 = 0x0030;
pub const USER_CODE_TEMPORARY_DISABLE_TIME: u32 = 0x0031;
pub const SEND_PIN_OVER_THE_AIR: u32 = 0x0032;
pub const REQUIRE_PIN_FOR_REMOTE_OPERATION: u32 = 0x0033;
pub const EXPIRING_USER_TIMEOUT: u32 = 0x0035;
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Feature: u32 {
const PIN = 1 << 0;
const RID = 1 << 1;
const FGP = 1 << 2;
const WDSCH = 1 << 4;
const DPS = 1 << 5;
const FACE = 1 << 6;
const COTA = 1 << 7;
const USR = 1 << 8;
const YDSCH = 1 << 10;
const HDSCH = 1 << 11;
const UBOLT = 1 << 12;
const ALIRO = 1 << 13;
const ALBU = 1 << 14;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AlarmCodeEnum {
LockJammed,
LockFactoryReset,
LockRadioPowerCycled,
WrongCodeEntryLimit,
FrontEsceutcheonRemoved,
DoorForcedOpen,
DoorAjar,
ForcedUser,
Unknown(u8),
}
impl AlarmCodeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::LockJammed,
1 => Self::LockFactoryReset,
3 => Self::LockRadioPowerCycled,
4 => Self::WrongCodeEntryLimit,
5 => Self::FrontEsceutcheonRemoved,
6 => Self::DoorForcedOpen,
7 => Self::DoorAjar,
8 => Self::ForcedUser,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::LockJammed => 0,
Self::LockFactoryReset => 1,
Self::LockRadioPowerCycled => 3,
Self::WrongCodeEntryLimit => 4,
Self::FrontEsceutcheonRemoved => 5,
Self::DoorForcedOpen => 6,
Self::DoorAjar => 7,
Self::ForcedUser => 8,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct AlarmMaskBitmap: u16 {
const LOCK_JAMMED = 1 << 0;
const LOCK_FACTORY_RESET = 1 << 1;
const LOCK_RADIO_POWER_CYCLED = 1 << 3;
const WRONG_CODE_ENTRY_LIMIT = 1 << 4;
const FRONT_ESCUTCHEON_REMOVED = 1 << 5;
const DOOR_FORCED_OPEN = 1 << 6;
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ConfigurationRegisterBitmap: u16 {
const LOCAL_PROGRAMMING = 1 << 0;
const KEYPAD_INTERFACE = 1 << 1;
const REMOTE_INTERFACE = 1 << 2;
const SOUND_VOLUME = 1 << 5;
const AUTO_RELOCK_TIME = 1 << 6;
const LED_SETTINGS = 1 << 7;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum CredentialRuleEnum {
Single,
Dual,
Tri,
Unknown(u8),
}
impl CredentialRuleEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Single,
1 => Self::Dual,
2 => Self::Tri,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Single => 0,
Self::Dual => 1,
Self::Tri => 2,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct CredentialRulesBitmap: u8 {
const SINGLE = 1 << 0;
const DUAL = 1 << 1;
const TRI = 1 << 2;
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct CredentialStruct {
pub credential_type: CredentialTypeEnum,
pub credential_index: u16,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum CredentialTypeEnum {
ProgrammingPin,
Pin,
Rfid,
Fingerprint,
FingerVein,
Face,
AliroCredentialIssuerKey,
AliroEvictableEndpointKey,
AliroNonEvictableEndpointKey,
Unknown(u8),
}
impl CredentialTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::ProgrammingPin,
1 => Self::Pin,
2 => Self::Rfid,
3 => Self::Fingerprint,
4 => Self::FingerVein,
5 => Self::Face,
6 => Self::AliroCredentialIssuerKey,
7 => Self::AliroEvictableEndpointKey,
8 => Self::AliroNonEvictableEndpointKey,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::ProgrammingPin => 0,
Self::Pin => 1,
Self::Rfid => 2,
Self::Fingerprint => 3,
Self::FingerVein => 4,
Self::Face => 5,
Self::AliroCredentialIssuerKey => 6,
Self::AliroEvictableEndpointKey => 7,
Self::AliroNonEvictableEndpointKey => 8,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DataOperationTypeEnum {
Add,
Clear,
Modify,
Unknown(u8),
}
impl DataOperationTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Add,
1 => Self::Clear,
2 => Self::Modify,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Add => 0,
Self::Clear => 1,
Self::Modify => 2,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct DaysMaskBitmap: u8 {
const SUNDAY = 1 << 0;
const MONDAY = 1 << 1;
const TUESDAY = 1 << 2;
const WEDNESDAY = 1 << 3;
const THURSDAY = 1 << 4;
const FRIDAY = 1 << 5;
const SATURDAY = 1 << 6;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DoorStateEnum {
DoorOpen,
DoorClosed,
DoorJammed,
DoorForcedOpen,
DoorUnspecifiedError,
DoorAjar,
Unknown(u8),
}
impl DoorStateEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::DoorOpen,
1 => Self::DoorClosed,
2 => Self::DoorJammed,
3 => Self::DoorForcedOpen,
4 => Self::DoorUnspecifiedError,
5 => Self::DoorAjar,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::DoorOpen => 0,
Self::DoorClosed => 1,
Self::DoorJammed => 2,
Self::DoorForcedOpen => 3,
Self::DoorUnspecifiedError => 4,
Self::DoorAjar => 5,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum EventTypeEnum {
Operation,
Programming,
Alarm,
Unknown(u8),
}
impl EventTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Operation,
1 => Self::Programming,
2 => Self::Alarm,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Operation => 0,
Self::Programming => 1,
Self::Alarm => 2,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum LEDSettingEnum {
NoLedSignal,
NoLedSignalAccessAllowed,
LedSignalAll,
Unknown(u8),
}
impl LEDSettingEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::NoLedSignal,
1 => Self::NoLedSignalAccessAllowed,
2 => Self::LedSignalAll,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::NoLedSignal => 0,
Self::NoLedSignalAccessAllowed => 1,
Self::LedSignalAll => 2,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct LocalProgrammingFeaturesBitmap: u8 {
const ADD_USERS_CREDENTIALS_SCHEDULES = 1 << 0;
const MODIFY_USERS_CREDENTIALS_SCHEDULES = 1 << 1;
const CLEAR_USERS_CREDENTIALS_SCHEDULES = 1 << 2;
const ADJUST_SETTINGS = 1 << 3;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum LockDataTypeEnum {
Unspecified,
ProgrammingCode,
UserIndex,
WeekDaySchedule,
YearDaySchedule,
HolidaySchedule,
Pin,
Rfid,
Fingerprint,
FingerVein,
Face,
AliroCredentialIssuerKey,
AliroEvictableEndpointKey,
AliroNonEvictableEndpointKey,
Unknown(u8),
}
impl LockDataTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::ProgrammingCode,
2 => Self::UserIndex,
3 => Self::WeekDaySchedule,
4 => Self::YearDaySchedule,
5 => Self::HolidaySchedule,
6 => Self::Pin,
7 => Self::Rfid,
8 => Self::Fingerprint,
9 => Self::FingerVein,
10 => Self::Face,
11 => Self::AliroCredentialIssuerKey,
12 => Self::AliroEvictableEndpointKey,
13 => Self::AliroNonEvictableEndpointKey,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unspecified => 0,
Self::ProgrammingCode => 1,
Self::UserIndex => 2,
Self::WeekDaySchedule => 3,
Self::YearDaySchedule => 4,
Self::HolidaySchedule => 5,
Self::Pin => 6,
Self::Rfid => 7,
Self::Fingerprint => 8,
Self::FingerVein => 9,
Self::Face => 10,
Self::AliroCredentialIssuerKey => 11,
Self::AliroEvictableEndpointKey => 12,
Self::AliroNonEvictableEndpointKey => 13,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum LockOperationTypeEnum {
Lock,
Unlock,
NonAccessUserEvent,
ForcedUserEvent,
Unlatch,
Unknown(u8),
}
impl LockOperationTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Lock,
1 => Self::Unlock,
2 => Self::NonAccessUserEvent,
3 => Self::ForcedUserEvent,
4 => Self::Unlatch,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Lock => 0,
Self::Unlock => 1,
Self::NonAccessUserEvent => 2,
Self::ForcedUserEvent => 3,
Self::Unlatch => 4,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum LockStateEnum {
NotFullyLocked,
Locked,
Unlocked,
Unlatched,
Unknown(u8),
}
impl LockStateEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::NotFullyLocked,
1 => Self::Locked,
2 => Self::Unlocked,
3 => Self::Unlatched,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::NotFullyLocked => 0,
Self::Locked => 1,
Self::Unlocked => 2,
Self::Unlatched => 3,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum LockTypeEnum {
DeadBolt,
Magnetic,
Other,
Mortise,
Rim,
LatchBolt,
CylindricalLock,
TubularLock,
InterconnectedLock,
DeadLatch,
DoorFurniture,
Eurocylinder,
Unknown(u8),
}
impl LockTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::DeadBolt,
1 => Self::Magnetic,
2 => Self::Other,
3 => Self::Mortise,
4 => Self::Rim,
5 => Self::LatchBolt,
6 => Self::CylindricalLock,
7 => Self::TubularLock,
8 => Self::InterconnectedLock,
9 => Self::DeadLatch,
10 => Self::DoorFurniture,
11 => Self::Eurocylinder,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::DeadBolt => 0,
Self::Magnetic => 1,
Self::Other => 2,
Self::Mortise => 3,
Self::Rim => 4,
Self::LatchBolt => 5,
Self::CylindricalLock => 6,
Self::TubularLock => 7,
Self::InterconnectedLock => 8,
Self::DeadLatch => 9,
Self::DoorFurniture => 10,
Self::Eurocylinder => 11,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum OperatingModeEnum {
Normal,
Vacation,
Privacy,
NoRemoteLockUnlock,
Passage,
Unknown(u8),
}
impl OperatingModeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Normal,
1 => Self::Vacation,
2 => Self::Privacy,
3 => Self::NoRemoteLockUnlock,
4 => Self::Passage,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Normal => 0,
Self::Vacation => 1,
Self::Privacy => 2,
Self::NoRemoteLockUnlock => 3,
Self::Passage => 4,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct OperatingModesBitmap: u16 {
const NORMAL = 1 << 0;
const VACATION = 1 << 1;
const PRIVACY = 1 << 2;
const NO_REMOTE_LOCK_UNLOCK = 1 << 3;
const PASSAGE = 1 << 4;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum OperationErrorEnum {
Unspecified,
InvalidCredential,
DisabledUserDenied,
Restricted,
InsufficientBattery,
Unknown(u8),
}
impl OperationErrorEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::InvalidCredential,
2 => Self::DisabledUserDenied,
3 => Self::Restricted,
4 => Self::InsufficientBattery,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unspecified => 0,
Self::InvalidCredential => 1,
Self::DisabledUserDenied => 2,
Self::Restricted => 3,
Self::InsufficientBattery => 4,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum OperationSourceEnum {
Unspecified,
Manual,
ProprietaryRemote,
Keypad,
Auto,
Button,
Schedule,
Remote,
Rfid,
Biometric,
Aliro,
Unknown(u8),
}
impl OperationSourceEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::Manual,
2 => Self::ProprietaryRemote,
3 => Self::Keypad,
4 => Self::Auto,
5 => Self::Button,
6 => Self::Schedule,
7 => Self::Remote,
8 => Self::Rfid,
9 => Self::Biometric,
10 => Self::Aliro,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unspecified => 0,
Self::Manual => 1,
Self::ProprietaryRemote => 2,
Self::Keypad => 3,
Self::Auto => 4,
Self::Button => 5,
Self::Schedule => 6,
Self::Remote => 7,
Self::Rfid => 8,
Self::Biometric => 9,
Self::Aliro => 10,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum SoundVolumeEnum {
Silent,
Low,
High,
Medium,
Unknown(u8),
}
impl SoundVolumeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Silent,
1 => Self::Low,
2 => Self::High,
3 => Self::Medium,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Silent => 0,
Self::Low => 1,
Self::High => 2,
Self::Medium => 3,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum StatusCodeEnum {
Duplicate,
Occupied,
Unknown(u8),
}
impl StatusCodeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
2 => Self::Duplicate,
3 => Self::Occupied,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Duplicate => 2,
Self::Occupied => 3,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum UserStatusEnum {
Available,
OccupiedEnabled,
OccupiedDisabled,
Unknown(u8),
}
impl UserStatusEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Available,
1 => Self::OccupiedEnabled,
3 => Self::OccupiedDisabled,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Available => 0,
Self::OccupiedEnabled => 1,
Self::OccupiedDisabled => 3,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum UserTypeEnum {
UnrestrictedUser,
YearDayScheduleUser,
WeekDayScheduleUser,
ProgrammingUser,
NonAccessUser,
ForcedUser,
DisposableUser,
ExpiringUser,
ScheduleRestrictedUser,
RemoteOnlyUser,
Unknown(u8),
}
impl UserTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::UnrestrictedUser,
1 => Self::YearDayScheduleUser,
2 => Self::WeekDayScheduleUser,
3 => Self::ProgrammingUser,
4 => Self::NonAccessUser,
5 => Self::ForcedUser,
6 => Self::DisposableUser,
7 => Self::ExpiringUser,
8 => Self::ScheduleRestrictedUser,
9 => Self::RemoteOnlyUser,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::UnrestrictedUser => 0,
Self::YearDayScheduleUser => 1,
Self::WeekDayScheduleUser => 2,
Self::ProgrammingUser => 3,
Self::NonAccessUser => 4,
Self::ForcedUser => 5,
Self::DisposableUser => 6,
Self::ExpiringUser => 7,
Self::ScheduleRestrictedUser => 8,
Self::RemoteOnlyUser => 9,
Self::Unknown(v) => v,
}
}
}
impl CredentialStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_credential_type: Option<CredentialTypeEnum> = None;
let mut f_credential_index: Option<u16> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_credential_type = Some(CredentialTypeEnum::from_raw(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("CredentialType"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_credential_index = Some(
u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("CredentialIndex"))?,
)
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
credential_type: f_credential_type
.ok_or(ClusterError::MissingField("CredentialType"))?,
credential_index: f_credential_index
.ok_or(ClusterError::MissingField("CredentialIndex"))?,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "CredentialStruct",
})
}
}
Self::decode_from(&mut r)
}
#[allow(clippy::expect_used)] pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
w.put_uint(Tag::Context(0), u64::from(self.credential_type.to_raw()))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(self.credential_index))
.expect("infallible: vec writer");
}
#[must_use]
#[allow(clippy::expect_used)] pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
self.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
buf
}
}
pub fn decode_lock_state(tlv: &[u8]) -> Result<Nullable<LockStateEnum>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(LockStateEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("LockState"))?,
))),
_ => Err(ClusterError::UnexpectedType {
context: "LockState",
}),
}
}
pub fn decode_lock_type(tlv: &[u8]) -> Result<LockTypeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(LockTypeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("LockType"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "LockType",
}),
}
}
pub fn decode_actuator_enabled(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "ActuatorEnabled",
}),
}
}
pub fn decode_door_state(tlv: &[u8]) -> Result<Nullable<DoorStateEnum>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(DoorStateEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("DoorState"))?,
))),
_ => Err(ClusterError::UnexpectedType {
context: "DoorState",
}),
}
}
pub fn decode_door_open_events(tlv: &[u8]) -> Result<u32, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("DoorOpenEvents"))?),
_ => Err(ClusterError::UnexpectedType {
context: "DoorOpenEvents",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_door_open_events(value: u32) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_door_closed_events(tlv: &[u8]) -> Result<u32, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("DoorClosedEvents"))?),
_ => Err(ClusterError::UnexpectedType {
context: "DoorClosedEvents",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_door_closed_events(value: u32) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_open_period(tlv: &[u8]) -> Result<u16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("OpenPeriod"))?),
_ => Err(ClusterError::UnexpectedType {
context: "OpenPeriod",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_open_period(value: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_number_of_total_users_supported(tlv: &[u8]) -> Result<u16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("NumberOfTotalUsersSupported"))?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfTotalUsersSupported",
}),
}
}
pub fn decode_number_of_pin_users_supported(tlv: &[u8]) -> Result<u16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("NumberOfPinUsersSupported"))?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfPinUsersSupported",
}),
}
}
pub fn decode_number_of_rfid_users_supported(tlv: &[u8]) -> Result<u16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("NumberOfRfidUsersSupported"))?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfRfidUsersSupported",
}),
}
}
pub fn decode_number_of_week_day_schedules_supported_per_user(
tlv: &[u8],
) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| {
ClusterError::InvalidLength("NumberOfWeekDaySchedulesSupportedPerUser")
})?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfWeekDaySchedulesSupportedPerUser",
}),
}
}
pub fn decode_number_of_year_day_schedules_supported_per_user(
tlv: &[u8],
) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| {
ClusterError::InvalidLength("NumberOfYearDaySchedulesSupportedPerUser")
})?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfYearDaySchedulesSupportedPerUser",
}),
}
}
pub fn decode_number_of_holiday_schedules_supported(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("NumberOfHolidaySchedulesSupported"))?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfHolidaySchedulesSupported",
}),
}
}
pub fn decode_max_pin_code_length(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("MaxPinCodeLength"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MaxPinCodeLength",
}),
}
}
pub fn decode_min_pin_code_length(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("MinPinCodeLength"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MinPinCodeLength",
}),
}
}
pub fn decode_max_rfid_code_length(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("MaxRfidCodeLength"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MaxRfidCodeLength",
}),
}
}
pub fn decode_min_rfid_code_length(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("MinRfidCodeLength"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MinRfidCodeLength",
}),
}
}
pub fn decode_credential_rules_support(tlv: &[u8]) -> Result<CredentialRulesBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(CredentialRulesBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("CredentialRulesSupport"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "CredentialRulesSupport",
}),
}
}
pub fn decode_number_of_credentials_supported_per_user(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("NumberOfCredentialsSupportedPerUser"))?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfCredentialsSupportedPerUser",
}),
}
}
pub fn decode_language(tlv: &[u8]) -> Result<String, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Utf8(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "Language",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_language(value: &String) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_utf8(Tag::Anonymous, &value)
.expect("infallible: vec writer");
buf
}
pub fn decode_led_settings(tlv: &[u8]) -> Result<LEDSettingEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(LEDSettingEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("LedSettings"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "LedSettings",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_led_settings(value: LEDSettingEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_auto_relock_time(tlv: &[u8]) -> Result<u32, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("AutoRelockTime"))?),
_ => Err(ClusterError::UnexpectedType {
context: "AutoRelockTime",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_auto_relock_time(value: u32) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_sound_volume(tlv: &[u8]) -> Result<SoundVolumeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(SoundVolumeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("SoundVolume"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "SoundVolume",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_sound_volume(value: SoundVolumeEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_operating_mode(tlv: &[u8]) -> Result<OperatingModeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(OperatingModeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("OperatingMode"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "OperatingMode",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_operating_mode(value: OperatingModeEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_supported_operating_modes(tlv: &[u8]) -> Result<OperatingModesBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(OperatingModesBitmap::from_bits_retain(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("SupportedOperatingModes"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "SupportedOperatingModes",
}),
}
}
pub fn decode_default_configuration_register(
tlv: &[u8],
) -> Result<ConfigurationRegisterBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ConfigurationRegisterBitmap::from_bits_retain(
u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("DefaultConfigurationRegister"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "DefaultConfigurationRegister",
}),
}
}
pub fn decode_enable_local_programming(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "EnableLocalProgramming",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_enable_local_programming(value: bool) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_bool(Tag::Anonymous, value)
.expect("infallible: vec writer");
buf
}
pub fn decode_enable_one_touch_locking(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "EnableOneTouchLocking",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_enable_one_touch_locking(value: bool) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_bool(Tag::Anonymous, value)
.expect("infallible: vec writer");
buf
}
pub fn decode_enable_inside_status_led(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "EnableInsideStatusLed",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_enable_inside_status_led(value: bool) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_bool(Tag::Anonymous, value)
.expect("infallible: vec writer");
buf
}
pub fn decode_enable_privacy_mode_button(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "EnablePrivacyModeButton",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_enable_privacy_mode_button(value: bool) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_bool(Tag::Anonymous, value)
.expect("infallible: vec writer");
buf
}
pub fn decode_local_programming_features(
tlv: &[u8],
) -> Result<LocalProgrammingFeaturesBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(LocalProgrammingFeaturesBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("LocalProgrammingFeatures"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "LocalProgrammingFeatures",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_local_programming_features(value: LocalProgrammingFeaturesBitmap) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.bits()))
.expect("infallible: vec writer");
buf
}
pub fn decode_wrong_code_entry_limit(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("WrongCodeEntryLimit"))?),
_ => Err(ClusterError::UnexpectedType {
context: "WrongCodeEntryLimit",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_wrong_code_entry_limit(value: u8) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_user_code_temporary_disable_time(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("UserCodeTemporaryDisableTime"))?),
_ => Err(ClusterError::UnexpectedType {
context: "UserCodeTemporaryDisableTime",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_user_code_temporary_disable_time(value: u8) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_send_pin_over_the_air(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "SendPinOverTheAir",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_send_pin_over_the_air(value: bool) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_bool(Tag::Anonymous, value)
.expect("infallible: vec writer");
buf
}
pub fn decode_require_pin_for_remote_operation(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "RequirePinForRemoteOperation",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_require_pin_for_remote_operation(value: bool) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_bool(Tag::Anonymous, value)
.expect("infallible: vec writer");
buf
}
pub fn decode_expiring_user_timeout(tlv: &[u8]) -> Result<u16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("ExpiringUserTimeout"))?),
_ => Err(ClusterError::UnexpectedType {
context: "ExpiringUserTimeout",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_expiring_user_timeout(value: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_lock_door(pin_code: Option<Vec<u8>>) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
if let Some(pin_code) = pin_code {
w.put_bytes(Tag::Context(0), &pin_code)
.expect("infallible: vec writer");
}
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_unlock_door(pin_code: Option<Vec<u8>>) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
if let Some(pin_code) = pin_code {
w.put_bytes(Tag::Context(0), &pin_code)
.expect("infallible: vec writer");
}
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_unlock_with_timeout(timeout: u16, pin_code: Option<Vec<u8>>) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(timeout))
.expect("infallible: vec writer");
if let Some(pin_code) = pin_code {
w.put_bytes(Tag::Context(1), &pin_code)
.expect("infallible: vec writer");
}
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_set_week_day_schedule(
week_day_index: u8,
user_index: u16,
days_mask: DaysMaskBitmap,
start_hour: u8,
start_minute: u8,
end_hour: u8,
end_minute: u8,
) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(week_day_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(user_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(2), u64::from(days_mask.bits()))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(3), u64::from(start_hour))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(4), u64::from(start_minute))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(5), u64::from(end_hour))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(6), u64::from(end_minute))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_get_week_day_schedule(week_day_index: u8, user_index: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(week_day_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(user_index))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct GetWeekDayScheduleResponse {
pub week_day_index: u8,
pub user_index: u16,
pub status: u8,
pub days_mask: Option<DaysMaskBitmap>,
pub start_hour: Option<u8>,
pub start_minute: Option<u8>,
pub end_hour: Option<u8>,
pub end_minute: Option<u8>,
}
impl GetWeekDayScheduleResponse {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_week_day_index: Option<u8> = None;
let mut f_user_index: Option<u16> = None;
let mut f_status: Option<u8> = None;
let mut f_days_mask: Option<DaysMaskBitmap> = None;
let mut f_start_hour: Option<u8> = None;
let mut f_start_minute: Option<u8> = None;
let mut f_end_hour: Option<u8> = None;
let mut f_end_minute: Option<u8> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_week_day_index = Some(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("WeekDayIndex"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_user_index = Some(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("UserIndex"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_status =
Some(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Status"))?)
}
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Uint(v),
}) => {
f_days_mask = Some(DaysMaskBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("DaysMask"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Uint(v),
}) => {
f_start_hour = Some(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("StartHour"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Uint(v),
}) => {
f_start_minute = Some(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("StartMinute"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(6),
value: Value::Uint(v),
}) => {
f_end_hour =
Some(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("EndHour"))?)
}
Some(Element::Scalar {
tag: Tag::Context(7),
value: Value::Uint(v),
}) => {
f_end_minute = Some(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("EndMinute"))?,
)
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
week_day_index: f_week_day_index.ok_or(ClusterError::MissingField("WeekDayIndex"))?,
user_index: f_user_index.ok_or(ClusterError::MissingField("UserIndex"))?,
status: f_status.ok_or(ClusterError::MissingField("Status"))?,
days_mask: f_days_mask,
start_hour: f_start_hour,
start_minute: f_start_minute,
end_hour: f_end_hour,
end_minute: f_end_minute,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "GetWeekDayScheduleResponse",
})
}
}
Self::decode_from(&mut r)
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_clear_week_day_schedule(week_day_index: u8, user_index: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(week_day_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(user_index))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_set_year_day_schedule(
year_day_index: u8,
user_index: u16,
local_start_time: u32,
local_end_time: u32,
) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(year_day_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(user_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(2), u64::from(local_start_time))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(3), u64::from(local_end_time))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_get_year_day_schedule(year_day_index: u8, user_index: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(year_day_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(user_index))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct GetYearDayScheduleResponse {
pub year_day_index: u8,
pub user_index: u16,
pub status: u8,
pub local_start_time: Option<u32>,
pub local_end_time: Option<u32>,
}
impl GetYearDayScheduleResponse {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_year_day_index: Option<u8> = None;
let mut f_user_index: Option<u16> = None;
let mut f_status: Option<u8> = None;
let mut f_local_start_time: Option<u32> = None;
let mut f_local_end_time: Option<u32> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_year_day_index = Some(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("YearDayIndex"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_user_index = Some(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("UserIndex"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_status =
Some(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Status"))?)
}
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Uint(v),
}) => {
f_local_start_time = Some(
u32::try_from(v)
.map_err(|_| ClusterError::InvalidLength("LocalStartTime"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Uint(v),
}) => {
f_local_end_time = Some(
u32::try_from(v)
.map_err(|_| ClusterError::InvalidLength("LocalEndTime"))?,
)
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
year_day_index: f_year_day_index.ok_or(ClusterError::MissingField("YearDayIndex"))?,
user_index: f_user_index.ok_or(ClusterError::MissingField("UserIndex"))?,
status: f_status.ok_or(ClusterError::MissingField("Status"))?,
local_start_time: f_local_start_time,
local_end_time: f_local_end_time,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "GetYearDayScheduleResponse",
})
}
}
Self::decode_from(&mut r)
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_clear_year_day_schedule(year_day_index: u8, user_index: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(year_day_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(user_index))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_set_holiday_schedule(
holiday_index: u8,
local_start_time: u32,
local_end_time: u32,
operating_mode: OperatingModeEnum,
) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(holiday_index))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(local_start_time))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(2), u64::from(local_end_time))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(3), u64::from(operating_mode.to_raw()))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_get_holiday_schedule(holiday_index: u8) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(holiday_index))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct GetHolidayScheduleResponse {
pub holiday_index: u8,
pub status: u8,
pub local_start_time: Option<Nullable<u32>>,
pub local_end_time: Option<Nullable<u32>>,
pub operating_mode: Option<Nullable<OperatingModeEnum>>,
}
impl GetHolidayScheduleResponse {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_holiday_index: Option<u8> = None;
let mut f_status: Option<u8> = None;
let mut f_local_start_time: Option<Nullable<u32>> = None;
let mut f_local_end_time: Option<Nullable<u32>> = None;
let mut f_operating_mode: Option<Nullable<OperatingModeEnum>> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_holiday_index = Some(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("HolidayIndex"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_status =
Some(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Status"))?)
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Null,
}) => f_local_start_time = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_local_start_time =
Some(Nullable::Value(u32::try_from(v).map_err(|_| {
ClusterError::InvalidLength("LocalStartTime")
})?))
}
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Null,
}) => f_local_end_time = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Uint(v),
}) => {
f_local_end_time = Some(Nullable::Value(
u32::try_from(v)
.map_err(|_| ClusterError::InvalidLength("LocalEndTime"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Null,
}) => f_operating_mode = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Uint(v),
}) => {
f_operating_mode = Some(Nullable::Value(OperatingModeEnum::from_raw(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("OperatingMode"))?,
)))
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
holiday_index: f_holiday_index.ok_or(ClusterError::MissingField("HolidayIndex"))?,
status: f_status.ok_or(ClusterError::MissingField("Status"))?,
local_start_time: f_local_start_time,
local_end_time: f_local_end_time,
operating_mode: f_operating_mode,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "GetHolidayScheduleResponse",
})
}
}
Self::decode_from(&mut r)
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_clear_holiday_schedule(holiday_index: u8) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(holiday_index))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_set_user(
operation_type: DataOperationTypeEnum,
user_index: u16,
user_name: Nullable<String>,
user_unique_id: Nullable<u32>,
user_status: Nullable<UserStatusEnum>,
user_type: Nullable<UserTypeEnum>,
credential_rule: Nullable<CredentialRuleEnum>,
) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(operation_type.to_raw()))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(user_index))
.expect("infallible: vec writer");
match user_name {
Nullable::Null => w.put_null(Tag::Context(2)).expect("infallible: vec writer"),
Nullable::Value(user_name) => {
w.put_utf8(Tag::Context(2), &user_name)
.expect("infallible: vec writer");
}
}
match user_unique_id {
Nullable::Null => w.put_null(Tag::Context(3)).expect("infallible: vec writer"),
Nullable::Value(user_unique_id) => {
w.put_uint(Tag::Context(3), u64::from(user_unique_id))
.expect("infallible: vec writer");
}
}
match user_status {
Nullable::Null => w.put_null(Tag::Context(4)).expect("infallible: vec writer"),
Nullable::Value(user_status) => {
w.put_uint(Tag::Context(4), u64::from(user_status.to_raw()))
.expect("infallible: vec writer");
}
}
match user_type {
Nullable::Null => w.put_null(Tag::Context(5)).expect("infallible: vec writer"),
Nullable::Value(user_type) => {
w.put_uint(Tag::Context(5), u64::from(user_type.to_raw()))
.expect("infallible: vec writer");
}
}
match credential_rule {
Nullable::Null => w.put_null(Tag::Context(6)).expect("infallible: vec writer"),
Nullable::Value(credential_rule) => {
w.put_uint(Tag::Context(6), u64::from(credential_rule.to_raw()))
.expect("infallible: vec writer");
}
}
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_get_user(user_index: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(user_index))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct GetUserResponse {
pub user_index: u16,
pub user_name: Nullable<String>,
pub user_unique_id: Nullable<u32>,
pub user_status: Nullable<UserStatusEnum>,
pub user_type: Nullable<UserTypeEnum>,
pub credential_rule: Nullable<CredentialRuleEnum>,
pub credentials: Nullable<Vec<CredentialStruct>>,
pub creator_fabric_index: Nullable<u8>,
pub last_modified_fabric_index: Nullable<u8>,
pub next_user_index: Nullable<u16>,
}
impl GetUserResponse {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_user_index: Option<u16> = None;
let mut f_user_name: Option<Nullable<String>> = None;
let mut f_user_unique_id: Option<Nullable<u32>> = None;
let mut f_user_status: Option<Nullable<UserStatusEnum>> = None;
let mut f_user_type: Option<Nullable<UserTypeEnum>> = None;
let mut f_credential_rule: Option<Nullable<CredentialRuleEnum>> = None;
let mut f_credentials: Option<Nullable<Vec<CredentialStruct>>> = None;
let mut f_creator_fabric_index: Option<Nullable<u8>> = None;
let mut f_last_modified_fabric_index: Option<Nullable<u8>> = None;
let mut f_next_user_index: Option<Nullable<u16>> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_user_index = Some(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("UserIndex"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Null,
}) => f_user_name = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Utf8(v),
}) => f_user_name = Some(Nullable::Value(v)),
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Null,
}) => f_user_unique_id = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_user_unique_id = Some(Nullable::Value(
u32::try_from(v)
.map_err(|_| ClusterError::InvalidLength("UserUniqueId"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Null,
}) => f_user_status = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Uint(v),
}) => {
f_user_status = Some(Nullable::Value(UserStatusEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("UserStatus"))?,
)))
}
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Null,
}) => f_user_type = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Uint(v),
}) => {
f_user_type = Some(Nullable::Value(UserTypeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("UserType"))?,
)))
}
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Null,
}) => f_credential_rule = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Uint(v),
}) => {
f_credential_rule = Some(Nullable::Value(CredentialRuleEnum::from_raw(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("CredentialRule"))?,
)))
}
Some(Element::Scalar {
tag: Tag::Context(6),
value: Value::Null,
}) => f_credentials = Some(Nullable::Null),
Some(Element::ContainerStart {
tag: Tag::Context(6),
kind: ContainerKind::Array,
}) => {
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {
out.push(CredentialStruct::decode_from(r)?);
}
None => {
return Err(ClusterError::Tlv(
matter_codec::Error::UnclosedContainer,
))
}
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
f_credentials = Some(Nullable::Value(out));
}
Some(Element::Scalar {
tag: Tag::Context(7),
value: Value::Null,
}) => f_creator_fabric_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(7),
value: Value::Uint(v),
}) => {
f_creator_fabric_index =
Some(Nullable::Value(u8::try_from(v).map_err(|_| {
ClusterError::InvalidLength("CreatorFabricIndex")
})?))
}
Some(Element::Scalar {
tag: Tag::Context(8),
value: Value::Null,
}) => f_last_modified_fabric_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(8),
value: Value::Uint(v),
}) => {
f_last_modified_fabric_index =
Some(Nullable::Value(u8::try_from(v).map_err(|_| {
ClusterError::InvalidLength("LastModifiedFabricIndex")
})?))
}
Some(Element::Scalar {
tag: Tag::Context(9),
value: Value::Null,
}) => f_next_user_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(9),
value: Value::Uint(v),
}) => {
f_next_user_index = Some(Nullable::Value(
u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("NextUserIndex"))?,
))
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
user_index: f_user_index.ok_or(ClusterError::MissingField("UserIndex"))?,
user_name: f_user_name.ok_or(ClusterError::MissingField("UserName"))?,
user_unique_id: f_user_unique_id.ok_or(ClusterError::MissingField("UserUniqueId"))?,
user_status: f_user_status.ok_or(ClusterError::MissingField("UserStatus"))?,
user_type: f_user_type.ok_or(ClusterError::MissingField("UserType"))?,
credential_rule: f_credential_rule
.ok_or(ClusterError::MissingField("CredentialRule"))?,
credentials: f_credentials.ok_or(ClusterError::MissingField("Credentials"))?,
creator_fabric_index: f_creator_fabric_index
.ok_or(ClusterError::MissingField("CreatorFabricIndex"))?,
last_modified_fabric_index: f_last_modified_fabric_index
.ok_or(ClusterError::MissingField("LastModifiedFabricIndex"))?,
next_user_index: f_next_user_index
.ok_or(ClusterError::MissingField("NextUserIndex"))?,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "GetUserResponse",
})
}
}
Self::decode_from(&mut r)
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_clear_user(user_index: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(user_index))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_set_credential(
operation_type: DataOperationTypeEnum,
credential: CredentialStruct,
credential_data: &Vec<u8>,
user_index: Nullable<u16>,
user_status: Nullable<UserStatusEnum>,
user_type: Nullable<UserTypeEnum>,
) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(operation_type.to_raw()))
.expect("infallible: vec writer");
w.start_structure(Tag::Context(1))
.expect("infallible: vec writer");
credential.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
w.put_bytes(Tag::Context(2), &credential_data)
.expect("infallible: vec writer");
match user_index {
Nullable::Null => w.put_null(Tag::Context(3)).expect("infallible: vec writer"),
Nullable::Value(user_index) => {
w.put_uint(Tag::Context(3), u64::from(user_index))
.expect("infallible: vec writer");
}
}
match user_status {
Nullable::Null => w.put_null(Tag::Context(4)).expect("infallible: vec writer"),
Nullable::Value(user_status) => {
w.put_uint(Tag::Context(4), u64::from(user_status.to_raw()))
.expect("infallible: vec writer");
}
}
match user_type {
Nullable::Null => w.put_null(Tag::Context(5)).expect("infallible: vec writer"),
Nullable::Value(user_type) => {
w.put_uint(Tag::Context(5), u64::from(user_type.to_raw()))
.expect("infallible: vec writer");
}
}
w.end_container().expect("infallible: vec writer");
buf
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct SetCredentialResponse {
pub status: u8,
pub user_index: Nullable<u16>,
pub next_credential_index: Option<Nullable<u16>>,
}
impl SetCredentialResponse {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_status: Option<u8> = None;
let mut f_user_index: Option<Nullable<u16>> = None;
let mut f_next_credential_index: Option<Nullable<u16>> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_status =
Some(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Status"))?)
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Null,
}) => f_user_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_user_index = Some(Nullable::Value(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("UserIndex"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Null,
}) => f_next_credential_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_next_credential_index =
Some(Nullable::Value(u16::try_from(v).map_err(|_| {
ClusterError::InvalidLength("NextCredentialIndex")
})?))
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
status: f_status.ok_or(ClusterError::MissingField("Status"))?,
user_index: f_user_index.ok_or(ClusterError::MissingField("UserIndex"))?,
next_credential_index: f_next_credential_index,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "SetCredentialResponse",
})
}
}
Self::decode_from(&mut r)
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_get_credential_status(credential: CredentialStruct) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.start_structure(Tag::Context(0))
.expect("infallible: vec writer");
credential.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct GetCredentialStatusResponse {
pub credential_exists: bool,
pub user_index: Nullable<u16>,
pub creator_fabric_index: Nullable<u8>,
pub last_modified_fabric_index: Nullable<u8>,
pub next_credential_index: Option<Nullable<u16>>,
pub credential_data: Option<Nullable<Vec<u8>>>,
}
impl GetCredentialStatusResponse {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_credential_exists: Option<bool> = None;
let mut f_user_index: Option<Nullable<u16>> = None;
let mut f_creator_fabric_index: Option<Nullable<u8>> = None;
let mut f_last_modified_fabric_index: Option<Nullable<u8>> = None;
let mut f_next_credential_index: Option<Nullable<u16>> = None;
let mut f_credential_data: Option<Nullable<Vec<u8>>> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Bool(v),
}) => f_credential_exists = Some(v),
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Null,
}) => f_user_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_user_index = Some(Nullable::Value(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("UserIndex"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Null,
}) => f_creator_fabric_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_creator_fabric_index =
Some(Nullable::Value(u8::try_from(v).map_err(|_| {
ClusterError::InvalidLength("CreatorFabricIndex")
})?))
}
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Null,
}) => f_last_modified_fabric_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Uint(v),
}) => {
f_last_modified_fabric_index =
Some(Nullable::Value(u8::try_from(v).map_err(|_| {
ClusterError::InvalidLength("LastModifiedFabricIndex")
})?))
}
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Null,
}) => f_next_credential_index = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Uint(v),
}) => {
f_next_credential_index =
Some(Nullable::Value(u16::try_from(v).map_err(|_| {
ClusterError::InvalidLength("NextCredentialIndex")
})?))
}
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Null,
}) => f_credential_data = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Bytes(v),
}) => f_credential_data = Some(Nullable::Value(v)),
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
credential_exists: f_credential_exists
.ok_or(ClusterError::MissingField("CredentialExists"))?,
user_index: f_user_index.ok_or(ClusterError::MissingField("UserIndex"))?,
creator_fabric_index: f_creator_fabric_index
.ok_or(ClusterError::MissingField("CreatorFabricIndex"))?,
last_modified_fabric_index: f_last_modified_fabric_index
.ok_or(ClusterError::MissingField("LastModifiedFabricIndex"))?,
next_credential_index: f_next_credential_index,
credential_data: f_credential_data,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "GetCredentialStatusResponse",
})
}
}
Self::decode_from(&mut r)
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_clear_credential(credential: Nullable<CredentialStruct>) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
match &credential {
Nullable::Null => w.put_null(Tag::Context(0)).expect("infallible: vec writer"),
Nullable::Value(credential) => {
w.start_structure(Tag::Context(0))
.expect("infallible: vec writer");
credential.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
}
}
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_unbolt_door(pin_code: Option<Vec<u8>>) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
if let Some(pin_code) = pin_code {
w.put_bytes(Tag::Context(0), &pin_code)
.expect("infallible: vec writer");
}
w.end_container().expect("infallible: vec writer");
buf
}