add lzma as only default compression, add missing cfg annotations
This commit is contained in:
		
							parent
							
								
									e615f3f949
								
							
						
					
					
						commit
						79e963d045
					
				
					 5 changed files with 34 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -104,9 +104,13 @@ impl From<Command> for Packet {
 | 
			
		|||
                    CompressionCode::Uncompressed => {
 | 
			
		||||
                        CommandCode::BitmapLinearWinUncompressed
 | 
			
		||||
                    }
 | 
			
		||||
                    #[cfg(feature = "compression_zlib")]
 | 
			
		||||
                    CompressionCode::Zlib => CommandCode::BitmapLinearWinZlib,
 | 
			
		||||
                    #[cfg(feature = "compression_bzip2")]
 | 
			
		||||
                    CompressionCode::Bzip2 => CommandCode::BitmapLinearWinBzip2,
 | 
			
		||||
                    #[cfg(feature = "compression_lzma")]
 | 
			
		||||
                    CompressionCode::Lzma => CommandCode::BitmapLinearWinLzma,
 | 
			
		||||
                    #[cfg(feature = "compression_zstd")]
 | 
			
		||||
                    CompressionCode::Zstd => CommandCode::BitmapLinearWinZstd,
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -263,15 +267,19 @@ impl TryFrom<Packet> for Command {
 | 
			
		|||
                    CompressionCode::Uncompressed,
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
            #[cfg(feature = "compression_zlib")]
 | 
			
		||||
            CommandCode::BitmapLinearWinZlib => {
 | 
			
		||||
                Self::packet_into_bitmap_win(packet, CompressionCode::Zlib)
 | 
			
		||||
            }
 | 
			
		||||
            #[cfg(feature = "compression_bzip2")]
 | 
			
		||||
            CommandCode::BitmapLinearWinBzip2 => {
 | 
			
		||||
                Self::packet_into_bitmap_win(packet, CompressionCode::Bzip2)
 | 
			
		||||
            }
 | 
			
		||||
            #[cfg(feature = "compression_lzma")]
 | 
			
		||||
            CommandCode::BitmapLinearWinLzma => {
 | 
			
		||||
                Self::packet_into_bitmap_win(packet, CompressionCode::Lzma)
 | 
			
		||||
            }
 | 
			
		||||
            #[cfg(feature = "compression_zstd")]
 | 
			
		||||
            CommandCode::BitmapLinearWinZstd => {
 | 
			
		||||
                Self::packet_into_bitmap_win(packet, CompressionCode::Zstd)
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -541,8 +549,8 @@ mod tests {
 | 
			
		|||
    use crate::command::TryFromPacketError;
 | 
			
		||||
    use crate::command_code::CommandCode;
 | 
			
		||||
    use crate::{
 | 
			
		||||
        BitVec, ByteGrid, Command, CompressionCode, Header, Origin, Packet,
 | 
			
		||||
        PixelGrid,
 | 
			
		||||
        BitVec, ByteGrid, Command, CompressionCode, Grid, Header, Origin,
 | 
			
		||||
        Packet, PixelGrid,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    fn round_trip(original: Command) {
 | 
			
		||||
| 
						 | 
				
			
			@ -554,12 +562,16 @@ mod tests {
 | 
			
		|||
        assert_eq!(copy, original);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn all_compressions() -> [CompressionCode; 5] {
 | 
			
		||||
        [
 | 
			
		||||
    fn all_compressions<'t>() -> &'t [CompressionCode] {
 | 
			
		||||
        &[
 | 
			
		||||
            CompressionCode::Uncompressed,
 | 
			
		||||
            #[cfg(feature = "compression_lzma")]
 | 
			
		||||
            CompressionCode::Lzma,
 | 
			
		||||
            #[cfg(feature = "compression_bzip2")]
 | 
			
		||||
            CompressionCode::Bzip2,
 | 
			
		||||
            #[cfg(feature = "compression_zlib")]
 | 
			
		||||
            CompressionCode::Zlib,
 | 
			
		||||
            #[cfg(feature = "compression_zstd")]
 | 
			
		||||
            CompressionCode::Zstd,
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -602,7 +614,7 @@ mod tests {
 | 
			
		|||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn round_trip_bitmap_linear() {
 | 
			
		||||
        for compression in all_compressions() {
 | 
			
		||||
        for compression in all_compressions().to_owned() {
 | 
			
		||||
            round_trip(Command::BitmapLinear(23, BitVec::new(40), compression));
 | 
			
		||||
            round_trip(Command::BitmapLinearAnd(
 | 
			
		||||
                23,
 | 
			
		||||
| 
						 | 
				
			
			@ -704,7 +716,7 @@ mod tests {
 | 
			
		|||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn error_decompression_failed_win() {
 | 
			
		||||
        for compression in all_compressions() {
 | 
			
		||||
        for compression in all_compressions().to_owned() {
 | 
			
		||||
            let p: Packet = Command::BitmapLinearWin(
 | 
			
		||||
                Origin(16, 8),
 | 
			
		||||
                PixelGrid::new(8, 8),
 | 
			
		||||
| 
						 | 
				
			
			@ -730,7 +742,7 @@ mod tests {
 | 
			
		|||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn error_decompression_failed_and() {
 | 
			
		||||
        for compression in all_compressions() {
 | 
			
		||||
        for compression in all_compressions().to_owned() {
 | 
			
		||||
            let p: Packet =
 | 
			
		||||
                Command::BitmapLinearAnd(0, BitVec::new(8), compression).into();
 | 
			
		||||
            let Packet(header, mut payload) = p;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,9 +15,13 @@ pub(crate) enum CommandCode {
 | 
			
		|||
    BitmapLinearAnd = 0x0014,
 | 
			
		||||
    BitmapLinearOr = 0x0015,
 | 
			
		||||
    BitmapLinearXor = 0x0016,
 | 
			
		||||
    #[cfg(feature = "compression_zlib")]
 | 
			
		||||
    BitmapLinearWinZlib = 0x0017,
 | 
			
		||||
    #[cfg(feature = "compression_bzip2")]
 | 
			
		||||
    BitmapLinearWinBzip2 = 0x0018,
 | 
			
		||||
    #[cfg(feature = "compression_lzma")]
 | 
			
		||||
    BitmapLinearWinLzma = 0x0019,
 | 
			
		||||
    #[cfg(feature = "compression_zstd")]
 | 
			
		||||
    BitmapLinearWinZstd = 0x001A,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -51,15 +55,19 @@ impl TryFrom<u16> for CommandCode {
 | 
			
		|||
            value if value == BitmapLinearAnd as u16 => Ok(BitmapLinearAnd),
 | 
			
		||||
            value if value == BitmapLinearOr as u16 => Ok(BitmapLinearOr),
 | 
			
		||||
            value if value == BitmapLinearXor as u16 => Ok(BitmapLinearXor),
 | 
			
		||||
            #[cfg(feature = "compression_zstd")]
 | 
			
		||||
            value if value == BitmapLinearWinZstd as u16 => {
 | 
			
		||||
                Ok(BitmapLinearWinZstd)
 | 
			
		||||
            }
 | 
			
		||||
            #[cfg(feature = "compression_lzma")]
 | 
			
		||||
            value if value == BitmapLinearWinLzma as u16 => {
 | 
			
		||||
                Ok(BitmapLinearWinLzma)
 | 
			
		||||
            }
 | 
			
		||||
            #[cfg(feature = "compression_zlib")]
 | 
			
		||||
            value if value == BitmapLinearWinZlib as u16 => {
 | 
			
		||||
                Ok(BitmapLinearWinZlib)
 | 
			
		||||
            }
 | 
			
		||||
            #[cfg(feature = "compression_bzip2")]
 | 
			
		||||
            value if value == BitmapLinearWinBzip2 as u16 => {
 | 
			
		||||
                Ok(BitmapLinearWinBzip2)
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
#[cfg(feature = "compression")]
 | 
			
		||||
#[allow(unused)]
 | 
			
		||||
use std::io::{Read, Write};
 | 
			
		||||
 | 
			
		||||
#[cfg(feature = "compression_bzip2")]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue