Skip to content

Commit

Permalink
Merge branch 'chore/codec-traits' into 'master'
Browse files Browse the repository at this point in the history
Support for codec traits

See merge request joamag/boytacean!58
  • Loading branch information
joamag committed Aug 9, 2024
2 parents 01610ae + 02bc9a2 commit a938fe4
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 244 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
9 changes: 9 additions & 0 deletions crates/encoding/src/cipher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use boytacean_common::error::Error;

pub trait Cipher {
type EncryptOptions;
type 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>;
}
9 changes: 9 additions & 0 deletions crates/encoding/src/codec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use boytacean_common::error::Error;

pub trait Codec {
type EncodeOptions;
type DecodeOptions;

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 a938fe4

Please sign in to comment.