Skip to content

Commit 4a7cc48

Browse files
authored
Split BasicDataFormatDescriptorHeader off from BasicDataFormatDescriptor (#11)
1 parent 4e1dd3a commit 4a7cc48

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Per Keep a Changelog there are 6 main categories of changes:
3333
- `LevelIndex::uncompressed_byte_length`
3434
- `Level::data`
3535
- `Level::uncompressed_byte_length`
36+
- Moved header data in `BasicDataFormatDescriptor` into `BasicDataFormatDescriptorHeader`.
3637

3738
## v0.3.0
3839

src/lib.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ pub struct DataFormatDescriptor<'data> {
462462
pub data: &'data [u8],
463463
}
464464

465-
pub struct BasicDataFormatDescriptor<'data> {
465+
#[derive(Debug, Copy, Clone)]
466+
pub struct BasicDataFormatDescriptorHeader {
466467
/// None means Unspecified
467468
pub color_model: Option<ColorModel>, //: 8;
468469
/// None means Unspecified
@@ -472,11 +473,12 @@ pub struct BasicDataFormatDescriptor<'data> {
472473
pub flags: DataFormatFlags, //: 8;
473474
pub texel_block_dimensions: [u32; 4], //: 8 x 4;
474475
pub bytes_planes: [u32; 8], //: 8 x 8;
475-
sample_data: &'data [u8],
476476
}
477477

478-
impl<'data> BasicDataFormatDescriptor<'data> {
479-
pub fn parse(bytes: &'data [u8]) -> Result<Self, ParseError> {
478+
impl BasicDataFormatDescriptorHeader {
479+
pub const LENGTH: usize = 16;
480+
481+
pub fn parse(bytes: &[u8]) -> Result<Self, ParseError> {
480482
let mut offset = 0;
481483

482484
let v = bytes_to_u32(bytes, &mut offset)?;
@@ -513,12 +515,29 @@ impl<'data> BasicDataFormatDescriptor<'data> {
513515
flags: DataFormatFlags::from_bits_truncate(flags),
514516
texel_block_dimensions,
515517
bytes_planes,
516-
sample_data: &bytes[offset..],
518+
})
519+
}
520+
}
521+
522+
pub struct BasicDataFormatDescriptor<'data> {
523+
pub header: BasicDataFormatDescriptorHeader,
524+
sample_information: &'data [u8],
525+
}
526+
527+
impl<'data> BasicDataFormatDescriptor<'data> {
528+
pub fn parse(bytes: &'data [u8]) -> Result<Self, ParseError> {
529+
let header = BasicDataFormatDescriptorHeader::parse(bytes)?;
530+
531+
Ok(Self {
532+
header,
533+
sample_information: &bytes[BasicDataFormatDescriptorHeader::LENGTH..],
517534
})
518535
}
519536

520537
pub fn sample_information(&self) -> impl Iterator<Item = SampleInformation> + 'data {
521-
SampleInformationIterator { data: self.sample_data }
538+
SampleInformationIterator {
539+
data: self.sample_information,
540+
}
522541
}
523542
}
524543

0 commit comments

Comments
 (0)