1use std::{error::Error, fmt};
12
13use tracing::debug;
14
15#[derive(Debug)]
16pub struct AttributeIdError;
18
19impl fmt::Display for AttributeIdError {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 write!(f, "AttributeIdError")
22 }
23}
24
25impl Error for AttributeIdError {}
26
27#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
28#[repr(u32)]
29pub enum AttributeId {
31 NodeId = 1,
33 NodeClass = 2,
35 BrowseName = 3,
37 DisplayName = 4,
39 Description = 5,
41 WriteMask = 6,
43 UserWriteMask = 7,
45 IsAbstract = 8,
47 Symmetric = 9,
49 InverseName = 10,
51 ContainsNoLoops = 11,
53 EventNotifier = 12,
55 Value = 13,
57 DataType = 14,
59 ValueRank = 15,
61 ArrayDimensions = 16,
63 AccessLevel = 17,
65 UserAccessLevel = 18,
67 MinimumSamplingInterval = 19,
69 Historizing = 20,
71 Executable = 21,
73 UserExecutable = 22,
75 DataTypeDefinition = 23,
77 RolePermissions = 24,
79 UserRolePermissions = 25,
81 AccessRestrictions = 26,
83 AccessLevelEx = 27,
85}
86
87impl AttributeId {
88 pub fn from_u32(attribute_id: u32) -> Result<AttributeId, AttributeIdError> {
90 let attribute_id = match attribute_id {
91 1 => AttributeId::NodeId,
92 2 => AttributeId::NodeClass,
93 3 => AttributeId::BrowseName,
94 4 => AttributeId::DisplayName,
95 5 => AttributeId::Description,
96 6 => AttributeId::WriteMask,
97 7 => AttributeId::UserWriteMask,
98 8 => AttributeId::IsAbstract,
99 9 => AttributeId::Symmetric,
100 10 => AttributeId::InverseName,
101 11 => AttributeId::ContainsNoLoops,
102 12 => AttributeId::EventNotifier,
103 13 => AttributeId::Value,
104 14 => AttributeId::DataType,
105 15 => AttributeId::ValueRank,
106 16 => AttributeId::ArrayDimensions,
107 17 => AttributeId::AccessLevel,
108 18 => AttributeId::UserAccessLevel,
109 19 => AttributeId::MinimumSamplingInterval,
110 20 => AttributeId::Historizing,
111 21 => AttributeId::Executable,
112 22 => AttributeId::UserExecutable,
113 23 => AttributeId::DataTypeDefinition,
114 24 => AttributeId::RolePermissions,
115 25 => AttributeId::UserRolePermissions,
116 26 => AttributeId::AccessRestrictions,
117 27 => AttributeId::AccessLevelEx,
118 _ => {
119 debug!("Invalid attribute id {}", attribute_id);
120 return Err(AttributeIdError);
121 }
122 };
123 Ok(attribute_id)
124 }
125}