#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct DecodeLevel {
pub app: AppDecodeLevel,
pub frame: FrameDecodeLevel,
pub physical: PhysDecodeLevel,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AppDecodeLevel {
Nothing,
FunctionCode,
DataHeaders,
DataValues,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum FrameDecodeLevel {
Nothing,
Header,
Payload,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PhysDecodeLevel {
Nothing,
Length,
Data,
}
impl DecodeLevel {
pub fn nothing() -> Self {
Self::default()
}
pub fn new(pdu: AppDecodeLevel, adu: FrameDecodeLevel, physical: PhysDecodeLevel) -> Self {
DecodeLevel {
app: pdu,
frame: adu,
physical,
}
}
pub fn application(mut self, level: AppDecodeLevel) -> Self {
self.app = level;
self
}
pub fn frame(mut self, level: FrameDecodeLevel) -> Self {
self.frame = level;
self
}
pub fn physical(mut self, level: PhysDecodeLevel) -> Self {
self.physical = level;
self
}
}
impl Default for DecodeLevel {
fn default() -> Self {
Self {
app: AppDecodeLevel::Nothing,
frame: FrameDecodeLevel::Nothing,
physical: PhysDecodeLevel::Nothing,
}
}
}
impl From<AppDecodeLevel> for DecodeLevel {
fn from(pdu: AppDecodeLevel) -> Self {
Self {
app: pdu,
frame: FrameDecodeLevel::Nothing,
physical: PhysDecodeLevel::Nothing,
}
}
}
impl AppDecodeLevel {
pub(crate) fn enabled(&self) -> bool {
self.header()
}
pub(crate) fn header(&self) -> bool {
match self {
AppDecodeLevel::Nothing => false,
AppDecodeLevel::FunctionCode => true,
AppDecodeLevel::DataHeaders => true,
AppDecodeLevel::DataValues => true,
}
}
pub(crate) fn data_headers(&self) -> bool {
match self {
AppDecodeLevel::Nothing => false,
AppDecodeLevel::FunctionCode => false,
AppDecodeLevel::DataHeaders => true,
AppDecodeLevel::DataValues => true,
}
}
pub(crate) fn data_values(&self) -> bool {
match self {
AppDecodeLevel::Nothing => false,
AppDecodeLevel::FunctionCode => false,
AppDecodeLevel::DataHeaders => false,
AppDecodeLevel::DataValues => true,
}
}
}
impl FrameDecodeLevel {
pub(crate) fn enabled(&self) -> bool {
self.header_enabled()
}
pub(crate) fn header_enabled(&self) -> bool {
match self {
FrameDecodeLevel::Nothing => false,
FrameDecodeLevel::Header => true,
FrameDecodeLevel::Payload => true,
}
}
pub(crate) fn payload_enabled(&self) -> bool {
match self {
FrameDecodeLevel::Nothing => false,
FrameDecodeLevel::Header => false,
FrameDecodeLevel::Payload => true,
}
}
}
impl PhysDecodeLevel {
pub(crate) fn enabled(&self) -> bool {
self.length_enabled()
}
pub(crate) fn length_enabled(&self) -> bool {
match self {
PhysDecodeLevel::Nothing => false,
PhysDecodeLevel::Length => true,
PhysDecodeLevel::Data => true,
}
}
pub(crate) fn data_enabled(&self) -> bool {
match self {
PhysDecodeLevel::Nothing => false,
PhysDecodeLevel::Length => false,
PhysDecodeLevel::Data => true,
}
}
}