pub struct Parser<V: Version> { /* private fields */ }Expand description
A configurable replay parser. Construct a new parser with default paramaters or use the
ParserBuilder for fine grained control.
§Example
use faf_replay_parser::{Parser, SCFA};
use std::io::Read;
let mut data: &[u8] = b"Some replay data";
let parser = Parser::<SCFA>::new();
let result = parser.parse(&mut data)
.expect_err("Sadly not a valid replay");Implementations§
Source§impl<V: Version> Parser<V>
impl<V: Version> Parser<V>
Sourcepub fn new() -> Parser<V>
pub fn new() -> Parser<V>
Constructs a new parser with default settings. This will only parse the most essential commands needed to determine the number of participants, the length of the replay, and whether or not the replay desynced.
Sourcepub fn with_options(options: ParserOptions<V>) -> Parser<V>
pub fn with_options(options: ParserOptions<V>) -> Parser<V>
Constructs a new Parser with given ParserOptions
Sourcepub fn new_stream(&self) -> StreamParser<V>
pub fn new_stream(&self) -> StreamParser<V>
Creates a new StreamParser with the same options as self.
Sourcepub fn parse(
&self,
reader: &mut (impl Read + BufRead),
) -> ReplayResult<Replay<V>>
pub fn parse( &self, reader: &mut (impl Read + BufRead), ) -> ReplayResult<Replay<V>>
Fully parses a stream of bytes into a Replay struct.
Sourcepub fn parse_with_callback(
&self,
reader: &mut (impl Read + BufRead),
callback: impl Fn(&mut SimData, &V::Command) -> ReplayResult<()>,
) -> ReplayResult<Replay<V>>
pub fn parse_with_callback( &self, reader: &mut (impl Read + BufRead), callback: impl Fn(&mut SimData, &V::Command) -> ReplayResult<()>, ) -> ReplayResult<Replay<V>>
Like parse but using a custom command processing function. This can be useful for
aggregating replay results on the fly without saving the whole command stream to a Vec
first.
§Example
use faf_replay_parser::{ParserBuilder, SCFA};
use faf_replay_parser::scfa::ReplayCommand;
let mut data: &[u8] = b"Some replay data";
let parser = ParserBuilder::<SCFA>::new()
.save_commands(false)
.build();
let replay = parser.parse_with_callback(&mut data, |sim, command| {
if let ReplayCommand::Advance { ticks } = command {
println!("Advancing {}!", ticks);
}
Ok(())
});Sourcepub fn parse_header(
&self,
reader: &mut (impl Read + BufRead),
) -> ReplayResult<ReplayHeader>
pub fn parse_header( &self, reader: &mut (impl Read + BufRead), ) -> ReplayResult<ReplayHeader>
Parses a stream of bytes into a ReplayHeader struct.
Sourcepub fn parse_body(&self, reader: &mut impl Read) -> ReplayResult<ReplayBody<V>>
pub fn parse_body(&self, reader: &mut impl Read) -> ReplayResult<ReplayBody<V>>
Parses a stream of bytes into a ReplayBody struct. Usually this means the header has
already been parsed so that reader starts at the correct offset for the replay body.
Sourcepub fn parse_body_with_callback(
&self,
reader: &mut impl Read,
callback: impl Fn(&mut SimData, &V::Command) -> ReplayResult<()>,
) -> ReplayResult<ReplayBody<V>>
pub fn parse_body_with_callback( &self, reader: &mut impl Read, callback: impl Fn(&mut SimData, &V::Command) -> ReplayResult<()>, ) -> ReplayResult<ReplayBody<V>>
Like parse_body but using a custom command processing function. See
parse_with_callback for an example callback function.