variable_size_byte_writer
A Rust crate for writing variable-size bytes into io::Write traited targets.
Writes are internally buffered and so the usage of any additional buffering such as std::io::BufWriter is not recommended.
Usage:
Writing some unconventionally sized bytes into Vec<u8>:
use variable_size_byte_writer::*;
let mut target = Vec::new();
let mut writer = VariableSizeByteWriter::new(target);
let bytes = [(0x3F, 6),(0x1AFF, 13),(0x7, 3)];
bytes
.iter()
.for_each(|&(byte, bits)|
writer.write(byte, bits).unwrap()
);
Writing a series of 7bit bytes into a file, manually flushing the internal buffer and capturing the required bits to pad the last byte:
use std::fs::File;
use variable_size_byte_writer::*;
let mut file = File::create("path").unwrap();
let mut writer = VariableSizeByteWriter::new(file);
for variable in 0..0x8F {
writer.write(variable, 7).unwrap();
}
let mut padding = 0;
writer.flush(&mut padding).unwrap();
Writing some unconventionally sized bytes into Vec
use *;
let mut target = Vecnew;
let mut writer = new;
let bytes = ;
bytes
.iter
.for_each;
Writing a series of 7bit bytes into a file
use File;
use *;
let mut writer = new;
let mut file = create.unwrap;
for variable in 0..0x8F
let mut padding = 0;
writer
.flush_all_bytes
.unwrap;
License
variable_size_byte_writer is distributed under the terms of MIT licence.