pub struct Parser { /* private fields */ }Expand description
The main parser. Owns the demo file data (memory-mapped or in-memory).
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn from_file(path: &Path) -> Result<Self>
pub fn from_file(path: &Path) -> Result<Self>
Open a demo file and memory-map it for zero-copy parsing.
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Self
pub fn from_bytes(bytes: Vec<u8>) -> Self
Create a parser from an in-memory byte buffer.
This is useful for testing, WASM targets (where mmap is unavailable), or when the demo data has already been loaded into memory.
Sourcepub fn verify(&self) -> Result<()>
pub fn verify(&self) -> Result<()>
Verify magic bytes. Verify that the file has valid demo magic bytes.
Sourcepub fn messages(&self) -> Result<Vec<MessageInfo>>
pub fn messages(&self) -> Result<Vec<MessageInfo>>
Iterate all commands and return metadata about each. Continues past DEM_Stop to capture DEM_FileInfo.
Sourcepub fn file_header(&self) -> Result<CDemoFileHeader>
pub fn file_header(&self) -> Result<CDemoFileHeader>
Find and decode the CDemoFileHeader message.
Sourcepub fn file_info(&self) -> Result<CDemoFileInfo>
pub fn file_info(&self) -> Result<CDemoFileInfo>
Decode CDemoFileInfo using the offset stored in the file header.
Sourcepub fn events(&self, max_tick: Option<i32>) -> Result<Vec<GameEvent>>
pub fn events(&self, max_tick: Option<i32>) -> Result<Vec<GameEvent>>
Parse game events from the demo.
Extracts Source 1 legacy game events and Citadel user messages from
DEM_Packet, DEM_SignonPacket, and DEM_FullPacket commands.
If max_tick is set, stops parsing once the tick exceeds the limit.
Sourcepub fn parse_send_tables(&self) -> Result<SerializerContainer>
pub fn parse_send_tables(&self) -> Result<SerializerContainer>
Parse send tables from DEM_SendTables command.
Sourcepub fn parse_class_info(&self) -> Result<ClassInfo>
pub fn parse_class_info(&self) -> Result<ClassInfo>
Parse class info from DEM_ClassInfo command.
Sourcepub fn parse_init(&self) -> Result<Context>
pub fn parse_init(&self) -> Result<Context>
Parse all initialization data up to DEM_SyncTick and return a Context.
Sourcepub fn parse_to_tick(&self, target_tick: i32) -> Result<Context>
pub fn parse_to_tick(&self, target_tick: i32) -> Result<Context>
Parse the demo to a specific tick, returning the full game state.
Uses an optimisation where it skips forward to the last
DEM_FullPacket snapshot before target_tick, applies that snapshot,
then replays individual packets until target_tick is reached.
Sourcepub fn run_to_end<F>(&self, on_tick: F) -> Result<()>
pub fn run_to_end<F>(&self, on_tick: F) -> Result<()>
Parse the entire demo, calling a callback at each tick with the current context. This is more efficient than calling parse_to_tick repeatedly.
Sourcepub fn run_to_end_filtered<F>(
&self,
class_filter: &HashSet<&str>,
on_tick: F,
) -> Result<()>
pub fn run_to_end_filtered<F>( &self, class_filter: &HashSet<&str>, on_tick: F, ) -> Result<()>
Parse the entire demo with entity class filtering. Only entities with classes in the filter are fully tracked. This is much faster when you only need specific entity types.
Sourcepub fn run_to_end_with_events_filtered<F>(
&self,
class_filter: &HashSet<&str>,
on_tick: F,
) -> Result<()>
pub fn run_to_end_with_events_filtered<F>( &self, class_filter: &HashSet<&str>, on_tick: F, ) -> Result<()>
Parse the entire demo with entity class filtering AND event collection.
Combines run_to_end_filtered with process_packet_events in a single pass.
The callback receives both the entity context and accumulated events for the tick.