1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// None (copy) codec
use crate::compression::{
    CodecImplementation, CompressionCodec, CompressionCodecType, DecompressResult,
};
use crate::error::Result;
use crate::header::CodecType;
use std::io::Write;

/// None/copy codec that does a byte-for-byte copy of the input buffer.
///
/// ## Buffer Restrictions
/// The input buffer must be exactly the same length as the output buffer.
pub struct NoneCodec;
impl CodecImplementation for NoneCodec {
    fn new(_: u32) -> Result<Self> {
        Ok(NoneCodec)
    }

    fn decompress(&mut self, input: &[u8], mut output: &mut [u8]) -> Result<DecompressResult> {
        Ok(DecompressResult::new(output.write(input)?, input.len()))
    }
}

impl CompressionCodecType for NoneCodec {
    fn codec_type(&self) -> CodecType {
        CodecType::None
    }
}

impl CompressionCodec for NoneCodec {}