/// Read the extended header of an ID3v2.4 tag.
Read the extended header of an ID3v2.4 tag.
Read the extended header of an ID3v2 . 4 tag .
fn read_id3v2p4_extended_header<B: ByteStream>(reader: &mut B) -> Result<ExtendedHeader> {
    let _size = read_syncsafe_leq32(reader, 28)?;
    if reader.read_u8()? != 1 {
        return decode_error("extended flags should have a length of 1");
    }
    let flags = reader.read_u8()?;
    let mut header = ExtendedHeader {
        padding_size: None,
        crc32: None,
        is_update: Some(false),
        restrictions: None,
    };
    // Tag is an update flag.
    if flags & 0x40 != 0x0 {
        let len = reader.read_u8()?;
        if len != 1 {
            return decode_error("is update extended flag has invalid size");
        }
        header.is_update = Some(true);
    }
    // CRC32 flag.
    if flags & 0x20 != 0x0 {
        let len = reader.read_u8()?;
        if len != 5 {
            return decode_error("CRC32 extended flag has invalid size");
        }
        header.crc32 = Some(read_syncsafe_leq32(reader, 32)?);
    }
    // Restrictions flag.
    if flags & 0x10 != 0x0 {
        let len = reader.read_u8()?;
        if len != 1 {
            return decode_error("restrictions extended flag has invalid size");
        }
        let restrictions = reader.read_u8()?;
        let tag_size = match (restrictions & 0xc0) >> 6 {
            0 => TagSizeRestriction::Max128Frames1024KiB,
            1 => TagSizeRestriction::Max64Frames128KiB,
            2 => TagSizeRestriction::Max32Frames40KiB,
            3 => TagSizeRestriction::Max32Frames4KiB,
            _ => unreachable!(),
        };
        let text_encoding = match (restrictions & 0x40) >> 5 {
            0 => TextEncodingRestriction::None,
            1 => TextEncodingRestriction::Utf8OrIso88591,
            _ => unreachable!(),
        };
        let text_field_size = match (restrictions & 0x18) >> 3 {
            0 => TextFieldSize::None,
            1 => TextFieldSize::Max1024Characters,
            2 => TextFieldSize::Max128Characters,
            3 => TextFieldSize::Max30Characters,
            _ => unreachable!(),
        };
        let image_encoding = match (restrictions & 0x04) >> 2 {
            0 => ImageEncodingRestriction::None,
            1 => ImageEncodingRestriction::PngOrJpegOnly,
            _ => unreachable!(),
        };
        let image_size = match restrictions & 0x03 {
            0 => ImageSizeRestriction::None,
            1 => ImageSizeRestriction::LessThan256x256,
            2 => ImageSizeRestriction::LessThan64x64,
            3 => ImageSizeRestriction::Exactly64x64,
            _ => unreachable!(),
        };
        header.restrictions = Some(Restrictions {
            tag_size,
            text_encoding,
            text_field_size,
            image_encoding,
            image_size,
        })
    }
    Ok(header)
}
fn read_id3v2p4_extended_header < B : ByteStream > ( reader : & mut B ) -> Result < ExtendedHeader > { let _size = read_syncsafe_leq32 ( reader , 28 ) ? ; if reader . read_u8 ( ) ? != 1 { return decode_error ( " " ) ; } let flags = reader . read_u8 ( ) ? ; let mut header = ExtendedHeader { padding_size : None , crc32 : None , is_update : Some ( false ) , restrictions : None , } ; // Tag is an update flag. if flags & 0x40 != 0x0 { let len = reader . read_u8 ( ) ? ; if len != 1 { return decode_error ( " " ) ; } header . is_update = Some ( true ) ; } // CRC32 flag. if flags & 0x20 != 0x0 { let len = reader . read_u8 ( ) ? ; if len != 5 { return decode_error ( " " ) ; } header . crc32 = Some ( read_syncsafe_leq32 ( reader , 32 ) ? ) ; } // Restrictions flag. if flags & 0x10 != 0x0 { let len = reader . read_u8 ( ) ? ; if len != 1 { return decode_error ( " " ) ; } let restrictions = reader . read_u8 ( ) ? ; let tag_size = match ( restrictions & 0xc0 ) >> 6 { 0 => TagSizeRestriction :: Max128Frames1024KiB , 1 => TagSizeRestriction :: Max64Frames128KiB , 2 => TagSizeRestriction :: Max32Frames40KiB , 3 => TagSizeRestriction :: Max32Frames4KiB , _ => unreachable ! ( ) , } ; let text_encoding = match ( restrictions & 0x40 ) >> 5 { 0 => TextEncodingRestriction :: None , 1 => TextEncodingRestriction :: Utf8OrIso88591 , _ => unreachable ! ( ) , } ; let text_field_size = match ( restrictions & 0x18 ) >> 3 { 0 => TextFieldSize :: None , 1 => TextFieldSize :: Max1024Characters , 2 => TextFieldSize :: Max128Characters , 3 => TextFieldSize :: Max30Characters , _ => unreachable ! ( ) , } ; let image_encoding = match ( restrictions & 0x04 ) >> 2 { 0 => ImageEncodingRestriction :: None , 1 => ImageEncodingRestriction :: PngOrJpegOnly , _ => unreachable ! ( ) , } ; let image_size = match restrictions & 0x03 { 0 => ImageSizeRestriction :: None , 1 => ImageSizeRestriction :: LessThan256x256 , 2 => ImageSizeRestriction :: LessThan64x64 , 3 => ImageSizeRestriction :: Exactly64x64 , _ => unreachable ! ( ) , } ; header . restrictions = Some ( Restrictions { tag_size , text_encoding , text_field_size , image_encoding , image_size , } ) } Ok ( header ) }
Read the extended header of an ID3v2.4 tag.
Read the extended header of an ID3v2 . 4 tag .
reader
&mut B