use clap::Subcommand;
use gamut::bitstream::{leb128_len, write_leb128};
use crate::error::CliError;
#[derive(Subcommand)]
pub(crate) enum BitstreamCommand {
Leb128 {
value: u64,
},
}
pub(crate) fn run(cmd: &BitstreamCommand) -> Result<(), CliError> {
match cmd {
BitstreamCommand::Leb128 { value } => {
leb128(*value);
Ok(())
}
}
}
fn leb128(value: u64) {
let mut buf = Vec::new();
write_leb128(&mut buf, value);
let hex = buf
.iter()
.map(|byte| format!("{byte:02x}"))
.collect::<Vec<_>>()
.join(" ");
println!("value: {value}");
println!("leb128: {hex} ({} bytes)", buf.len());
println!("len(): {} (matches)", leb128_len(value));
}