pub fn decompress(&self, stream: &mut Vec<u8>) -> Result<(), Error> {
        match *self {
            Codec::Null => (),
            Codec::Deflate => {
                let mut decoded = Vec::new();
                {
                    // either the compiler or I is dumb
                    let mut decoder = Decoder::new(&stream[..]);
                    decoder.read_to_end(&mut decoded)?;
                }
                *stream = decoded;
            }
            #[cfg(feature = "snappy")]
            Codec::Snappy => {
                use byteorder::ByteOrder;

                let decompressed_size = snap::decompress_len(&stream[..stream.len() - 4])?;
                let mut decoded = vec![0; decompressed_size];
                snap::Decoder::new().decompress(&stream[..stream.len() - 4], &mut decoded[..])?;

                let expected_crc = byteorder::BigEndian::read_u32(&stream[stream.len() - 4..]);
                let actual_crc = crc::crc32::checksum_ieee(&decoded);

                if expected_crc != actual_crc {
                    return Err(DecodeError::new(format!(
                        "bad Snappy CRC32; expected {:x} but got {:x}",
                        expected_crc, actual_crc
                    ))
                    .into());
                }
                *stream = decoded;
            }
        };

        Ok(())
    }
/// Decompress a stream of bytes in-place.
Decompress a stream of bytes in-place.
Decompress a stream of bytes in - place .
pub fn decompress(&self, stream: &mut Vec<u8>) -> Result<(), Error> {
        match *self {
            Codec::Null => (),
            Codec::Deflate => {
                let mut decoded = Vec::new();
                {
                    // either the compiler or I is dumb
                    let mut decoder = Decoder::new(&stream[..]);
                    decoder.read_to_end(&mut decoded)?;
                }
                *stream = decoded;
            }
            #[cfg(feature = "snappy")]
            Codec::Snappy => {
                use byteorder::ByteOrder;
                let decompressed_size = snap::decompress_len(&stream[..stream.len() - 4])?;
                let mut decoded = vec![0; decompressed_size];
                snap::Decoder::new().decompress(&stream[..stream.len() - 4], &mut decoded[..])?;
                let expected_crc = byteorder::BigEndian::read_u32(&stream[stream.len() - 4..]);
                let actual_crc = crc::crc32::checksum_ieee(&decoded);
                if expected_crc != actual_crc {
                    return Err(DecodeError::new(format!(
                        "bad Snappy CRC32; expected {:x} but got {:x}",
                        expected_crc, actual_crc
                    ))
                    .into());
                }
                *stream = decoded;
            }
        };
        Ok(())
    }
pub fn decompress ( & self , stream : & mut Vec < u8 > ) -> Result < ( ) , Error > { match * self { Codec :: Null => ( ) , Codec :: Deflate => { let mut decoded = Vec :: new ( ) ; { // either the compiler or I is dumb let mut decoder = Decoder :: new ( & stream [ .. ] ) ; decoder . read_to_end ( & mut decoded ) ? ; } * stream = decoded ; } # [ cfg ( feature " " ) ] Codec :: Snappy => { use byteorder :: ByteOrder ; let decompressed_size = snap :: decompress_len ( & stream [ .. stream . len ( ) - 4 ] ) ? ; let mut decoded = vec ! [ 0 decompressed_size ] ; snap :: Decoder :: new ( ) . decompress ( & stream [ .. stream . len ( ) - 4 ] , & mut decoded [ .. ] ) ? ; let expected_crc = byteorder :: BigEndian :: read_u32 ( & stream [ stream . len ( ) - 4 .. ] ) ; let actual_crc = crc :: crc32 :: checksum_ieee ( & decoded ) ; if expected_crc != actual_crc { return Err ( DecodeError :: new ( format ! ( " " expected_crc actual_crc ) ) . into ( ) ) ; } * stream = decoded ; } } ; Ok ( ( ) ) }
Decompress a stream of bytes in-place.
Decompress a stream of bytes in - place .
&self
stream
&mut Vec<u8>