Jomini
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 and CK3 saves.
Features
- ✔ Versatile: Handle both plaintext and binary encoded data
- ✔ Fast: Parse data at 1 GB/s
- ✔ Small: Compile with zero dependencies
- ✔ Safe: Extensively fuzzed against potential malicious input
- ✔ Ergonomic: Use serde-like macros to have parsing logic automatically implemented
- ✔ Embeddable: Cross platform native apps, statically compiled services, or in the browser via WASM
- ✔ Agnostic: Parse EU4, HOIV, Imperator, CK3, etc save files
Quick Start
Below is a demonstration on parsing plaintext data using jomini tools.
use ;
let data = br#"
human = yes
forth = 10
core = "HAB"
names = { "Johan" "Frederick" }
core = FRA
"#;
let expected = Model ;
let actual: Model = from_windows1252_slice?;
assert_eq!;
Binary Parsing
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
use ;
use HashMap;
let data = ;
let mut map = new;
map.insert;
let actual: MyStruct = from_eu4?;
assert_eq!;
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).
Caveats
Caller is responsible for:
- Determining the correct format (text or binary) ahead of time
- Stripping off any header that may be present (eg:
EU4txt
/EU4bin
) - Providing the token resolver for the binary format
- Providing the conversion to reconcile how, for example, a date may be encoded as an integer in the binary format, but as a string when in plaintext.
The plaintext parser is geared towards save file parsing and is not yet general enough to handle files that embed operators other than equals.
One Level Lower
If the automatic deserialization via JominiDeserialize
is too high level, one can
interact with the raw data directly via TextTape
and BinaryTape
.
use ;
let data = b"foo=bar";
assert_eq!;
If one will only use TextTape
and BinaryTape
then jomini
can be compiled without default
features, resulting in a build without dependencies.
Benchmarks
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.