1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::ua;
/// Wrapper for event ID from [`open62541_sys`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EventId(ua::ByteString);
impl EventId {
/// Creates event ID from raw string.
///
/// This may return [`None`] when the string is invalid (as defined by OPC UA).
///
/// Note: The given string should not be empty.
#[must_use]
pub(crate) fn new(event_id: ua::ByteString) -> Option<Self> {
// Unset event IDs are not expected.
if event_id.is_invalid() {
return None;
}
// An empty string would be a strange event ID. Nothing bad would happen since this is not
// an invalid string (as defined by OPC UA) but it might indicate an error.
debug_assert!(!event_id.is_empty());
Some(Self(event_id))
}
/// Gets underlying representation.
#[allow(dead_code)] // It is unclear whether external callers need the raw event ID.
#[must_use]
pub(crate) const fn as_byte_string(&self) -> &ua::ByteString {
&self.0
}
/// Gets underlying representation.
#[allow(dead_code)] // It is unclear whether external callers need the raw event ID.
#[must_use]
pub(crate) fn to_byte_string(&self) -> ua::ByteString {
self.0.clone()
}
/// Gets underlying representation.
#[allow(dead_code)] // It is unclear whether external callers need the raw event ID.
#[must_use]
pub(crate) fn into_byte_string(self) -> ua::ByteString {
self.0
}
}