A low level, performance oriented parser for EU4 save files and other PDS developed titles.
Jomini is the cornerstone of the Rakaly, an EU4 achievement leaderboard and save file analyzer. This library is also used in the Paradox Game Converters project to parse ironman EU4 saves.
Below is a demonstration on parsing plaintext data using jomini tools.
```rust use jomini::{JominiDeserialize, TextDeserializer};
pub struct Model {
human: bool,
first: Option
let data = br#" human = yes forth = 10 core = "HAB" names = { "Johan" "Frederick" } core = FRA "#;
let expected = Model { human: true, first: None, fourth: 10, cores: vec!["HAB".tostring(), "FRA".tostring()], names: vec!["Johan".tostring(), "Frederick".tostring()], };
let actual: Model = TextDeserializer::fromslice(data).unwrap(); asserteq!(actual, expected); ```
Parsing data encoded in the binary format is done in a similar fashion but with an extra step. Tokens can be encoded into 16 integers, and so one must provide a map from these integers to their textual representations
```rust use jomini::{JominiDeserialize, BinaryDeserializer}; use std::collections::HashMap;
struct MyStruct { field1: String, }
let data = [ 0x82, 0x2d, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x00, 0x45, 0x4e, 0x47 ];
let mut map = HashMap::new(); map.insert(0x2d82, "field1");
let actual: MyStruct = BinaryDeserializer::fromslice(&data[..], &map).unwrap(); asserteq!(actual, MyStruct { field1: "ENG".to_string() }); ```
When done correctly, one can use the same structure to represent both the plaintext and binary data without any duplication.
One can configure the behavior when a token is unknown (ie: fail immediately or try to continue).
Caller is responsible for:
EU4txt
/ EU4bin
)The plaintext parser is geared towards save file parsing and is not yet general enough to handle files that embed operators other than equals.
If the automatic deserialization via JominiDeserialize
is too high level, one can
interact with the raw data directly via TextTape
and BinaryTape
.
```rust use jomini::{TextTape, TextToken, Scalar};
let data = b"foo=bar";
asserteq!( TextTape::fromslice(&data[..])?.tokens(), &[ TextToken::Scalar(Scalar::new(b"foo")), TextToken::Scalar(Scalar::new(b"bar")), ] ); ```
If one will only use TextTape
and BinaryTape
then jomini
can be compiled without default
features, resulting in a build without dependencies.
Benchmarks are ran with the following command:
cargo clean
cargo bench -- 'parse|deserialize'
find ./target -wholename "*/new/raw.csv" -print0 | xargs -0 xsv cat rows > assets/jomini-benchmarks.csv
And can be analyzed with the R script found in the assets directory.
Below is a graph generated from benchmarking on an arbitrary computer.