pub enum Variant {
Show 27 variants
Empty,
Boolean(bool),
SByte(i8),
Byte(u8),
Int16(i16),
UInt16(u16),
Int32(i32),
UInt32(u32),
Int64(i64),
UInt64(u64),
Float(f32),
Double(f64),
String(UAString),
DateTime(Box<DateTime>),
Guid(Box<Guid>),
StatusCode(StatusCode),
ByteString(ByteString),
XmlElement(XmlElement),
QualifiedName(Box<QualifiedName>),
LocalizedText(Box<LocalizedText>),
NodeId(Box<NodeId>),
ExpandedNodeId(Box<ExpandedNodeId>),
ExtensionObject(ExtensionObject),
Variant(Box<Variant>),
DataValue(Box<DataValue>),
DiagnosticInfo(Box<DiagnosticInfo>),
Array(Box<Array>),
}Expand description
A Variant holds built-in OPC UA data types, including single and multi dimensional arrays,
data values and extension objects.
As variants may be passed around a lot on the stack, Boxes are used for more complex types to keep the size of this type down a bit, especially when used in arrays.
Variants§
Empty
Empty type has no value. It is equivalent to a Null value (part 6 5.1.6)
Boolean(bool)
Boolean
SByte(i8)
Signed byte
Byte(u8)
Unsigned byte
Int16(i16)
Signed 16-bit int
UInt16(u16)
Unsigned 16-bit int
Int32(i32)
Signed 32-bit int
UInt32(u32)
Unsigned 32-bit int
Int64(i64)
Signed 64-bit int
UInt64(u64)
Unsigned 64-bit int
Float(f32)
Float
Double(f64)
Double
String(UAString)
String
DateTime(Box<DateTime>)
DateTime
Guid(Box<Guid>)
Guid
StatusCode(StatusCode)
StatusCode
ByteString(ByteString)
ByteString
XmlElement(XmlElement)
XmlElement
QualifiedName(Box<QualifiedName>)
QualifiedName
LocalizedText(Box<LocalizedText>)
LocalizedText
NodeId(Box<NodeId>)
NodeId
ExpandedNodeId(Box<ExpandedNodeId>)
ExpandedNodeId
ExtensionObject(ExtensionObject)
ExtensionObject
Variant(Box<Variant>)
Variant containing a nested variant.
DataValue(Box<DataValue>)
DataValue
DiagnosticInfo(Box<DiagnosticInfo>)
DiagnosticInfo
Array(Box<Array>)
Single dimension array which can contain any scalar type, all the same type. Nested
arrays will be rejected.
To represent matrices or nested arrays, set the array_dimensions field
on the Array.
Implementations§
Source§impl Variant
impl Variant
Sourcepub fn serialize_variant_value(
&self,
stream: &mut JsonStreamWriter<&mut dyn Write>,
ctx: &Context<'_>,
) -> EncodingResult<()>
pub fn serialize_variant_value( &self, stream: &mut JsonStreamWriter<&mut dyn Write>, ctx: &Context<'_>, ) -> EncodingResult<()>
JSON serialize the value of a variant using OPC-UA JSON encoding.
Note that this serializes just the value. To include the type ID,
use JsonEncodable::encode.
Source§impl Variant
impl Variant
Sourcepub fn get_variant_default(ty: VariantScalarTypeId) -> Variant
pub fn get_variant_default(ty: VariantScalarTypeId) -> Variant
Get a default variant of the given type.
Sourcepub fn xml_decode_variant_value(
stream: &mut XmlStreamReader<&mut dyn Read>,
context: &Context<'_>,
key: &str,
) -> EncodingResult<Self>
pub fn xml_decode_variant_value( stream: &mut XmlStreamReader<&mut dyn Read>, context: &Context<'_>, key: &str, ) -> EncodingResult<Self>
Decode an XML variant value from stream, consuming the rest of the current element.
Source§impl Variant
impl Variant
Sourcepub fn value_byte_len(&self, ctx: &Context<'_>) -> usize
pub fn value_byte_len(&self, ctx: &Context<'_>) -> usize
Get the value in bytes of the contents of this variant if it is serialize to OPC-UA binary.
To get the full byte length including type ID, use
BinaryEncodable::encode
Sourcepub fn encode_value<S: Write + ?Sized>(
&self,
stream: &mut S,
ctx: &Context<'_>,
) -> EncodingResult<()>
pub fn encode_value<S: Write + ?Sized>( &self, stream: &mut S, ctx: &Context<'_>, ) -> EncodingResult<()>
Encode the value of this variant as binary to the given stream.
Note that to encode a full variant with type ID and other details,
use BinaryEncodable::encode
Source§impl Variant
impl Variant
Sourcepub fn test_encoding_flag(encoding_mask: u8, flag: u8) -> bool
pub fn test_encoding_flag(encoding_mask: u8, flag: u8) -> bool
Test the flag (convenience method)
Sourcepub fn cast<'a>(&self, target_type: impl Into<VariantTypeId<'a>>) -> Variant
pub fn cast<'a>(&self, target_type: impl Into<VariantTypeId<'a>>) -> Variant
Performs an EXPLICIT cast from one type to another. This will first attempt an implicit conversion and only then attempt to cast. Casting is potentially lossy.
Sourcepub fn convert<'a>(&self, target_type: impl Into<VariantTypeId<'a>>) -> Variant
pub fn convert<'a>(&self, target_type: impl Into<VariantTypeId<'a>>) -> Variant
Performs an IMPLICIT conversion from one type to another
Sourcepub fn type_id(&self) -> VariantTypeId<'_>
pub fn type_id(&self) -> VariantTypeId<'_>
Get the type ID of this variant. This can be useful to work with the variant abstractly, and check if the variant is of the expected type and dimensions.
Sourcepub fn scalar_type_id(&self) -> Option<VariantScalarTypeId>
pub fn scalar_type_id(&self) -> Option<VariantScalarTypeId>
Get the scalar type id of this variant, if present.
This returns None only if the variant is empty.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this variant is Variant::Empty.
Sourcepub fn is_numeric(&self) -> bool
pub fn is_numeric(&self) -> bool
Tests and returns true if the variant holds a numeric type
Sourcepub fn as_array(&self) -> Option<&Vec<Variant>>
pub fn as_array(&self) -> Option<&Vec<Variant>>
Try to get the inner array if this is an array variant.
Sourcepub fn is_array_of_type(&self, variant_type: VariantScalarTypeId) -> bool
pub fn is_array_of_type(&self, variant_type: VariantScalarTypeId) -> bool
Check if this is an array of the given variant type.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Tests that the variant is in a valid state. In particular for arrays ensuring that the values are all acceptable and for a multi dimensional array that the dimensions equal the actual values.
Sourcepub fn data_type(&self) -> Option<ExpandedNodeId>
pub fn data_type(&self) -> Option<ExpandedNodeId>
Returns the scalar data type. Returns None if the variant is Empty.
Sourcepub fn to_byte_array(&self) -> Result<Self, ArrayError>
pub fn to_byte_array(&self) -> Result<Self, ArrayError>
This function is for a special edge case of converting a byte string to a single array of bytes
Sourcepub fn set_range_of(
&mut self,
range: &NumericRange,
other: &Variant,
) -> Result<(), StatusCode>
pub fn set_range_of( &mut self, range: &NumericRange, other: &Variant, ) -> Result<(), StatusCode>
Set a range of values in this variant using a different variant.
Sourcepub fn range_of_owned(self, range: &NumericRange) -> Result<Variant, StatusCode>
pub fn range_of_owned(self, range: &NumericRange) -> Result<Variant, StatusCode>
This function gets a range of values from the variant if it is an array, or returns the variant itself.
Sourcepub fn range_of(&self, range: &NumericRange) -> Result<Variant, StatusCode>
pub fn range_of(&self, range: &NumericRange) -> Result<Variant, StatusCode>
This function gets a range of values from the variant if it is an array, or returns a clone of the variant itself.
Sourcepub fn try_cast_to<T: TryFromVariant>(self) -> Result<T, Error>
pub fn try_cast_to<T: TryFromVariant>(self) -> Result<T, Error>
Try to cast this variant to the type T.
Source§impl Variant
impl Variant
Sourcepub fn from_nodeset(
val: &XmlVariant,
ctx: &Context<'_>,
) -> EncodingResult<Variant>
pub fn from_nodeset( val: &XmlVariant, ctx: &Context<'_>, ) -> EncodingResult<Variant>
Create a Variant value from a NodeSet2 variant object.
Note that this is different from the FromXml implementation of Variant,
which accepts an untyped XML node.
Trait Implementations§
Source§impl BinaryDecodable for Variant
impl BinaryDecodable for Variant
Source§fn decode<S: Read + ?Sized>(
stream: &mut S,
ctx: &Context<'_>,
) -> EncodingResult<Self>
fn decode<S: Read + ?Sized>( stream: &mut S, ctx: &Context<'_>, ) -> EncodingResult<Self>
BadDecodingError as soon as possible.Source§impl BinaryEncodable for Variant
impl BinaryEncodable for Variant
Source§fn byte_len(&self, ctx: &Context<'_>) -> usize
fn byte_len(&self, ctx: &Context<'_>) -> usize
encode were called.
This may be called prior to writing to ensure the correct amount of space is available.Source§fn encode<S: Write + ?Sized>(
&self,
stream: &mut S,
ctx: &Context<'_>,
) -> EncodingResult<()>
fn encode<S: Write + ?Sized>( &self, stream: &mut S, ctx: &Context<'_>, ) -> EncodingResult<()>
Source§fn override_encoding(&self) -> Option<BuiltInDataEncoding>
fn override_encoding(&self) -> Option<BuiltInDataEncoding>
Source§impl Display for Variant
This implementation is mainly for debugging / convenience purposes, to eliminate some of the
noise in common types from using the Debug trait.
impl Display for Variant
This implementation is mainly for debugging / convenience purposes, to eliminate some of the noise in common types from using the Debug trait.