Expand description
Port of the oead::byml
module.
A Byml
type will usually be constructed from binary data or a YAML string,
e.g.
let buf: Vec<u8> = std::fs::read("test/byml/A-1_Dynamic.byml")?;
let map_unit = Byml::from_binary(&buf)?;
let text: String = std::fs::read_to_string("test/byml/A-1_Dynamic.yml")?;
//let map_unit2 = Byml::from_text(&text)?;
//assert_eq!(map_unit, map_unit2);
You can also easily serialize to binary or a YAML string.
let buf: Vec<u8> = std::fs::read("test/aamp/A-1_Dynamic.byml")?;
let map_unit = Byml::from_binary(&buf)?;
//std::fs::write("A-1_Static.yml", &map_unit.to_text())?;
std::fs::write(
"test/aamp/A-1_Dynamic.byml",
&map_unit.to_binary(Endian::Big),
)?;
A number of convenience getters are available which return a result for a variant value:
let doc = Byml::from_binary(some_data)?;
let map = doc.as_map().unwrap();
Most of the node types are fairly self-explanatory. Arrays are implemented
as Vec<Byml>
, and maps as FxHashMap<String, Byml>
. The new v7 hash maps
are FxHashMap<u32, Byml>
and FxHashMap<u32, (Byml, u32)>
.
For convenience, a Byml
known to be an array or map can be
indexed. Panics if the node has the wrong type, the index has the wrong
type, or the index is not found.
let buf: Vec<u8> = std::fs::read("test/byml/ActorInfo.product.byml")?;
let actor_info = Byml::from_binary(&buf)?;
assert_eq!(actor_info["Actors"].as_array().unwrap().len(), 7934);
assert_eq!(actor_info["Hashes"][0].as_i32().unwrap(), 31119);
Macros§
- Convenience macro to construct a
Byml
array using array literal syntax. Example: - Convenience macro to construct a
Byml
map using map literal syntax. Example:
Enums§
- Represents a Nintendo binary YAML (BYML) document or node.
- Convenience type used for indexing into
Byml
s
Type Aliases§
- A BYML hash node.