Expand description
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.
Re-exports§
pub use visitor::BinVisitor;
pub use visitor::BinTraversal;
pub use data::*;
Modules§
Macros§
- binget
- Helper to access nested bin values
- binvalue_
map_ keytype - Same as
binvalue_map_type!
, but limited to types used aBinMap
keys - binvalue_
map_ type - Map
BinType
variant toBinValue
concrete type in an expression
Structs§
- BinEntry
- Entry in a PROP file
- BinEntry
Scanner - Scan entries from a bin file
- BinHash
Kind Mapping - Generic type to associate each kind of hash from bin files to a value
- Json
Serializer - Serialize bin values to JSON
- Prop
File - PROP file, with entries
- Text
Tree Serializer - Serialize bin values to a human readable text tree
Enums§
- BinHash
Kind - Enum with a variant for each kind of bin hash
- Prop
Error - Error in a PROP file
Constants§
- NON_
PROP_ BASENAMES - Files known to not be PROP files, despite their extension
Traits§
- BinEntries
Serializer - Serialize streamed bin entries
- BinSerializer
- Serialize bin data
Functions§
- is_
binfile_ path - Return
true
if a path is a bin file path
Type Aliases§
- BinEntry
Header - Entry header, used by parsers that iterate on entries
- BinEntry
Scanner Item - Item type for entry scanning
- BinHash
Mapper - Mapper for bin hashes
- BinHash
Mappers - Hash mappers for all kinds of bin hashes