add a few comments

master
rascul 3 years ago
parent 8b23140f8e
commit 598e523733

@ -5,6 +5,7 @@ use serde_json::{Map, Value};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
/// try to parse a 32bit int from the delta chunk, then another 32bit in from the size chunk
fn chunk32(chunk: &Vec<u8>) -> Result<(i32, i32)> {
let (delta_chunk, size_chunk) = {
let (mut delta_chunk, mut size_chunk): ([u8; 4], [u8; 4]) = ([0; 4], [0; 4]);
@ -25,6 +26,7 @@ fn chunk32(chunk: &Vec<u8>) -> Result<(i32, i32)> {
Ok((delta, size))
}
/// try to parse a 64bit int from the delta chunk, then a 32bit int from the size chunk
fn chunk64(delta_chunk: &Vec<u8>, size_chunk: &Vec<u8>) -> Result<(i32, i32)> {
let delta = i64::from_be_bytes(delta_chunk.as_slice().try_into()?);
let size = i32::from_be_bytes(size_chunk.as_slice().try_into()?);
@ -42,6 +44,7 @@ fn chunk64(delta_chunk: &Vec<u8>, size_chunk: &Vec<u8>) -> Result<(i32, i32)> {
Ok((delta, size))
}
/// parse the log of raw bytes and make some nice json for clients
pub fn parse_log(raw: &Vec<u8>) -> Result<Value> {
let mut raw = raw.to_owned();
let mut chunks: Vec<Map<String, Value>> = Vec::new();

Loading…
Cancel
Save