Skip to main content

ua_client/
types.rs

1use opcua::types::{NodeClass, NodeId};
2
3#[derive(Debug, Clone)]
4pub struct TreeChild {
5    pub node_id: NodeId,
6    pub browse_name: String,
7    pub display_name: String,
8    pub node_class: NodeClass,
9    pub has_children: bool,
10}
11
12#[derive(Debug, Clone)]
13pub struct NodeSummary {
14    pub node_id: NodeId,
15    pub attributes: Vec<NodeAttribute>,
16}
17
18#[derive(Debug, Clone)]
19pub struct NodeAttribute {
20    pub name: String,
21    pub value: ValueTree,
22}
23
24#[derive(Debug, Clone)]
25pub enum ValueTree {
26    Null,
27    Leaf(String),
28    Array(Vec<ValueTree>),
29    Object(Vec<(String, ValueTree)>),
30}
31
32impl ValueTree {
33    pub fn format_inline(&self) -> String {
34        use std::fmt::Write as _;
35        fn write(v: &ValueTree, out: &mut String) {
36            match v {
37                ValueTree::Null => out.push_str("<null>"),
38                ValueTree::Leaf(s) => out.push_str(s),
39                ValueTree::Array(items) => {
40                    out.push('[');
41                    for (i, item) in items.iter().enumerate() {
42                        if i > 0 {
43                            out.push_str(", ");
44                        }
45                        write(item, out);
46                    }
47                    out.push(']');
48                }
49                ValueTree::Object(fields) => {
50                    out.push('{');
51                    for (i, (k, val)) in fields.iter().enumerate() {
52                        if i > 0 {
53                            out.push_str(", ");
54                        }
55                        let _ = write!(out, "{k}: ");
56                        write(val, out);
57                    }
58                    out.push('}');
59                }
60            }
61        }
62        let mut out = String::new();
63        write(self, &mut out);
64        out
65    }
66}
67
68#[derive(Debug, Clone)]
69pub struct AuthSpec {
70    pub mode: AuthMode,
71    pub username: String,
72    pub password: String,
73    pub cert_path: String,
74    pub key_path: String,
75}
76
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
78pub enum AuthMode {
79    #[default]
80    Anonymous,
81    UserName,
82    Certificate,
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
86pub enum SecurityMode {
87    #[default]
88    None,
89    Sign,
90    SignAndEncrypt,
91}
92
93impl SecurityMode {
94    pub fn label(self) -> &'static str {
95        match self {
96            SecurityMode::None => "None",
97            SecurityMode::Sign => "Sign",
98            SecurityMode::SignAndEncrypt => "SignAndEncrypt",
99        }
100    }
101}
102
103#[derive(Debug, Clone)]
104pub struct EndpointInfo {
105    pub endpoint_url: String,
106    pub security_policy: String,
107    pub security_policy_uri: String,
108    pub security_mode: SecurityMode,
109    pub security_level: u8,
110    pub supports_anonymous: bool,
111    pub supports_username: bool,
112    pub supports_certificate: bool,
113}
114
115#[derive(Debug, Clone)]
116pub struct MethodArgument {
117    pub name: String,
118    pub description: String,
119    pub data_type: NodeId,
120    pub value_rank: i32,
121    pub type_label: String,
122}
123
124#[derive(Debug, Clone)]
125pub struct MethodSignature {
126    pub parent_object: NodeId,
127    pub method_node: NodeId,
128    pub method_display_name: String,
129    pub inputs: Vec<MethodArgument>,
130    pub outputs: Vec<MethodArgument>,
131}
132
133#[derive(Debug, Clone)]
134pub struct MethodCallOutcome {
135    pub status: String,
136    pub outputs: Vec<ValueTree>,
137    pub input_arg_errors: Vec<Option<String>>,
138}
139
140#[derive(Debug, Clone)]
141pub enum AttrSpec {
142    Value { data_type: NodeId, value_rank: i32 },
143    LocalizedText,
144    QualifiedName,
145    Boolean,
146    UInt32,
147    Byte,
148    Double,
149    Int32,
150}
151
152#[derive(Debug, Clone)]
153pub struct WriteTarget {
154    pub spec: AttrSpec,
155    pub type_label: String,
156    pub current_value: String,
157}
158
159#[derive(Debug, Clone)]
160pub struct SubscriptionRow {
161    pub node_id: NodeId,
162    pub display_name: String,
163    pub value: String,
164    pub status: String,
165    pub timestamp: Option<String>,
166}
167
168#[derive(Debug, Clone)]
169pub struct ReferenceRow {
170    pub reference_type: String,
171    pub is_forward: bool,
172    pub target_node_id: NodeId,
173    pub target_browse_name: String,
174    pub target_display_name: String,
175    pub target_node_class: NodeClass,
176}
177
178#[derive(Debug, Clone, Copy, PartialEq, Eq)]
179pub enum LogLevel {
180    Error,
181    Warn,
182    Info,
183    Debug,
184    Trace,
185}
186
187#[derive(Debug, Clone)]
188pub struct LogLine {
189    pub level: LogLevel,
190    pub target: String,
191    pub message: String,
192}