Skip to content

Commit

Permalink
Merge pull request #16 from ddeityy/master
Browse files Browse the repository at this point in the history
Added header to json output
  • Loading branch information
icewind1991 authored Nov 11, 2023
2 parents f595843 + 4b2bf49 commit 5f6600c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ use std::env;
use std::fs;

use main_error::MainError;
use serde::{Deserialize, Serialize};
use tf_demo_parser::demo::header::Header;
use tf_demo_parser::demo::parser::analyser::MatchState;
use tf_demo_parser::demo::parser::player_summary_analyzer::PlayerSummaryAnalyzer;
pub use tf_demo_parser::{Demo, DemoParser, Parse, ParseError, ParserState, Stream};

#[cfg(feature = "jemallocator")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct JsonDemo {
header: Header,
#[serde(flatten)]
state: MatchState,
}

fn main() -> Result<(), MainError> {
#[cfg(feature = "better_panic")]
better_panic::install();
Expand All @@ -34,8 +45,9 @@ fn main() -> Result<(), MainError> {
} else {
DemoParser::new(demo.get_stream())
};
let (_, state) = parser.parse()?;
println!("{}", serde_json::to_string(&state)?);
let (header, state) = parser.parse()?;
let demo = JsonDemo { header, state };
println!("{}", serde_json::to_string(&demo)?);
} else {
let parser = DemoParser::new_with_analyser(demo.get_stream(), PlayerSummaryAnalyzer::new());
let (header, state) = parser.parse()?;
Expand Down

0 comments on commit 5f6600c

Please sign in to comment.