tsfile_writer/writer/
compression.rs

1//! Contains the compression algorithms
2use crate::writer::CompressionType::{SNAPPY, UNCOMPRESSED};
3
4#[derive(PartialEq, Copy, Clone, Debug)]
5pub enum CompressionType {
6    UNCOMPRESSED,
7    SNAPPY,
8}
9
10impl TryFrom<u8> for CompressionType {
11    type Error = ();
12
13    fn try_from(value: u8) -> Result<Self, Self::Error> {
14        match value {
15            0x00 => Ok(UNCOMPRESSED),
16            0x01 => Ok(SNAPPY),
17            _ => Err(()),
18        }
19    }
20}
21
22impl CompressionType {
23    pub fn serialize(&self) -> u8 {
24        match self {
25            CompressionType::UNCOMPRESSED => 0x00,
26            CompressionType::SNAPPY => 0x01,
27        }
28    }
29}