Skip to content

Commit

Permalink
Merge pull request #52 from instaclustr/compressor-cli-interface
Browse files Browse the repository at this point in the history
Introduce compressor field in Args for single compression input
  • Loading branch information
cjrolo authored Oct 17, 2023
2 parents 75d2ddd + ca3368c commit aad6fde
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions brro-compressor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ use std::path::PathBuf;

/// Processes the given input based on the provided arguments.
fn process_args(arguments: &Args) -> Result<(), Box<dyn Error>> {

// Create a vector of boolean values from the argument flags.
// Then, count how many of these flags are set to true.
let count = vec![arguments.noop, arguments.constant, arguments.fft]
.iter()
.filter(|&&x| x)
.count();

if count > 1 {
return Err("Multiple compressors are set to true. Please specify only one.".into());
}

let metadata = fs::metadata(&arguments.input)?;

// If the input path points to a single file
Expand Down Expand Up @@ -99,10 +87,13 @@ fn compress_data(vec: &Vec<f64>, tag: &MetricTag, arguments: &Args) -> Vec<u8> {
let _optimizer_results_f: Vec<f64> = optimizer_results.iter().map(|&x| x as f64).collect();

let mut cs = CompressedStream::new();
let compressor = match arguments {
_ if arguments.constant => Compressor::Constant,
_ if arguments.fft => Compressor::FFT,
_ => Compressor::Noop,
let compressor = match arguments.compressor {
CompressorType::Noop => Compressor::Noop,
CompressorType::Constant => Compressor::Constant,
CompressorType::Fft => Compressor::FFT,
CompressorType::Polynomial => Compressor::Polynomial,
CompressorType::TopBottom => Compressor::TopBottom,
CompressorType::Wavelet => Compressor::Wavelet
};

cs.compress_chunk_with(vec, compressor);
Expand All @@ -129,23 +120,28 @@ fn write_compressed_data_to_path(compressed: &[u8], path: &Path) -> Result<(), s
struct Args {
/// input file
input: PathBuf,
/// Forces Noop compressor
#[arg(long, action)]
noop: bool,
/// Forces Constant compressor
#[arg(long, action)]
constant: bool,
/// Forces FFT compressor
//TODO: This needs to be a subcommand
#[arg(long, action)]
fft: bool,

#[arg(long, value_enum, default_value = "noop")]
compressor: CompressorType,

/// Uncompresses the input file/directory
#[arg(short, action)]
uncompress: bool,


}

#[derive(clap::ValueEnum, Default, Clone, Debug)]
enum CompressorType {
#[default]
Noop,
Fft,
Wavelet,
Constant,
Polynomial,
TopBottom,
}

fn main() {
env_logger::init();
let arguments = Args::parse();
Expand Down

0 comments on commit aad6fde

Please sign in to comment.