opcua_types/
lib.rs

1// OPCUA for Rust
2// SPDX-License-Identifier: MPL-2.0
3// Copyright (C) 2017-2022 Adam Lock
4
5//! The OPC UA Types module contains data types and enumerations for OPC UA.
6//!
7//! This includes:
8//!
9//! 1. All of the built-in data types described in OPC Part 6 Chapter 5 that are encodable.
10//! 2. All of the standard data types described in OPC Part 3 Chapter 8 (if not covered by 1.).
11//! 3. Autogenerated data types and request / responses as described in OPC Part 4.
12//!
13//! For the built-in data types, the module provides functions
14
15#[macro_use]
16extern crate log;
17#[macro_use]
18extern crate lazy_static;
19#[macro_use]
20extern crate bitflags;
21#[macro_use]
22extern crate serde_derive;
23#[cfg(test)]
24extern crate serde_json;
25
26///Contains constants recognized by OPC UA clients and servers to describe various protocols and
27/// profiles used during communication and encryption.
28pub mod profiles {
29    pub const TRANSPORT_PROFILE_URI_BINARY: &str =
30        "http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary";
31
32    pub const SECURITY_USER_TOKEN_POLICY_ANONYMOUS: &str =
33        "http://opcfoundation.org/UA-Profile/Security/UserToken/Anonymous";
34    pub const SECURITY_USER_TOKEN_POLICY_USERPASS: &str =
35        "http://opcfoundation.org/UA-Profile/ Security/UserToken-Server/UserNamePassword";
36}
37
38pub mod constants {
39    /// Default OPC UA port number. Used by a discovery server. Other servers would normally run
40    /// on a different port. So OPC UA for Rust does not use this nr by default but it is used
41    /// implicitly in opc.tcp:// urls and elsewhere.
42    pub const DEFAULT_OPC_UA_SERVER_PORT: u16 = 4840;
43    /// Maximum number of elements in an array
44    pub const MAX_ARRAY_LENGTH: usize = 1000;
45    /// Maximum size of a string in chars
46    pub const MAX_STRING_LENGTH: usize = 65535;
47    /// Maximum size of a byte string in bytes
48    pub const MAX_BYTE_STRING_LENGTH: usize = 65535;
49    /// Maximum size of a certificate to send
50    pub const MAX_CERTIFICATE_LENGTH: u32 = 32767;
51
52    /// URI supplied for the None security policy
53    pub const SECURITY_POLICY_NONE_URI: &str = "http://opcfoundation.org/UA/SecurityPolicy#None";
54    /// String used as shorthand in config files, debug etc.for `None` security policy
55    pub const SECURITY_POLICY_NONE: &str = "None";
56}
57
58// Attributes mask bits
59bitflags! {
60    pub struct AttributesMask: u32 {
61        /// Indicates if the AccessLevel Attribute is set.
62        const ACCESS_LEVEL = 1;
63        /// Indicates if the ArrayDimensions Attribute is set.
64        const ARRAY_DIMENSIONS = 1 << 1;
65        /// Indicates if the ContainsNoLoops Attribute is set.
66        const CONTAINS_NO_LOOPS = 1 << 3;
67        /// Indicates if the DataType Attribute is set.
68        const DATA_TYPE = 1 << 4;
69        /// Indicates if the Description Attribute is set.
70        const DESCRIPTION = 1 << 5;
71        /// Indicates if the DisplayName Attribute is set.
72        const DISPLAY_NAME = 1 << 6;
73        /// Indicates if the EventNotifier Attribute is set.
74        const EVENT_NOTIFIER = 1 << 7;
75        /// Indicates if the Executable Attribute is set.
76        const EXECUTABLE = 1 << 8;
77        /// Indicates if the Historizing Attribute is set.
78        const HISTORIZING = 1 << 9;
79        /// Indicates if the InverseName Attribute is set.
80        const INVERSE_NAME = 1 << 10;
81        /// Indicates if the IsAbstract Attribute is set.
82        const IS_ABSTRACT = 1 << 11;
83        /// Indicates if the MinimumSamplingInterval Attribute is set.
84        const MINIMUM_SAMPLING_INTERVAL = 1 << 12;
85        /// Indicates if the Symmetric Attribute is set.
86        const SYMMETRIC = 1 << 15;
87        /// Indicates if the UserAccessLevel Attribute is set.
88        const USER_ACCESS_LEVEL = 1 << 16;
89        /// Indicates if the UserExecutable Attribute is set.
90        const USER_EXECUTABLE = 1 << 17;
91        /// Indicates if the UserWriteMask Attribute is set.
92        const USER_WRITE_MASK = 1 << 18;
93        /// Indicates if the ValueRank Attribute is set.
94        const VALUE_RANK = 1 << 19;
95        /// Indicates if the WriteMask Attribute is set.
96        const WRITE_MASK = 1 << 20;
97        /// Indicates if the Value Attribute is set
98        const VALUE = 1 << 21;
99    }
100}
101
102// Write mask bits (similar but different to AttributesMask)
103//
104// See Part 3, Table 43
105bitflags! {
106    pub struct WriteMask: u32 {
107        /// Indicates if the AccessLevel Attribute is writable.
108        const ACCESS_LEVEL = 1;
109        /// Indicates if the ArrayDimensions Attribute is writable.
110        const ARRAY_DIMENSIONS = 1 << 1;
111        ///Indicates if the BrowseName Attribute is writable.
112        const BROWSE_NAME = 1 << 2;
113        /// Indicates if the ContainsNoLoops Attribute is writable.
114        const CONTAINS_NO_LOOPS = 1 << 3;
115        /// Indicates if the DataType Attribute is writable.
116        const DATA_TYPE = 1 << 4;
117        /// Indicates if the Description Attribute is writable.
118        const DESCRIPTION = 1 << 5;
119        /// Indicates if the DisplayName Attribute is writable.
120        const DISPLAY_NAME = 1 << 6;
121        /// Indicates if the EventNotifier Attribute is writable.
122        const EVENT_NOTIFIER = 1 << 7;
123        /// Indicates if the Executable Attribute is writable.
124        const EXECUTABLE = 1 << 8;
125        /// Indicates if the Historizing Attribute is writable.
126        const HISTORIZING = 1 << 9;
127        /// Indicates if the InverseName Attribute is writable.
128        const INVERSE_NAME = 1 << 10;
129        /// Indicates if the IsAbstract Attribute is writable.
130        const IS_ABSTRACT = 1 << 11;
131        /// Indicates if the MinimumSamplingInterval Attribute is writable.
132        const MINIMUM_SAMPLING_INTERVAL = 1 << 12;
133        /// Indicates if the NodeClass Attribute is writable.
134        const NODE_CLASS = 1 << 13;
135        /// Indicates if the NodeId Attribute is writable.
136        const NODE_ID = 1 << 14;
137        /// Indicates if the Symmetric Attribute is writable.
138        const SYMMETRIC = 1 << 15;
139        /// Indicates if the UserAccessLevel Attribute is writable.
140        const USER_ACCESS_LEVEL = 1 << 16;
141        /// Indicates if the UserExecutable Attribute is writable.
142        const USER_EXECUTABLE = 1 << 17;
143        /// Indicates if the UserWriteMask Attribute is writable.
144        const USER_WRITE_MASK = 1 << 18;
145        /// Indicates if the ValueRank Attribute is writable.
146        const VALUE_RANK = 1 << 19;
147        /// Indicates if the WriteMask Attribute is writable.
148        const WRITE_MASK = 1 << 20;
149        /// Indicates if the Value Attribute is writable for a VariableType. It does not apply for Variables
150        /// since this is handled by the AccessLevel and UserAccessLevel Attributes for the Variable.
151        /// For Variables this bit shall be set to 0.
152        const VALUE_FOR_VARIABLE_TYPE = 1 << 21;
153        /// Indicates if the DataTypeDefinition Attribute is writable.
154        const DATA_TYPE_DEFINITION = 1 << 22;
155        /// Indicates if the RolePermissions Attribute is writable.
156        const ROLE_PERMISSIONS = 1 << 23;
157        /// Indicates if the AccessRestrictions Attribute is writable
158        const ACCESS_RESTRICTIONS = 1 << 24;
159        /// Indicates if the AccessLevelEx Attribute is writable
160        const ACCESS_LEVEL_EX = 1 << 25;
161
162        // Bits 26-31. Reserved for future use. Shall always be zero.
163    }
164}
165
166// Bits that control the reference description coming back from browse()
167bitflags! {
168    pub struct BrowseDescriptionResultMask: u32 {
169        const RESULT_MASK_REFERENCE_TYPE = 1;
170        const RESULT_MASK_IS_FORWARD = 1 << 1;
171        const RESULT_MASK_NODE_CLASS = 1 << 2;
172        const RESULT_MASK_BROWSE_NAME = 1 << 3;
173        const RESULT_MASK_DISPLAY_NAME = 1 << 4;
174        const RESULT_MASK_TYPE_DEFINITION = 1 << 5;
175    }
176}
177
178// Bits for a node class mask
179bitflags! {
180    pub struct NodeClassMask: u32 {
181        const OBJECT = 1;
182        const VARIABLE = 1 << 1;
183        const METHOD = 1 << 2;
184        const OBJECT_TYPE = 1 << 3;
185        const VARIABLE_TYPE = 1 << 4;
186        const REFERENCE_TYPE = 1 << 5;
187        const DATA_TYPE = 1 << 6;
188        const VIEW = 1 << 7;
189    }
190}
191
192#[rustfmt::skip]
193mod status_codes;
194#[rustfmt::skip]
195pub mod node_ids;
196
197pub mod argument;
198pub mod array;
199pub mod attribute;
200pub mod basic_types;
201pub mod byte_string;
202pub mod data_types;
203pub mod data_value;
204pub mod date_time;
205pub mod diagnostic_info;
206pub mod encoding;
207pub mod extension_object;
208pub mod guid;
209pub mod localized_text;
210pub mod node_id;
211pub mod notification_message;
212pub mod numeric_range;
213pub mod operand;
214pub mod qualified_name;
215pub mod relative_path;
216pub mod request_header;
217pub mod response_header;
218
219#[rustfmt::skip]
220pub mod service_types;
221pub mod status_code;
222pub mod string;
223pub mod variant;
224
225pub use crate::{
226    argument::*, array::*, attribute::*, basic_types::*, byte_string::*, data_types::*,
227    data_value::*, date_time::*, diagnostic_info::*, encoding::*, extension_object::*, guid::*,
228    localized_text::*, node_id::*, node_ids::*, numeric_range::*, operand::*, qualified_name::*,
229    request_header::*, response_header::*, service_types::*, status_code::*, string::*, variant::*,
230};
231
232#[cfg(test)]
233mod tests;