opcua_types/
add_node_attributes.rs1use crate::match_extension_object_owned;
2
3use super::{
4 extension_object::ExtensionObject, status_code::StatusCode, DataTypeAttributes,
5 GenericAttributes, MethodAttributes, ObjectAttributes, ObjectTypeAttributes,
6 ReferenceTypeAttributes, VariableAttributes, VariableTypeAttributes, ViewAttributes,
7};
8
9#[derive(Clone, Debug)]
10pub enum AddNodeAttributes {
12 Object(ObjectAttributes),
14 Variable(VariableAttributes),
16 Method(MethodAttributes),
18 ObjectType(ObjectTypeAttributes),
20 VariableType(VariableTypeAttributes),
22 ReferenceType(ReferenceTypeAttributes),
24 DataType(DataTypeAttributes),
26 View(ViewAttributes),
28 Generic(GenericAttributes),
30 None,
32}
33
34impl AddNodeAttributes {
35 pub fn from_extension_object(obj: ExtensionObject) -> Result<Self, StatusCode> {
37 if obj.is_null() {
38 return Ok(Self::None);
39 }
40 match_extension_object_owned!(obj,
41 v: ObjectAttributes => Ok(Self::Object(v)),
42 v: MethodAttributes => Ok(Self::Method(v)),
43 v: VariableAttributes => Ok(Self::Variable(v)),
44 v: ViewAttributes => Ok(Self::View(v)),
45 v: ObjectTypeAttributes => Ok(Self::ObjectType(v)),
46 v: VariableTypeAttributes => Ok(Self::VariableType(v)),
47 v: ReferenceTypeAttributes => Ok(Self::ReferenceType(v)),
48 v: DataTypeAttributes => Ok(Self::DataType(v)),
49 v: GenericAttributes => Ok(Self::Generic(v)),
50 _ => Err(StatusCode::BadNodeAttributesInvalid),
51 )
52 }
53
54 pub fn as_extension_object(&self) -> ExtensionObject {
56 match self.clone() {
57 AddNodeAttributes::Object(o) => ExtensionObject::from_message(o),
58 AddNodeAttributes::Variable(o) => ExtensionObject::from_message(o),
59 AddNodeAttributes::Method(o) => ExtensionObject::from_message(o),
60 AddNodeAttributes::ObjectType(o) => ExtensionObject::from_message(o),
61 AddNodeAttributes::VariableType(o) => ExtensionObject::from_message(o),
62 AddNodeAttributes::ReferenceType(o) => ExtensionObject::from_message(o),
63 AddNodeAttributes::DataType(o) => ExtensionObject::from_message(o),
64 AddNodeAttributes::View(o) => ExtensionObject::from_message(o),
65 AddNodeAttributes::Generic(o) => ExtensionObject::from_message(o),
66 AddNodeAttributes::None => ExtensionObject::null(),
67 }
68 }
69}