22 unstable releases (9 breaking)

0.12.0 Nov 17, 2024
0.11.0 Oct 13, 2024
0.10.2 Jul 18, 2024
0.9.0 Aug 24, 2023
0.3.2 Mar 15, 2021

#736 in Parser implementations

Download history 152/week @ 2024-08-19 37/week @ 2024-08-26 20/week @ 2024-09-16 19/week @ 2024-09-23 44/week @ 2024-09-30 336/week @ 2024-10-07 177/week @ 2024-10-14 21/week @ 2024-10-21 7/week @ 2024-10-28 178/week @ 2024-11-04 72/week @ 2024-11-11 70/week @ 2024-11-18 28/week @ 2024-11-25 30/week @ 2024-12-02

206 downloads per month
Used in 7 crates (via twgame-core)

LGPL-3.0

72KB
2K SLoC

Teehistorian parser

This is a Teehistorian parser, a data format for DDNet servers saving all input to reproduce it faithfully.

License

LGPL-3.0


lib.rs:

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());

Dependencies

~1.4–2.2MB
~45K SLoC