pancake_db_core/compression/
zstd_codec.rs

1use crate::primitives::Primitive;
2use crate::errors::CoreResult;
3
4use super::Codec;
5use std::marker::PhantomData;
6
7const ZSTD_LEVEL: i32 = 5;
8
9#[derive(Clone, Debug, Default)]
10pub struct ZstdCodec<P: Primitive> {
11  _phantom: PhantomData<P>,
12}
13
14impl<P: Primitive<A=u8>> Codec for ZstdCodec<P> {
15  type P = P;
16
17  fn compress_atoms(&self, atoms: &[u8]) -> CoreResult<Vec<u8>> {
18    Ok(zstd::encode_all(atoms, ZSTD_LEVEL)?)
19  }
20
21  fn decompress_atoms(&self, bytes: &[u8]) -> CoreResult<Vec<u8>> {
22    Ok(zstd::decode_all(bytes)?)
23  }
24}