ci Version

Jomini

A low level, performance orientated 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.

Features

Quick Start

Below is a demonstration on parsing plaintext data using jomini tools.

```rust use jomini::{JominiDeserialize, TextDeserializer};

[derive(JominiDeserialize, PartialEq, Debug)]

pub struct Model { human: bool, first: Option, #[jomini(alias = "forth")] fourth: u16, #[jomini(alias = "core", duplicated)] cores: Vec, names: Vec, }

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

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

```rust use jomini::{JominiDeserialize, BinaryDeserializer}; use std::collections::HashMap;

[derive(JominiDeserialize, PartialEq, Debug)]

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).

Caveats

Caller is responsible for:

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

It can be the case that either that having the data automatically deserialized into a data structure is inappropriate. Maybe there's a requirement to accomplish everything without pulling in additional dependencies. Whatever the case, one can opt into using TextTape and BinaryTape directly.

```rust use jomini::{TextTape, TextToken, Scalar};

let data = b"foo=bar";

asserteq!( TextTape::fromslice(&data[..]).unwrap().token_tape, vec![ TextToken::Scalar(Scalar::new(b"foo")), TextToken::Scalar(Scalar::new(b"bar")), ] ); ```

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.

jomini-bench-throughput.png