#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub enum HdrWcgIdc {
Sdr,
WcgOnly,
HdrAndWcg,
NoIndication,
}
impl HdrWcgIdc {
#[must_use]
pub fn from_u8(v: u8) -> Self {
match v & 0x03 {
0 => Self::Sdr,
1 => Self::WcgOnly,
2 => Self::HdrAndWcg,
_ => Self::NoIndication,
}
}
#[must_use]
pub const fn to_u8(self) -> u8 {
match self {
Self::Sdr => 0,
Self::WcgOnly => 1,
Self::HdrAndWcg => 2,
Self::NoIndication => 3,
}
}
#[must_use]
pub fn name(self) -> &'static str {
match self {
Self::Sdr => "SDR",
Self::WcgOnly => "WCG only",
Self::HdrAndWcg => "HDR and WCG",
Self::NoIndication => "no indication",
}
}
}
broadcast_common::impl_spec_display!(HdrWcgIdc);
#[cfg(test)]
mod tests {
use super::*;
use alloc::string::ToString;
#[test]
fn labels_match_table_2_114() {
assert_eq!(HdrWcgIdc::Sdr.name(), "SDR");
assert_eq!(HdrWcgIdc::WcgOnly.name(), "WCG only");
assert_eq!(HdrWcgIdc::HdrAndWcg.name(), "HDR and WCG");
assert_eq!(HdrWcgIdc::NoIndication.name(), "no indication");
assert_eq!(HdrWcgIdc::HdrAndWcg.to_string(), "HDR and WCG");
}
}