#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PcResult {
Acceptance,
UserRejection,
NoReason,
AbstractSyntaxNotSupported,
TransferSyntaxesNotSupported,
}
impl PcResult {
pub fn from_u8(v: u8) -> Self {
match v {
0 => Self::Acceptance,
1 => Self::UserRejection,
2 => Self::NoReason,
3 => Self::AbstractSyntaxNotSupported,
_ => Self::TransferSyntaxesNotSupported,
}
}
pub fn to_u8(self) -> u8 {
match self {
Self::Acceptance => 0,
Self::UserRejection => 1,
Self::NoReason => 2,
Self::AbstractSyntaxNotSupported => 3,
Self::TransferSyntaxesNotSupported => 4,
}
}
pub fn is_accepted(self) -> bool {
self == Self::Acceptance
}
}
#[derive(Debug, Clone)]
pub struct PresentationContextRq {
pub id: u8,
pub abstract_syntax: String,
pub transfer_syntaxes: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct PresentationContextAc {
pub id: u8,
pub result: PcResult,
pub transfer_syntax: String,
pub abstract_syntax: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn pc_result_roundtrip() {
for v in 0u8..=4 {
let r = PcResult::from_u8(v);
assert_eq!(r.to_u8(), v);
}
}
#[test]
fn pc_result_is_accepted() {
assert!(PcResult::Acceptance.is_accepted());
assert!(!PcResult::UserRejection.is_accepted());
assert!(!PcResult::TransferSyntaxesNotSupported.is_accepted());
}
}