jsonxf
jsonxf copied to clipboard
Format binary data function
Binary data formatter is alreay there, I'd like it to be exposed as a public function.
Sample function is below. There's no need to copy original data as well as to have input to be mutable
fn format_json_binary(data: &Vec<u8>) -> Result<Vec<u8>, io::Error> {
let mut formatter = jsonxf::Formatter::pretty_printer();
let mut output: Vec<u8> = vec![];
let mut input = BufReader::new(data.as_slice());
return match formatter.format_stream(&mut input, &mut output) {
Ok(_) => Ok(output),
Err(f) => Err(f),
};
}