Skip to main content

opcua_kit/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3
4/// Client interpretation of the severity field of an OPC UA StatusCode.
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub enum Severity {
7    /// The operation succeeded.
8    Good,
9    /// The result may be unsuitable for some uses.
10    Uncertain,
11    /// The operation failed or the severity uses the reserved encoding.
12    Bad,
13}
14
15/// Classifies the two severity bits, independently of the subcode and flags.
16///
17/// ```
18/// use opcua_kit::{status_severity, Severity};
19///
20/// assert_eq!(status_severity(0x0000_0000), Severity::Good);
21/// assert_eq!(status_severity(0x4000_0000), Severity::Uncertain);
22/// assert_eq!(status_severity(0x8000_0000), Severity::Bad);
23/// assert_eq!(status_severity(0xFFFF_FFFF), Severity::Bad);
24/// ```
25pub const fn status_severity(status_code: u32) -> Severity {
26    match status_code >> 30 {
27        0 => Severity::Good,
28        1 => Severity::Uncertain,
29        _ => Severity::Bad,
30    }
31}