Skip to content

Commit 8713308

Browse files
baumanjkornelski
authored andcommitted
Use BitReader for ipma
1 parent 48aca82 commit 8713308

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

mp4parse/src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,7 @@ impl TryClone for ItemProperty {
16001600

16011601
struct Association {
16021602
item_id: u32,
1603+
essential: bool,
16031604
property_index: u16,
16041605
}
16051606

@@ -1622,16 +1623,14 @@ fn read_ipma<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<Association>> {
16221623
};
16231624
let association_count = src.read_u8()?;
16241625
for _ in 0..association_count {
1625-
let first_byte = src.read_u8()?;
1626-
let essential_flag = first_byte & 1 << 7;
1627-
let value = first_byte - essential_flag;
1628-
let property_index = if flags & 1 != 0 {
1629-
((value as u16) << 8) | src.read_u8()? as u16
1630-
} else {
1631-
value as u16
1632-
};
1626+
let num_association_bytes = if flags & 1 == 1 { 2 } else { 1 };
1627+
let association = src.take(num_association_bytes).read_into_try_vec()?;
1628+
let mut association = BitReader::new(association.as_slice());
1629+
let essential = association.read_bool()?;
1630+
let property_index = association.read_u16(association.remaining().try_into()?)?;
16331631
associations.push(Association {
16341632
item_id,
1633+
essential,
16351634
property_index,
16361635
})?;
16371636
}

0 commit comments

Comments
 (0)