Skip to content

Commit

Permalink
chore: adapted zippy to the codec trait
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Aug 9, 2024
1 parent 9146b28 commit 365fe15
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 227 deletions.
6 changes: 3 additions & 3 deletions benches/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn benchmark_encoding(c: &mut Criterion) {

group.bench_function("encode_rle", |b| {
b.iter(|| {
let encoded = encode_rle(black_box(&data));
let encoded = encode_rle(black_box(&data)).unwrap();
black_box(encoded);
})
});
Expand All @@ -39,7 +39,7 @@ fn benchmark_encoding(c: &mut Criterion) {
fn benchmark_decoding(c: &mut Criterion) {
let data = generate_data(10_000_000_usize);
let encoded_huffman = encode_huffman(black_box(&data)).unwrap();
let encoded_rle = encode_rle(black_box(&data));
let encoded_rle = encode_rle(black_box(&data)).unwrap();
let encoded_zippy = encode_zippy(black_box(&data), None, None).unwrap();

let mut group = c.benchmark_group("decoding");
Expand All @@ -54,7 +54,7 @@ fn benchmark_decoding(c: &mut Criterion) {

group.bench_function("decode_rle", |b| {
b.iter(|| {
let decoded = decode_rle(black_box(&encoded_rle));
let decoded = decode_rle(black_box(&encoded_rle)).unwrap();
black_box(decoded);
})
});
Expand Down
6 changes: 4 additions & 2 deletions crates/encoding/src/cipher.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use boytacean_common::error::Error;

pub trait Cipher {
type EncryptOptions;
type DecryptOptions;

fn encrypt(data: &mut [u8], key: &[u8], options: &Self::EncryptOptions);
fn decrypt(data: &mut [u8], key: &[u8], options: &Self::DecryptOptions);
fn encrypt(data: &mut [u8], key: &[u8], options: &Self::EncryptOptions) -> Result<(), Error>;
fn decrypt(data: &mut [u8], key: &[u8], options: &Self::DecryptOptions) -> Result<(), Error>;
}
6 changes: 4 additions & 2 deletions crates/encoding/src/codec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use boytacean_common::error::Error;

pub trait Codec {
type EncodeOptions;
type DecodeOptions;

fn encode(data: &[u8], options: &Self::EncodeOptions) -> Vec<u8>;
fn decode(data: &[u8], options: &Self::DecodeOptions) -> Vec<u8>;
fn encode(data: &[u8], options: &Self::EncodeOptions) -> Result<Vec<u8>, Error>;
fn decode(data: &[u8], options: &Self::DecodeOptions) -> Result<Vec<u8>, Error>;
}
Loading

0 comments on commit 365fe15

Please sign in to comment.