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§
- Houses the tape of tokens that is extracted from binary data
- Customizes how the binary tape is parsed from data
- The ID of current Lexeme
- Zero cost binary data scanner.
- Lexical error type with positional information
- An binary lexing error over a
Read
implementation - Extracted color info
- Creates a binary token reader
Enums§
- Represents any valid binary value
- Customize how the deserializer reacts when a token can’t be resolved
- Lexical error type without positional information
- The specific binary reader error type.
- Binary token, the raw form of BinaryToken
Traits§
- Trait customizing decoding values from binary data
- Resolves binary 16bit tokens to field names