#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct DecodeLevel {
#[cfg_attr(feature = "serialization", serde(default))]
pub application: AppDecodeLevel,
#[cfg_attr(feature = "serialization", serde(default))]
pub transport: TransportDecodeLevel,
#[cfg_attr(feature = "serialization", serde(default))]
pub link: LinkDecodeLevel,
#[cfg_attr(feature = "serialization", serde(default))]
pub physical: PhysDecodeLevel,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum AppDecodeLevel {
Nothing,
Header,
ObjectHeaders,
ObjectValues,
}
impl Default for AppDecodeLevel {
fn default() -> Self {
Self::Nothing
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum TransportDecodeLevel {
Nothing,
Header,
Payload,
}
impl Default for TransportDecodeLevel {
fn default() -> Self {
Self::Nothing
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum LinkDecodeLevel {
Nothing,
Header,
Payload,
}
impl Default for LinkDecodeLevel {
fn default() -> Self {
Self::Nothing
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum PhysDecodeLevel {
Nothing,
Length,
Data,
}
impl Default for PhysDecodeLevel {
fn default() -> Self {
Self::Nothing
}
}
impl DecodeLevel {
pub fn nothing() -> Self {
Self::default()
}
pub fn new(
application: AppDecodeLevel,
transport: TransportDecodeLevel,
link: LinkDecodeLevel,
physical: PhysDecodeLevel,
) -> Self {
DecodeLevel {
application,
transport,
link,
physical,
}
}
}
impl Default for DecodeLevel {
fn default() -> Self {
Self {
application: AppDecodeLevel::Nothing,
transport: TransportDecodeLevel::Nothing,
link: LinkDecodeLevel::Nothing,
physical: PhysDecodeLevel::Nothing,
}
}
}
impl From<AppDecodeLevel> for DecodeLevel {
fn from(application: AppDecodeLevel) -> Self {
Self {
application,
transport: TransportDecodeLevel::Nothing,
link: LinkDecodeLevel::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::Header => true,
AppDecodeLevel::ObjectHeaders => true,
AppDecodeLevel::ObjectValues => true,
}
}
pub(crate) fn object_headers(&self) -> bool {
match self {
AppDecodeLevel::Nothing => false,
AppDecodeLevel::Header => false,
AppDecodeLevel::ObjectHeaders => true,
AppDecodeLevel::ObjectValues => true,
}
}
pub(crate) fn object_values(&self) -> bool {
match self {
AppDecodeLevel::Nothing => false,
AppDecodeLevel::Header => false,
AppDecodeLevel::ObjectHeaders => false,
AppDecodeLevel::ObjectValues => true,
}
}
}
impl TransportDecodeLevel {
pub(crate) fn enabled(&self) -> bool {
self.header_enabled()
}
pub(crate) fn header_enabled(&self) -> bool {
match self {
TransportDecodeLevel::Nothing => false,
TransportDecodeLevel::Header => true,
TransportDecodeLevel::Payload => true,
}
}
pub(crate) fn payload_enabled(&self) -> bool {
match self {
TransportDecodeLevel::Nothing => false,
TransportDecodeLevel::Header => false,
TransportDecodeLevel::Payload => true,
}
}
}
impl LinkDecodeLevel {
pub(crate) fn enabled(&self) -> bool {
self.header_enabled()
}
pub(crate) fn header_enabled(&self) -> bool {
match self {
LinkDecodeLevel::Nothing => false,
LinkDecodeLevel::Header => true,
LinkDecodeLevel::Payload => true,
}
}
pub(crate) fn payload_enabled(&self) -> bool {
match self {
LinkDecodeLevel::Nothing => false,
LinkDecodeLevel::Header => false,
LinkDecodeLevel::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,
}
}
}