jsonxf icon indicating copy to clipboard operation
jsonxf copied to clipboard

Format binary data function

Open eirnym opened this issue 1 year ago • 0 comments

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),
    };
}

eirnym avatar Feb 04 '25 14:02 eirnym