-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from instaclustr/CompressStream
Compress stream
- Loading branch information
Showing
8 changed files
with
159 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
use std::mem::size_of_val; | ||
use bincode::{Decode, Encode}; | ||
use crate::compressor::Compressor; | ||
|
||
/// This is the structure of a compressor frame | ||
#[derive(Encode, Decode, Debug, Clone)] | ||
pub struct CompressorFrame{ | ||
/// The frame size in Bytes, | ||
frame_size: i64, | ||
/// The frame size in bytes, | ||
frame_size: usize, | ||
/// The number of samples in this frame, | ||
samples: u32, | ||
/// The compressor used in the current frame | ||
compressor: Compressor, | ||
/// Output from the compressor | ||
data: Vec<u8>, | ||
} | ||
|
||
impl CompressorFrame { | ||
/// For testing | ||
pub fn new() -> Self { | ||
/// Creates a compressor frame, if a compressor is provided, it forces that compressor, otherwise is selected | ||
/// by the optimizer | ||
/// compressor: None to allow BRRO to chose, or force one | ||
pub fn new(provided_compressor: Option<Compressor>) -> Self { | ||
CompressorFrame { | ||
frame_size: 0, | ||
compressor: Compressor::Noop, | ||
samples: 0, | ||
compressor: provided_compressor.unwrap_or_default(), | ||
data: Vec::new() } | ||
} | ||
|
||
/// Calculates the size of the Frame and "closes it" | ||
// TODO this is probably wrong, so we have to use the write stream to dump the bytes writen | ||
pub fn close(&mut self) { | ||
let size = size_of_val(&self.samples) | ||
+ size_of_val(&self.compressor) | ||
+ size_of_val(&self.data) | ||
+ size_of_val(&self.frame_size); | ||
self.frame_size = size; | ||
} | ||
|
||
/// Compress a data and stores the result in the frame | ||
pub fn compress(&mut self, data: &[f64]) { | ||
// TODO: Optimize here | ||
// self.compressor = optimizer_selection | ||
self.data = self.compressor.compress(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters