Module jomini::binary

source ·
Expand description

Types for parsing clausewitz binary input

Main binary deserialization APIs:

If the serde deserialization API is too high level, one can build abstractions ontop of.

  • BinaryTape::from_slice: Realizes a pseudo AST onto a linear tape. Cleans up and normalizes data.
  • TokenReader: An incremental binary lexer designed for handling large saves in a memory efficient manner.
  • Lexer: The lowest level, a zero cost binary data scanner over a byte slice.

§Direct identifier deserialization with token attribute

There may be some performance loss during binary deserialization as tokens are resolved to strings via a TokenResolver and then matched against the string representations of a struct’s fields.

We can fix this issue by directly encoding the expected token value into the struct:

#[derive(JominiDeserialize, PartialEq, Debug)]
struct MyStruct {
    #[jomini(token = 0x2d82)]
    field1: String,
}

// Empty token to string resolver
let map = HashMap::<u16, String>::new();

let actual: MyStruct = BinaryTestFlavor.deserialize_slice(&data[..], &map)?;
assert_eq!(actual, MyStruct { field1: "ENG".to_string() });

Couple notes:

  • This does not obviate need for the token to string resolver as tokens may be used as values.
  • If the token attribute is specified on one field on a struct, it must be specified on all fields of that struct.

Modules§

  • binary deserialization

Structs§

Enums§

Traits§