opcua_types/
attribute.rs

1// OPCUA for Rust
2// SPDX-License-Identifier: MPL-2.0
3// Copyright (C) 2017-2022 Adam Lock
4
5// Attributes as defined in Part 4, Figure B.7
6
7// Attributes sometimes required and sometimes optional
8
9use std::{error::Error, fmt};
10
11#[derive(Debug)]
12pub struct AttributeIdError;
13
14impl fmt::Display for AttributeIdError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        write!(f, "AttributeIdError")
17    }
18}
19
20impl Error for AttributeIdError {}
21
22#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
23pub enum AttributeId {
24    NodeId = 1,
25    NodeClass = 2,
26    BrowseName = 3,
27    DisplayName = 4,
28    Description = 5,
29    WriteMask = 6,
30    UserWriteMask = 7,
31    IsAbstract = 8,
32    Symmetric = 9,
33    InverseName = 10,
34    ContainsNoLoops = 11,
35    EventNotifier = 12,
36    Value = 13,
37    DataType = 14,
38    ValueRank = 15,
39    ArrayDimensions = 16,
40    AccessLevel = 17,
41    UserAccessLevel = 18,
42    MinimumSamplingInterval = 19,
43    Historizing = 20,
44    Executable = 21,
45    UserExecutable = 22,
46    DataTypeDefinition = 23,
47    RolePermissions = 24,
48    UserRolePermissions = 25,
49    AccessRestrictions = 26,
50    AccessLevelEx = 27,
51}
52
53impl AttributeId {
54    pub fn from_u32(attribute_id: u32) -> Result<AttributeId, AttributeIdError> {
55        let attribute_id = match attribute_id {
56            1 => AttributeId::NodeId,
57            2 => AttributeId::NodeClass,
58            3 => AttributeId::BrowseName,
59            4 => AttributeId::DisplayName,
60            5 => AttributeId::Description,
61            6 => AttributeId::WriteMask,
62            7 => AttributeId::UserWriteMask,
63            8 => AttributeId::IsAbstract,
64            9 => AttributeId::Symmetric,
65            10 => AttributeId::InverseName,
66            11 => AttributeId::ContainsNoLoops,
67            12 => AttributeId::EventNotifier,
68            13 => AttributeId::Value,
69            14 => AttributeId::DataType,
70            15 => AttributeId::ValueRank,
71            16 => AttributeId::ArrayDimensions,
72            17 => AttributeId::AccessLevel,
73            18 => AttributeId::UserAccessLevel,
74            19 => AttributeId::MinimumSamplingInterval,
75            20 => AttributeId::Historizing,
76            21 => AttributeId::Executable,
77            22 => AttributeId::UserExecutable,
78            23 => AttributeId::DataTypeDefinition,
79            24 => AttributeId::RolePermissions,
80            25 => AttributeId::UserRolePermissions,
81            26 => AttributeId::AccessRestrictions,
82            27 => AttributeId::AccessLevelEx,
83            _ => {
84                debug!("Invalid attribute id {}", attribute_id);
85                return Err(AttributeIdError);
86            }
87        };
88        Ok(attribute_id)
89    }
90}