mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-04 00:21:57 +00:00
dcb_tim::Header now checks for unknown flags.
This commit is contained in:
parent
c55ab5d80b
commit
8455998ae5
@ -26,6 +26,7 @@ impl Bytes for Header {
|
||||
type FromError = FromBytesError;
|
||||
type ToError = !;
|
||||
|
||||
#[bitmatch::bitmatch]
|
||||
fn from_bytes(bytes: &Self::ByteArray) -> Result<Self, Self::FromError> {
|
||||
let bytes = array_split!(bytes,
|
||||
tag : 0x1,
|
||||
@ -46,14 +47,18 @@ impl Bytes for Header {
|
||||
|
||||
// Else parse the flags
|
||||
let flags = LittleEndian::read_u32(bytes.flags);
|
||||
let bbp = match flags & 0b11 {
|
||||
let (bbp, clut_present) = #[bitmatch]
|
||||
match flags {
|
||||
"0000_0000_0000_0000_0000_0000_0000_c0bb" => (b, c != 0),
|
||||
_ => return Err(FromBytesError::UnknownFlag(flags)),
|
||||
};
|
||||
let bbp = match bbp {
|
||||
0b00 => BitsPerPixel::Index4Bit,
|
||||
0b01 => BitsPerPixel::Index8Bit,
|
||||
0b10 => BitsPerPixel::Color16Bit,
|
||||
0b11 => BitsPerPixel::Color24Bit,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let clut_present = flags & 0b1000 != 0;
|
||||
|
||||
Ok(Self { bbp, clut_present })
|
||||
}
|
||||
|
||||
@ -10,4 +10,8 @@ pub enum FromBytesError {
|
||||
/// Invalid version
|
||||
#[error("Invalid version {_0:#x}")]
|
||||
InvalidVersion(u8),
|
||||
|
||||
/// Unknown flag
|
||||
#[error("Unknown flag {_0:#010x}")]
|
||||
UnknownFlag(u32),
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user