use broadcast_common::bits::{BitReader, BitWriter};
use crate::error::{BitResultExt, Error, Result};
pub(crate) fn read_reserved(
r: &mut BitReader<'_>,
width: u32,
expected: u64,
field: &'static str,
) -> Result<()> {
let found = r.read_bits(width).ctx(field)?;
if found != expected {
return Err(Error::InvalidReserved {
field,
expected,
found,
});
}
Ok(())
}
pub(crate) fn write_reserved(
w: &mut BitWriter<'_>,
width: u32,
expected: u64,
field: &'static str,
) -> Result<()> {
w.write_bits(expected, width).ctx(field)
}
pub(crate) fn expect_fully_consumed(r: &BitReader<'_>, what: &'static str) -> Result<()> {
let remaining = r.bits_remaining();
if remaining != 0 {
return Err(Error::InvalidValue {
field: what,
value: remaining as u64,
reason: "trailing unparsed bits remain in the element body",
});
}
Ok(())
}