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    /// Render this value on a single line.
34    pub fn format_inline(&self) -> String {
35        use std::fmt::Write as _;
36        fn write(v: &ValueTree, out: &mut String) {
37            match v {
38                ValueTree::Null => out.push_str("<null>"),
39                ValueTree::Leaf(s) => out.push_str(s),
40                ValueTree::Array(items) => {
41                    out.push('[');
42                    for (i, item) in items.iter().enumerate() {
43                        if i > 0 {
44                            out.push_str(", ");
45                        }
46                        write(item, out);
47                    }
48                    out.push(']');
49                }
50                ValueTree::Object(fields) => {
51                    out.push('{');
52                    for (i, (k, val)) in fields.iter().enumerate() {
53                        if i > 0 {
54                            out.push_str(", ");
55                        }
56                        let _ = write!(out, "{k}: ");
57                        write(val, out);
58                    }
59                    out.push('}');
60                }
61            }
62        }
63        let mut out = String::new();
64        write(self, &mut out);
65        out
66    }
67}
68
69#[derive(Debug, Clone)]
70pub struct AuthSpec {
71    pub mode: AuthMode,
72    pub username: String,
73    pub password: String,
74    pub cert_path: String,
75    pub key_path: String,
76}
77
78#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
79pub enum AuthMode {
80    #[default]
81    Anonymous,
82    UserName,
83    Certificate,
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq)]
87pub enum SecurityMode {
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 struct ReferenceRow {
142    pub reference_type: String,
143    pub is_forward: bool,
144    pub target_node_id: NodeId,
145    pub target_browse_name: String,
146    pub target_display_name: String,
147    pub target_node_class: NodeClass,
148}
149
150#[derive(Debug, Clone, Copy, PartialEq, Eq)]
151pub enum LogLevel {
152    Error,
153    Warn,
154    Info,
155    Debug,
156    Trace,
157}
158
159#[derive(Debug, Clone)]
160pub struct LogLine {
161    pub level: LogLevel,
162    pub target: String,
163    pub message: String,
164}