2 unstable releases

0.2.0 Jan 7, 2024
0.1.0 Aug 16, 2023

#803 in Data structures

36 downloads per month
Used in cdragon

MIT/Apache

105KB
2K SLoC

CDragon library for BIN files

Library to work with BIN files used League of Legends.


lib.rs:

Support of Riot PROP files

Overview

PROP files, more commonly called bin files, contain nested data structures. All structures are typed and usually abide to the same type, but type is provided in the data itself, so there is no need to have a schema to decode it.

Each PROP File contains a list of entries which itself contains a nested list of fields of various data types.

Dynamic types

Container types store data whose type is defined dynamically. Since Rust types are defined statically, they cannot be used directly. Moreover, even if the embedded bin type is known by the container at run-time, the Rust type system requires the user to explicitely request a given type, one way or the other.

The [binget!()] macro makes it easier to chain casts and should be enough when the names and types to get are known in advance.

Data can also be casted explicitely, using the downcast() method provided by all types wrapping dynamically typed data:

field.downcast::<BinString>();
// => `Some(BinString)` if field contains a string, `None` otherwise

Containers with fields provide a getv() helper to follow a get() with a downcast().

If all possible types have to be handled, the [binvalue_map_type!()] can be used to provide a single generic expression to handle all possible types.

Map keys support only a subset or types. [binvalue_map_keytype!()] can be used to map only key types. It can be combined with another [binvalue_map_type!()] to handle both keys and values.

Note: those macros are expanded to a match handling all possible cases; resulting code can be large.

Examples

binvalue_map_type!(field.vtype, T, {
    let value: &T = field.downcast::<T>().unwrap();
});

binvalue_map_keytype!(map.ktype, K,
    binvalue_map_type!(map.vtype, V, {
        let entries: &Vec<(K, V)> = map.downcast::<K, V>().unwrap();
    })
);

Bin hashes

Bin files use 32-bit FNV-1a hashes for several identifier names:

Hash values can be computed at compile-time with [cdragon_hashes::binh!()], or using other methods from cdragon_hashes::bin.

A BinHashMappers gather all hash-to-string conversion needed by bin data.

Dependencies

~1.3–2MB
~40K SLoC