1#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23 ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26pub const ID: ClusterId = 0xFFFF0000;
28
29pub const REVISION: u16 = 1;
32
33pub const FEATURES: &[Feature] = &[];
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
38#[repr(u8)]
39pub enum AtomicRequestTypeEnum {
40 BeginWrite = 0,
42 CommitWrite = 1,
44 RollbackWrite = 2,
46}
47
48impl AtomicRequestTypeEnum {
49 #[must_use]
51 pub const fn from_value(value: u8) -> Option<Self> {
52 match value {
53 0 => Some(Self::BeginWrite),
54 1 => Some(Self::CommitWrite),
55 2 => Some(Self::RollbackWrite),
56 _ => None,
57 }
58 }
59
60 #[must_use]
62 pub const fn value(self) -> u8 {
63 self as u8
64 }
65}
66
67impl ToTlv for AtomicRequestTypeEnum {
68 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
69 self.value().to_tlv(w, tag)
70 }
71}
72
73impl<'a> FromTlv<'a> for AtomicRequestTypeEnum {
74 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
75 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
76 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
77 }
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
82#[repr(u8)]
83pub enum CertificationTypeEnum {
84 DeviceAttestationPKI = 0,
86 OperationalPKI = 1,
88 VIDSignerPKI = 2,
90}
91
92impl CertificationTypeEnum {
93 #[must_use]
95 pub const fn from_value(value: u8) -> Option<Self> {
96 match value {
97 0 => Some(Self::DeviceAttestationPKI),
98 1 => Some(Self::OperationalPKI),
99 2 => Some(Self::VIDSignerPKI),
100 _ => None,
101 }
102 }
103
104 #[must_use]
106 pub const fn value(self) -> u8 {
107 self as u8
108 }
109}
110
111impl ToTlv for CertificationTypeEnum {
112 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
113 self.value().to_tlv(w, tag)
114 }
115}
116
117impl<'a> FromTlv<'a> for CertificationTypeEnum {
118 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
119 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
120 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
121 }
122}
123
124#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
126#[repr(u8)]
127pub enum MeasurementTypeEnum {
128 Unspecified = 0,
130 Voltage = 1,
132 ActiveCurrent = 2,
134 ReactiveCurrent = 3,
136 ApparentCurrent = 4,
138 ActivePower = 5,
140 ReactivePower = 6,
142 ApparentPower = 7,
144 RMSVoltage = 8,
146 RMSCurrent = 9,
148 RMSPower = 10,
150 Frequency = 11,
152 PowerFactor = 12,
154 NeutralCurrent = 13,
156 ElectricalEnergy = 14,
158 ReactiveEnergy = 15,
160 ApparentEnergy = 16,
162 SoilMoisture = 17,
164}
165
166impl MeasurementTypeEnum {
167 #[must_use]
169 pub const fn from_value(value: u8) -> Option<Self> {
170 match value {
171 0 => Some(Self::Unspecified),
172 1 => Some(Self::Voltage),
173 2 => Some(Self::ActiveCurrent),
174 3 => Some(Self::ReactiveCurrent),
175 4 => Some(Self::ApparentCurrent),
176 5 => Some(Self::ActivePower),
177 6 => Some(Self::ReactivePower),
178 7 => Some(Self::ApparentPower),
179 8 => Some(Self::RMSVoltage),
180 9 => Some(Self::RMSCurrent),
181 10 => Some(Self::RMSPower),
182 11 => Some(Self::Frequency),
183 12 => Some(Self::PowerFactor),
184 13 => Some(Self::NeutralCurrent),
185 14 => Some(Self::ElectricalEnergy),
186 15 => Some(Self::ReactiveEnergy),
187 16 => Some(Self::ApparentEnergy),
188 17 => Some(Self::SoilMoisture),
189 _ => None,
190 }
191 }
192
193 #[must_use]
195 pub const fn value(self) -> u8 {
196 self as u8
197 }
198}
199
200impl ToTlv for MeasurementTypeEnum {
201 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
202 self.value().to_tlv(w, tag)
203 }
204}
205
206impl<'a> FromTlv<'a> for MeasurementTypeEnum {
207 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
208 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
209 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
210 }
211}
212
213#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
215#[repr(u8)]
216pub enum PowerThresholdSourceEnum {
217 Contract = 0,
219 Regulator = 1,
221 Equipment = 2,
223}
224
225impl PowerThresholdSourceEnum {
226 #[must_use]
228 pub const fn from_value(value: u8) -> Option<Self> {
229 match value {
230 0 => Some(Self::Contract),
231 1 => Some(Self::Regulator),
232 2 => Some(Self::Equipment),
233 _ => None,
234 }
235 }
236
237 #[must_use]
239 pub const fn value(self) -> u8 {
240 self as u8
241 }
242}
243
244impl ToTlv for PowerThresholdSourceEnum {
245 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
246 self.value().to_tlv(w, tag)
247 }
248}
249
250impl<'a> FromTlv<'a> for PowerThresholdSourceEnum {
251 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
252 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
253 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
254 }
255}
256
257#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
259#[repr(u8)]
260pub enum SoftwareVersionCertificationStatusEnum {
261 DevTest = 0,
263 Provisional = 1,
265 Certified = 2,
267 Revoked = 3,
269}
270
271impl SoftwareVersionCertificationStatusEnum {
272 #[must_use]
274 pub const fn from_value(value: u8) -> Option<Self> {
275 match value {
276 0 => Some(Self::DevTest),
277 1 => Some(Self::Provisional),
278 2 => Some(Self::Certified),
279 3 => Some(Self::Revoked),
280 _ => None,
281 }
282 }
283
284 #[must_use]
286 pub const fn value(self) -> u8 {
287 self as u8
288 }
289}
290
291impl ToTlv for SoftwareVersionCertificationStatusEnum {
292 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
293 self.value().to_tlv(w, tag)
294 }
295}
296
297impl<'a> FromTlv<'a> for SoftwareVersionCertificationStatusEnum {
298 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
299 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
300 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
301 }
302}
303
304#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
306#[repr(u8)]
307pub enum StreamUsageEnum {
308 Internal = 0,
310 Recording = 1,
312 Analysis = 2,
314 LiveView = 3,
316}
317
318impl StreamUsageEnum {
319 #[must_use]
321 pub const fn from_value(value: u8) -> Option<Self> {
322 match value {
323 0 => Some(Self::Internal),
324 1 => Some(Self::Recording),
325 2 => Some(Self::Analysis),
326 3 => Some(Self::LiveView),
327 _ => None,
328 }
329 }
330
331 #[must_use]
333 pub const fn value(self) -> u8 {
334 self as u8
335 }
336}
337
338impl ToTlv for StreamUsageEnum {
339 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
340 self.value().to_tlv(w, tag)
341 }
342}
343
344impl<'a> FromTlv<'a> for StreamUsageEnum {
345 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
346 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
347 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
348 }
349}
350
351#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
353#[repr(u8)]
354pub enum TariffPriceTypeEnum {
355 Standard = 0,
357 Critical = 1,
359 Virtual = 2,
361 Incentive = 3,
363 IncentiveSignal = 4,
365}
366
367impl TariffPriceTypeEnum {
368 #[must_use]
370 pub const fn from_value(value: u8) -> Option<Self> {
371 match value {
372 0 => Some(Self::Standard),
373 1 => Some(Self::Critical),
374 2 => Some(Self::Virtual),
375 3 => Some(Self::Incentive),
376 4 => Some(Self::IncentiveSignal),
377 _ => None,
378 }
379 }
380
381 #[must_use]
383 pub const fn value(self) -> u8 {
384 self as u8
385 }
386}
387
388impl ToTlv for TariffPriceTypeEnum {
389 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
390 self.value().to_tlv(w, tag)
391 }
392}
393
394impl<'a> FromTlv<'a> for TariffPriceTypeEnum {
395 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
396 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
397 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
398 }
399}
400
401#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
403#[repr(u8)]
404pub enum TariffUnitEnum {
405 KWh = 0,
407 KVAh = 1,
409}
410
411impl TariffUnitEnum {
412 #[must_use]
414 pub const fn from_value(value: u8) -> Option<Self> {
415 match value {
416 0 => Some(Self::KWh),
417 1 => Some(Self::KVAh),
418 _ => None,
419 }
420 }
421
422 #[must_use]
424 pub const fn value(self) -> u8 {
425 self as u8
426 }
427}
428
429impl ToTlv for TariffUnitEnum {
430 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
431 self.value().to_tlv(w, tag)
432 }
433}
434
435impl<'a> FromTlv<'a> for TariffUnitEnum {
436 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
437 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
438 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
439 }
440}
441
442#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
444#[repr(u8)]
445pub enum ThreeLevelAutoEnum {
446 Auto = 0,
448 Low = 1,
450 Medium = 2,
452 High = 3,
454}
455
456impl ThreeLevelAutoEnum {
457 #[must_use]
459 pub const fn from_value(value: u8) -> Option<Self> {
460 match value {
461 0 => Some(Self::Auto),
462 1 => Some(Self::Low),
463 2 => Some(Self::Medium),
464 3 => Some(Self::High),
465 _ => None,
466 }
467 }
468
469 #[must_use]
471 pub const fn value(self) -> u8 {
472 self as u8
473 }
474}
475
476impl ToTlv for ThreeLevelAutoEnum {
477 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
478 self.value().to_tlv(w, tag)
479 }
480}
481
482impl<'a> FromTlv<'a> for ThreeLevelAutoEnum {
483 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
484 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
485 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
486 }
487}
488
489#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
491#[repr(u8)]
492pub enum WebRTCEndReasonEnum {
493 ICEFailed = 0,
495 ICETimeout = 1,
497 UserHangup = 2,
499 UserBusy = 3,
501 Replaced = 4,
503 NoUserMedia = 5,
505 InviteTimeout = 6,
507 AnsweredElsewhere = 7,
509 OutOfResources = 8,
511 MediaTimeout = 9,
513 LowPower = 10,
515 PrivacyMode = 11,
517 UnknownReason = 12,
519}
520
521impl WebRTCEndReasonEnum {
522 #[must_use]
524 pub const fn from_value(value: u8) -> Option<Self> {
525 match value {
526 0 => Some(Self::ICEFailed),
527 1 => Some(Self::ICETimeout),
528 2 => Some(Self::UserHangup),
529 3 => Some(Self::UserBusy),
530 4 => Some(Self::Replaced),
531 5 => Some(Self::NoUserMedia),
532 6 => Some(Self::InviteTimeout),
533 7 => Some(Self::AnsweredElsewhere),
534 8 => Some(Self::OutOfResources),
535 9 => Some(Self::MediaTimeout),
536 10 => Some(Self::LowPower),
537 11 => Some(Self::PrivacyMode),
538 12 => Some(Self::UnknownReason),
539 _ => None,
540 }
541 }
542
543 #[must_use]
545 pub const fn value(self) -> u8 {
546 self as u8
547 }
548}
549
550impl ToTlv for WebRTCEndReasonEnum {
551 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
552 self.value().to_tlv(w, tag)
553 }
554}
555
556impl<'a> FromTlv<'a> for WebRTCEndReasonEnum {
557 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
558 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
559 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
560 }
561}
562
563bitflags::bitflags! {
564 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
566 pub struct WildcardPathFlagsBitmap: u16 {
567 const WILDCARD_SKIP_ROOT_NODE = 1 << 0;
569 const WILDCARD_SKIP_GLOBAL_ATTRIBUTES = 1 << 1;
571 const WILDCARD_SKIP_ATTRIBUTE_LIST = 1 << 2;
573 const DO_NOT_USE = 1 << 3;
575 const WILDCARD_SKIP_COMMAND_LISTS = 1 << 4;
577 const WILDCARD_SKIP_CUSTOM_ELEMENTS = 1 << 5;
579 const WILDCARD_SKIP_FIXED_ATTRIBUTES = 1 << 6;
581 const WILDCARD_SKIP_CHANGES_OMITTED_ATTRIBUTES = 1 << 7;
583 const WILDCARD_SKIP_DIAGNOSTICS_CLUSTERS = 1 << 8;
585 }
586}
587
588impl ToTlv for WildcardPathFlagsBitmap {
589 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
590 self.bits().to_tlv(w, tag)
591 }
592}
593
594impl<'a> FromTlv<'a> for WildcardPathFlagsBitmap {
595 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
596 let bits = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
597 Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
598 }
599}
600
601#[derive(Debug, Clone, Copy, PartialEq)]
603pub struct AtomicAttributeStatusStruct {
604 pub attribute_id: u32,
606 pub status_code: u8,
608}
609
610impl ToTlv for AtomicAttributeStatusStruct {
611 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
612 w.start_structure(tag)?;
613 self.attribute_id.to_tlv(w, Tag::Context(0))?;
614 self.status_code.to_tlv(w, Tag::Context(1))?;
615 w.end_container()
616 }
617}
618
619impl<'a> FromTlv<'a> for AtomicAttributeStatusStruct {
620 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
621 if element.value.container() != Some(ContainerKind::Structure) {
622 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
623 }
624 let mut attribute_id = None;
625 let mut status_code = None;
626 loop {
627 let Some(field) = reader.next_element()? else {
628 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
629 };
630 if field.value == Value::EndOfContainer {
631 break;
632 }
633 match field.tag.context() {
634 Some(0) => attribute_id = Some(<u32>::from_tlv(reader, &field)?),
635 Some(1) => status_code = Some(<u8>::from_tlv(reader, &field)?),
636 _ => reader.skip_value(&field)?,
640 }
641 }
642 Ok(Self {
643 attribute_id: attribute_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
644 status_code: status_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
645 })
646 }
647}
648
649#[derive(Debug, Clone, Copy, PartialEq)]
651pub struct CurrencyStruct {
652 pub currency: u16,
654 pub decimal_points: u8,
656}
657
658impl ToTlv for CurrencyStruct {
659 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
660 w.start_structure(tag)?;
661 self.currency.to_tlv(w, Tag::Context(0))?;
662 self.decimal_points.to_tlv(w, Tag::Context(1))?;
663 w.end_container()
664 }
665}
666
667impl<'a> FromTlv<'a> for CurrencyStruct {
668 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
669 if element.value.container() != Some(ContainerKind::Structure) {
670 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
671 }
672 let mut currency = None;
673 let mut decimal_points = None;
674 loop {
675 let Some(field) = reader.next_element()? else {
676 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
677 };
678 if field.value == Value::EndOfContainer {
679 break;
680 }
681 match field.tag.context() {
682 Some(0) => currency = Some(<u16>::from_tlv(reader, &field)?),
683 Some(1) => decimal_points = Some(<u8>::from_tlv(reader, &field)?),
684 _ => reader.skip_value(&field)?,
688 }
689 }
690 Ok(Self {
691 currency: currency.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
692 decimal_points: decimal_points
693 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
694 })
695 }
696}
697
698#[derive(Debug, Clone, Copy, PartialEq)]
700pub struct ICECandidateStruct<'a> {
701 pub candidate: &'a str,
703 pub sdp_mid: Nullable<&'a str>,
705 pub sdpm_line_index: Nullable<u16>,
707}
708
709impl<'a> ToTlv for ICECandidateStruct<'a> {
710 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
711 w.start_structure(tag)?;
712 self.candidate.to_tlv(w, Tag::Context(0))?;
713 self.sdp_mid.to_tlv(w, Tag::Context(1))?;
714 self.sdpm_line_index.to_tlv(w, Tag::Context(2))?;
715 w.end_container()
716 }
717}
718
719impl<'a> FromTlv<'a> for ICECandidateStruct<'a> {
720 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
721 if element.value.container() != Some(ContainerKind::Structure) {
722 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
723 }
724 let mut candidate = None;
725 let mut sdp_mid = None;
726 let mut sdpm_line_index = None;
727 loop {
728 let Some(field) = reader.next_element()? else {
729 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
730 };
731 if field.value == Value::EndOfContainer {
732 break;
733 }
734 match field.tag.context() {
735 Some(0) => candidate = Some(<&'a str>::from_tlv(reader, &field)?),
736 Some(1) => sdp_mid = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
737 Some(2) => sdpm_line_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
738 _ => reader.skip_value(&field)?,
742 }
743 }
744 Ok(Self {
745 candidate: candidate.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
746 sdp_mid: sdp_mid.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
747 sdpm_line_index: sdpm_line_index
748 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
749 })
750 }
751}
752
753#[derive(Debug, Clone, Copy, PartialEq)]
755pub struct ICEServerStruct<'a> {
756 pub ur_ls: TlvList<'a, &'a str>,
758 pub username: Option<&'a str>,
760 pub credential: Option<&'a str>,
762 pub caid: Option<u16>,
764}
765
766impl<'a> ToTlv for ICEServerStruct<'a> {
767 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
768 w.start_structure(tag)?;
769 self.ur_ls.to_tlv(w, Tag::Context(0))?;
770 if let Some(value) = &self.username {
771 value.to_tlv(w, Tag::Context(1))?;
772 }
773 if let Some(value) = &self.credential {
774 value.to_tlv(w, Tag::Context(2))?;
775 }
776 if let Some(value) = &self.caid {
777 value.to_tlv(w, Tag::Context(3))?;
778 }
779 w.end_container()
780 }
781}
782
783impl<'a> FromTlv<'a> for ICEServerStruct<'a> {
784 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
785 if element.value.container() != Some(ContainerKind::Structure) {
786 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
787 }
788 let mut ur_ls = None;
789 let mut username = None;
790 let mut credential = None;
791 let mut caid = None;
792 loop {
793 let Some(field) = reader.next_element()? else {
794 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
795 };
796 if field.value == Value::EndOfContainer {
797 break;
798 }
799 match field.tag.context() {
800 Some(0) => ur_ls = Some(<TlvList<'a, &'a str>>::from_tlv(reader, &field)?),
801 Some(1) => username = Some(<&'a str>::from_tlv(reader, &field)?),
802 Some(2) => credential = Some(<&'a str>::from_tlv(reader, &field)?),
803 Some(3) => caid = Some(<u16>::from_tlv(reader, &field)?),
804 _ => reader.skip_value(&field)?,
808 }
809 }
810 Ok(Self {
811 ur_ls: ur_ls.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
812 username,
813 credential,
814 caid,
815 })
816 }
817}
818
819#[derive(Debug, Clone, Copy, PartialEq)]
821pub struct LocationDescriptorStruct<'a> {
822 pub location_name: &'a str,
824 pub floor_number: Nullable<i16>,
826 pub area_type: Nullable<u8>,
828}
829
830impl<'a> ToTlv for LocationDescriptorStruct<'a> {
831 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
832 w.start_structure(tag)?;
833 self.location_name.to_tlv(w, Tag::Context(0))?;
834 self.floor_number.to_tlv(w, Tag::Context(1))?;
835 self.area_type.to_tlv(w, Tag::Context(2))?;
836 w.end_container()
837 }
838}
839
840impl<'a> FromTlv<'a> for LocationDescriptorStruct<'a> {
841 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
842 if element.value.container() != Some(ContainerKind::Structure) {
843 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
844 }
845 let mut location_name = None;
846 let mut floor_number = None;
847 let mut area_type = None;
848 loop {
849 let Some(field) = reader.next_element()? else {
850 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
851 };
852 if field.value == Value::EndOfContainer {
853 break;
854 }
855 match field.tag.context() {
856 Some(0) => location_name = Some(<&'a str>::from_tlv(reader, &field)?),
857 Some(1) => floor_number = Some(<Nullable<i16>>::from_tlv(reader, &field)?),
858 Some(2) => area_type = Some(<Nullable<u8>>::from_tlv(reader, &field)?),
859 _ => reader.skip_value(&field)?,
863 }
864 }
865 Ok(Self {
866 location_name: location_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
867 floor_number: floor_number.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
868 area_type: area_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
869 })
870 }
871}
872
873#[derive(Debug, Clone, Copy, PartialEq)]
875pub struct MeasurementAccuracyRangeStruct {
876 pub range_min: i64,
878 pub range_max: i64,
880 pub percent_max: Option<u16>,
882 pub percent_min: Option<u16>,
884 pub percent_typical: Option<u16>,
886 pub fixed_max: Option<u64>,
888 pub fixed_min: Option<u64>,
890 pub fixed_typical: Option<u64>,
892}
893
894impl ToTlv for MeasurementAccuracyRangeStruct {
895 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
896 w.start_structure(tag)?;
897 self.range_min.to_tlv(w, Tag::Context(0))?;
898 self.range_max.to_tlv(w, Tag::Context(1))?;
899 if let Some(value) = &self.percent_max {
900 value.to_tlv(w, Tag::Context(2))?;
901 }
902 if let Some(value) = &self.percent_min {
903 value.to_tlv(w, Tag::Context(3))?;
904 }
905 if let Some(value) = &self.percent_typical {
906 value.to_tlv(w, Tag::Context(4))?;
907 }
908 if let Some(value) = &self.fixed_max {
909 value.to_tlv(w, Tag::Context(5))?;
910 }
911 if let Some(value) = &self.fixed_min {
912 value.to_tlv(w, Tag::Context(6))?;
913 }
914 if let Some(value) = &self.fixed_typical {
915 value.to_tlv(w, Tag::Context(7))?;
916 }
917 w.end_container()
918 }
919}
920
921impl<'a> FromTlv<'a> for MeasurementAccuracyRangeStruct {
922 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
923 if element.value.container() != Some(ContainerKind::Structure) {
924 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
925 }
926 let mut range_min = None;
927 let mut range_max = None;
928 let mut percent_max = None;
929 let mut percent_min = None;
930 let mut percent_typical = None;
931 let mut fixed_max = None;
932 let mut fixed_min = None;
933 let mut fixed_typical = None;
934 loop {
935 let Some(field) = reader.next_element()? else {
936 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
937 };
938 if field.value == Value::EndOfContainer {
939 break;
940 }
941 match field.tag.context() {
942 Some(0) => range_min = Some(<i64>::from_tlv(reader, &field)?),
943 Some(1) => range_max = Some(<i64>::from_tlv(reader, &field)?),
944 Some(2) => percent_max = Some(<u16>::from_tlv(reader, &field)?),
945 Some(3) => percent_min = Some(<u16>::from_tlv(reader, &field)?),
946 Some(4) => percent_typical = Some(<u16>::from_tlv(reader, &field)?),
947 Some(5) => fixed_max = Some(<u64>::from_tlv(reader, &field)?),
948 Some(6) => fixed_min = Some(<u64>::from_tlv(reader, &field)?),
949 Some(7) => fixed_typical = Some(<u64>::from_tlv(reader, &field)?),
950 _ => reader.skip_value(&field)?,
954 }
955 }
956 Ok(Self {
957 range_min: range_min.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
958 range_max: range_max.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
959 percent_max,
960 percent_min,
961 percent_typical,
962 fixed_max,
963 fixed_min,
964 fixed_typical,
965 })
966 }
967}
968
969#[derive(Debug, Clone, Copy, PartialEq)]
971pub struct MeasurementAccuracyStruct<'a> {
972 pub measurement_type: MeasurementTypeEnum,
974 pub measured: bool,
976 pub min_measured_value: i64,
978 pub max_measured_value: i64,
980 pub accuracy_ranges: TlvList<'a, MeasurementAccuracyRangeStruct>,
982}
983
984impl<'a> ToTlv for MeasurementAccuracyStruct<'a> {
985 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
986 w.start_structure(tag)?;
987 self.measurement_type.to_tlv(w, Tag::Context(0))?;
988 self.measured.to_tlv(w, Tag::Context(1))?;
989 self.min_measured_value.to_tlv(w, Tag::Context(2))?;
990 self.max_measured_value.to_tlv(w, Tag::Context(3))?;
991 self.accuracy_ranges.to_tlv(w, Tag::Context(4))?;
992 w.end_container()
993 }
994}
995
996impl<'a> FromTlv<'a> for MeasurementAccuracyStruct<'a> {
997 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
998 if element.value.container() != Some(ContainerKind::Structure) {
999 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1000 }
1001 let mut measurement_type = None;
1002 let mut measured = None;
1003 let mut min_measured_value = None;
1004 let mut max_measured_value = None;
1005 let mut accuracy_ranges = None;
1006 loop {
1007 let Some(field) = reader.next_element()? else {
1008 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1009 };
1010 if field.value == Value::EndOfContainer {
1011 break;
1012 }
1013 match field.tag.context() {
1014 Some(0) => {
1015 measurement_type = Some(<MeasurementTypeEnum>::from_tlv(reader, &field)?)
1016 }
1017 Some(1) => measured = Some(<bool>::from_tlv(reader, &field)?),
1018 Some(2) => min_measured_value = Some(<i64>::from_tlv(reader, &field)?),
1019 Some(3) => max_measured_value = Some(<i64>::from_tlv(reader, &field)?),
1020 Some(4) => {
1021 accuracy_ranges = Some(<TlvList<'a, MeasurementAccuracyRangeStruct>>::from_tlv(
1022 reader, &field,
1023 )?)
1024 }
1025 _ => reader.skip_value(&field)?,
1029 }
1030 }
1031 Ok(Self {
1032 measurement_type: measurement_type
1033 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1034 measured: measured.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1035 min_measured_value: min_measured_value
1036 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1037 max_measured_value: max_measured_value
1038 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1039 accuracy_ranges: accuracy_ranges
1040 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1041 })
1042 }
1043}
1044
1045#[derive(Debug, Clone, Copy, PartialEq)]
1047pub struct PowerThresholdStruct {
1048 pub power_threshold: Option<i32>,
1050 pub apparent_power_threshold: Option<i32>,
1052 pub power_threshold_source: Nullable<PowerThresholdSourceEnum>,
1054}
1055
1056impl ToTlv for PowerThresholdStruct {
1057 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1058 w.start_structure(tag)?;
1059 if let Some(value) = &self.power_threshold {
1060 value.to_tlv(w, Tag::Context(0))?;
1061 }
1062 if let Some(value) = &self.apparent_power_threshold {
1063 value.to_tlv(w, Tag::Context(1))?;
1064 }
1065 self.power_threshold_source.to_tlv(w, Tag::Context(2))?;
1066 w.end_container()
1067 }
1068}
1069
1070impl<'a> FromTlv<'a> for PowerThresholdStruct {
1071 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1072 if element.value.container() != Some(ContainerKind::Structure) {
1073 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1074 }
1075 let mut power_threshold = None;
1076 let mut apparent_power_threshold = None;
1077 let mut power_threshold_source = None;
1078 loop {
1079 let Some(field) = reader.next_element()? else {
1080 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1081 };
1082 if field.value == Value::EndOfContainer {
1083 break;
1084 }
1085 match field.tag.context() {
1086 Some(0) => power_threshold = Some(<i32>::from_tlv(reader, &field)?),
1087 Some(1) => apparent_power_threshold = Some(<i32>::from_tlv(reader, &field)?),
1088 Some(2) => {
1089 power_threshold_source = Some(<Nullable<PowerThresholdSourceEnum>>::from_tlv(
1090 reader, &field,
1091 )?)
1092 }
1093 _ => reader.skip_value(&field)?,
1097 }
1098 }
1099 Ok(Self {
1100 power_threshold,
1101 apparent_power_threshold,
1102 power_threshold_source: power_threshold_source
1103 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1104 })
1105 }
1106}
1107
1108#[derive(Debug, Clone, Copy, PartialEq)]
1110pub struct PriceStruct {
1111 pub amount: i64,
1113 pub currency: CurrencyStruct,
1115}
1116
1117impl ToTlv for PriceStruct {
1118 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1119 w.start_structure(tag)?;
1120 self.amount.to_tlv(w, Tag::Context(0))?;
1121 self.currency.to_tlv(w, Tag::Context(1))?;
1122 w.end_container()
1123 }
1124}
1125
1126impl<'a> FromTlv<'a> for PriceStruct {
1127 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1128 if element.value.container() != Some(ContainerKind::Structure) {
1129 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1130 }
1131 let mut amount = None;
1132 let mut currency = None;
1133 loop {
1134 let Some(field) = reader.next_element()? else {
1135 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1136 };
1137 if field.value == Value::EndOfContainer {
1138 break;
1139 }
1140 match field.tag.context() {
1141 Some(0) => amount = Some(<i64>::from_tlv(reader, &field)?),
1142 Some(1) => currency = Some(<CurrencyStruct>::from_tlv(reader, &field)?),
1143 _ => reader.skip_value(&field)?,
1147 }
1148 }
1149 Ok(Self {
1150 amount: amount.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1151 currency: currency.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1152 })
1153 }
1154}
1155
1156#[derive(Debug, Clone, Copy, PartialEq)]
1158pub struct SemanticTagStruct<'a> {
1159 pub mfg_code: Nullable<crate::msg::VendorId>,
1161 pub namespace_id: u8,
1163 pub tag: u8,
1165 pub label: Option<Nullable<&'a str>>,
1167}
1168
1169impl<'a> ToTlv for SemanticTagStruct<'a> {
1170 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1171 w.start_structure(tag)?;
1172 self.mfg_code.to_tlv(w, Tag::Context(0))?;
1173 self.namespace_id.to_tlv(w, Tag::Context(1))?;
1174 self.tag.to_tlv(w, Tag::Context(2))?;
1175 if let Some(value) = &self.label {
1176 value.to_tlv(w, Tag::Context(3))?;
1177 }
1178 w.end_container()
1179 }
1180}
1181
1182impl<'a> FromTlv<'a> for SemanticTagStruct<'a> {
1183 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1184 if element.value.container() != Some(ContainerKind::Structure) {
1185 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1186 }
1187 let mut mfg_code = None;
1188 let mut namespace_id = None;
1189 let mut tag = None;
1190 let mut label = None;
1191 loop {
1192 let Some(field) = reader.next_element()? else {
1193 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1194 };
1195 if field.value == Value::EndOfContainer {
1196 break;
1197 }
1198 match field.tag.context() {
1199 Some(0) => {
1200 mfg_code = Some(<Nullable<crate::msg::VendorId>>::from_tlv(reader, &field)?)
1201 }
1202 Some(1) => namespace_id = Some(<u8>::from_tlv(reader, &field)?),
1203 Some(2) => tag = Some(<u8>::from_tlv(reader, &field)?),
1204 Some(3) => label = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
1205 _ => reader.skip_value(&field)?,
1209 }
1210 }
1211 Ok(Self {
1212 mfg_code: mfg_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1213 namespace_id: namespace_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1214 tag: tag.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1215 label,
1216 })
1217 }
1218}
1219
1220#[derive(Debug, Clone, Copy, PartialEq)]
1222pub struct ViewportStruct {
1223 pub x1: u16,
1225 pub y1: u16,
1227 pub x2: u16,
1229 pub y2: u16,
1231}
1232
1233impl ToTlv for ViewportStruct {
1234 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1235 w.start_structure(tag)?;
1236 self.x1.to_tlv(w, Tag::Context(0))?;
1237 self.y1.to_tlv(w, Tag::Context(1))?;
1238 self.x2.to_tlv(w, Tag::Context(2))?;
1239 self.y2.to_tlv(w, Tag::Context(3))?;
1240 w.end_container()
1241 }
1242}
1243
1244impl<'a> FromTlv<'a> for ViewportStruct {
1245 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1246 if element.value.container() != Some(ContainerKind::Structure) {
1247 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1248 }
1249 let mut x1 = None;
1250 let mut y1 = None;
1251 let mut x2 = None;
1252 let mut y2 = None;
1253 loop {
1254 let Some(field) = reader.next_element()? else {
1255 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1256 };
1257 if field.value == Value::EndOfContainer {
1258 break;
1259 }
1260 match field.tag.context() {
1261 Some(0) => x1 = Some(<u16>::from_tlv(reader, &field)?),
1262 Some(1) => y1 = Some(<u16>::from_tlv(reader, &field)?),
1263 Some(2) => x2 = Some(<u16>::from_tlv(reader, &field)?),
1264 Some(3) => y2 = Some(<u16>::from_tlv(reader, &field)?),
1265 _ => reader.skip_value(&field)?,
1269 }
1270 }
1271 Ok(Self {
1272 x1: x1.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1273 y1: y1.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1274 x2: x2.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1275 y2: y2.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1276 })
1277 }
1278}
1279
1280#[derive(Debug, Clone, Copy, PartialEq)]
1282pub struct WebRTCSessionStruct<'a> {
1283 pub id: u16,
1285 pub peer_node_id: crate::msg::NodeId,
1287 pub peer_endpoint_id: u16,
1289 pub stream_usage: StreamUsageEnum,
1291 pub video_stream_id: Option<Nullable<u16>>,
1293 pub audio_stream_id: Option<Nullable<u16>>,
1295 pub metadata_enabled: bool,
1297 pub video_streams: Option<TlvList<'a, u16>>,
1299 pub audio_streams: Option<TlvList<'a, u16>>,
1301 pub fabric_index: crate::msg::FabricIndex,
1303}
1304
1305impl<'a> ToTlv for WebRTCSessionStruct<'a> {
1306 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1307 w.start_structure(tag)?;
1308 self.id.to_tlv(w, Tag::Context(0))?;
1309 self.peer_node_id.to_tlv(w, Tag::Context(1))?;
1310 self.peer_endpoint_id.to_tlv(w, Tag::Context(2))?;
1311 self.stream_usage.to_tlv(w, Tag::Context(3))?;
1312 if let Some(value) = &self.video_stream_id {
1313 value.to_tlv(w, Tag::Context(4))?;
1314 }
1315 if let Some(value) = &self.audio_stream_id {
1316 value.to_tlv(w, Tag::Context(5))?;
1317 }
1318 self.metadata_enabled.to_tlv(w, Tag::Context(6))?;
1319 if let Some(value) = &self.video_streams {
1320 value.to_tlv(w, Tag::Context(7))?;
1321 }
1322 if let Some(value) = &self.audio_streams {
1323 value.to_tlv(w, Tag::Context(8))?;
1324 }
1325 self.fabric_index.to_tlv(w, Tag::Context(254))?;
1326 w.end_container()
1327 }
1328}
1329
1330impl<'a> FromTlv<'a> for WebRTCSessionStruct<'a> {
1331 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1332 if element.value.container() != Some(ContainerKind::Structure) {
1333 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1334 }
1335 let mut id = None;
1336 let mut peer_node_id = None;
1337 let mut peer_endpoint_id = None;
1338 let mut stream_usage = None;
1339 let mut video_stream_id = None;
1340 let mut audio_stream_id = None;
1341 let mut metadata_enabled = None;
1342 let mut video_streams = None;
1343 let mut audio_streams = None;
1344 let mut fabric_index = None;
1345 loop {
1346 let Some(field) = reader.next_element()? else {
1347 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1348 };
1349 if field.value == Value::EndOfContainer {
1350 break;
1351 }
1352 match field.tag.context() {
1353 Some(0) => id = Some(<u16>::from_tlv(reader, &field)?),
1354 Some(1) => peer_node_id = Some(<crate::msg::NodeId>::from_tlv(reader, &field)?),
1355 Some(2) => peer_endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
1356 Some(3) => stream_usage = Some(<StreamUsageEnum>::from_tlv(reader, &field)?),
1357 Some(4) => video_stream_id = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
1358 Some(5) => audio_stream_id = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
1359 Some(6) => metadata_enabled = Some(<bool>::from_tlv(reader, &field)?),
1360 Some(7) => video_streams = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
1361 Some(8) => audio_streams = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
1362 Some(254) => {
1363 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
1364 }
1365 _ => reader.skip_value(&field)?,
1369 }
1370 }
1371 Ok(Self {
1372 id: id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1373 peer_node_id: peer_node_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1374 peer_endpoint_id: peer_endpoint_id
1375 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1376 stream_usage: stream_usage.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1377 video_stream_id,
1378 audio_stream_id,
1379 metadata_enabled: metadata_enabled
1380 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1381 video_streams,
1382 audio_streams,
1383 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1384 })
1385 }
1386}