track total number of lines and add to json

master
rascul 2 years ago
parent 1fb973bc36
commit fda458d0f2

@ -45,10 +45,10 @@ fn chunk64(delta_chunk: &Vec<u8>, size_chunk: &Vec<u8>) -> Result<(i32, i32)> {
} }
/// parse the log of raw bytes and make some nice json for clients /// parse the log of raw bytes and make some nice json for clients
pub fn parse_log(raw: &Vec<u8>) -> Result<Value> { pub fn parse_log(raw: &Vec<u8>) -> Result<(i32, Value)> {
let mut raw = raw.to_owned(); let mut raw = raw.to_owned();
let mut chunks: Vec<Map<String, Value>> = Vec::new(); let mut chunks: Vec<Map<String, Value>> = Vec::new();
let mut lineno = 1; let mut lineno = 0;
while raw.len() > 0 { while raw.len() > 0 {
let chunk: Vec<u8> = raw.drain(0..8).collect(); let chunk: Vec<u8> = raw.drain(0..8).collect();
@ -84,15 +84,15 @@ pub fn parse_log(raw: &Vec<u8>) -> Result<Value> {
text = convert_escaped(&text)?; text = convert_escaped(&text)?;
for line in text.lines() { for line in text.lines() {
lineno += 1;
let mut map: Map<String, Value> = Map::new(); let mut map: Map<String, Value> = Map::new();
map.insert("lineno".into(), lineno.into()); map.insert("lineno".into(), lineno.into());
map.insert("delta".into(), delta.into()); map.insert("delta".into(), delta.into());
map.insert("text".into(), line.trim().into()); map.insert("text".into(), line.trim().into());
chunks.push(map); chunks.push(map);
delta = 0; delta = 0;
lineno += 1;
} }
} }
Ok(chunks.into()) Ok((lineno, chunks.into()))
} }

@ -97,7 +97,9 @@ impl WotLog {
match self.client { match self.client {
Client::Mudlet => { Client::Mudlet => {
map.insert("replay".into(), client::mudlet::parse_log(&self.raw)?.into()); let (lines, replay) = client::mudlet::parse_log(&self.raw)?;
map.insert("lines".into(), lines.into());
map.insert("replay".into(), replay.into());
} }
Client::TinTin => (), Client::TinTin => (),
Client::ZMud => (), Client::ZMud => (),

Loading…
Cancel
Save