Crate teehistorian

Source
Expand description

teehistorian parser for DDNet

This crate provides a library for safe parsing of teehistorian files from the game DDNet. Goals of this library are:

  • performance
    • the header is retrievable without loading the whole file
    • the teehistorian file doesn’t have to fit into memory
  • provide a C-API to eventually integrate it into DDNet for a teehistorian replayer

In the very center of this library is the Th struct to get the stream of Chunks of an teehistorian file

§Examples

With the teehistorian file loaded directly into memory

use teehistorian::{Chunk, Th};
let input = b"\x69\x9d\xb1\x7b\x8e\xfb\x34\xff\xb1\xd8\xda\x6f\x60\xc1\x5d\xd1\
           {\"version\":\"2\"}\x00\
           \x40";
let mut th = Th::parse(&input[..]).unwrap();
assert_eq!(th.header().unwrap(), br#"{"version":"2"}"#);
assert_eq!(th.next_chunk().unwrap(), Chunk::Eos);
assert!(th.next_chunk().unwrap_err().is_eof());

When operating with files:

use teehistorian::{Chunk, ThBufReader, Th};
use std::fs::File;

let f = File::open("tests/minimal.teehistorian").unwrap();
let mut th = Th::parse(ThBufReader::new(f)).unwrap();
assert_eq!(th.header().unwrap(), br#"{"version":"2"}"#);
assert_eq!(th.next_chunk().unwrap(), Chunk::Eos);
assert!(th.next_chunk().unwrap_err().is_eof());

Re-exports§

pub use chunks::Chunk;

Modules§

chunks

Structs§

Th
Straight forward Teehistorian reader: outputs the chunks as they are in the file. With this reader, you need to be careful with Teehistorian version differences. For a more consistent reader, which takes care of some differences, use ThCompat.
ThBufReader
ThCompat
Like Th, with some added compatibility to bridge version differences.
ThWriter

Enums§

Error
All possible Errors returned by this library
ErrorKind

Traits§

ThBufRead
ThStream

Functions§

serialize_into
export packer for now. TODO: move to separate crate