[][src]Enum byml::Byml

pub enum Byml {
    Null,
    String(String),
    Binary(Vec<u8>),
    Array(Vec<Byml>),
    Hash(BTreeMap<String, Byml>),
    Bool(bool),
    Int(i32),
    Float(Float),
    UInt(u32),
    Int64(i64),
    UInt64(u64),
    Double(Double),
}

Represents a Nintendo binary YAML (BYML) document or node. A Byml will usually be constructed from binary data or a YAML string, e.g.

This example is not tested
let buf: Vec<u8> = std::fs::read("A-1_Static.smubin")?;
let map_unit = Byml::from_binary(&buf)?;
let text: String = std::fs::read_to_string("A-1_Static.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.

This example is not tested
let buf: Vec<u8> = std::fs::read("A-1_Static.smubin")?;
let map_unit = Byml::from_binary(&buf)?;
std::fs::write("A-1_Static.yml", &map_unit.to_text()?)?;
std::fs::write("A-1_Static.copy.mubin", &map_unit.to_binary(Endian::Big, 2)?)?;

A number of convenience getters are available which return a result for a variant value:

This example is not tested
let doc = Byml::from_binary(&some_data)?;
let hash: &BTreeMap<String, Byml> = doc.as_hash()?;

Most of the node types are fairly self-explanatory. Arrays are implemented as Vec<Byml>, and hash nodes as BTreeMap<String, Byml>. Floats (f32) and doubles (f64) use wrapper types that support Eq. These can be converted with into(). You can also query the node type with get_type().

For convenience, a Byml known to be an array or hash node can be indexed. Panics if the node has the wrong type or if the index is not found.

This example is not tested
let buf: Vec<u8> = std::fs::read("ActorInfo.product.sbyml")?;
let actor_info = Byml::from_binary(&buf)?;
assert_eq(actor_info["Actors"].as_array()?.len(), 7934);
assert_eq(actor_info["Hashes"][0].as_int(), 31119);

Variants

Null
String(String)
Binary(Vec<u8>)
Array(Vec<Byml>)
Bool(bool)
Int(i32)
Float(Float)
UInt(u32)
Int64(i64)
UInt64(u64)
Double(Double)

Implementations

impl Byml[src]

pub fn from_binary<B: AsRef<[u8]>>(data: &B) -> Result<Byml, Box<dyn Error>>[src]

pub fn read_binary<R: Read + Seek>(
    reader: &mut R
) -> Result<Byml, Box<dyn Error>>
[src]

impl Byml[src]

pub fn to_binary(
    &self,
    endian: Endian,
    version: u16
) -> Result<Vec<u8>, WriteError>
[src]

Serialize the document to binary data with the specified endianness and version. Only hash, array, or null nodes can be used.

pub fn to_compressed_binary(
    &self,
    endian: Endian,
    version: u16
) -> Result<Vec<u8>, WriteError>
[src]

Serialize the document to binary data with the specified endianness and version and yaz0 compress it. Only hash, array, or null nodes can be used.

pub fn write_binary<W: Write + Seek>(
    &self,
    writer: &mut W,
    endian: Endian,
    version: u16
) -> Result<(), WriteError>
[src]

Write the binary serialized BYML document to a writer with the specified endianness and version. Only hash, array, or null nodes can be used.

impl Byml[src]

pub fn to_text(&self) -> Result<String, Box<dyn Error>>[src]

Serialize the document to a YAML string. The YAML output is fully compatible with the oead and byml Python libraries.

impl Byml[src]

pub fn from_text(text: &str) -> Result<Byml, Box<dyn Error>>[src]

Read a BYML document from a YAML string. The input YAML format is the same as that used by the byml and oead Python libraries.

impl Byml[src]

pub fn is_container(&self) -> bool[src]

Returns whether the node is an array or hash

pub fn is_value(&self) -> bool[src]

Returns whether the node is an inline value (Int, UInt, Float, or Bool)

pub fn is_string(&self) -> bool[src]

Do I even need to document this one?

pub fn get_type(&self) -> NodeType[src]

Gets the node type

pub fn as_hash(&self) -> Result<&BTreeMap<String, Byml>, TypeError>[src]

Returns a result with a reference to the inner BYML hash or a type error

pub fn as_array(&self) -> Result<&Vec<Byml>, TypeError>[src]

Returns a result with a reference to the inner BYML array or a type error

pub fn as_binary(&self) -> Result<&Vec<u8>, TypeError>[src]

Returns a result with a reference to the inner BYML binary data or a type error

pub fn as_bool(&self) -> Result<bool, TypeError>[src]

Returns a result with the inner boolean value or a type error

pub fn as_string(&self) -> Result<&String, TypeError>[src]

Returns a result with a reference to the inner string or a type error

pub fn as_int(&self) -> Result<&i32, TypeError>[src]

Returns a result with a reference to the inner i32 or a type error

pub fn as_int64(&self) -> Result<&i64, TypeError>[src]

Returns a result with a reference to the inner i64 or a type error

pub fn as_uint(&self) -> Result<&u32, TypeError>[src]

Returns a result with a reference to the inner u32 or a type error

pub fn as_uint64(&self) -> Result<&u64, TypeError>[src]

Returns a result with a reference to the inner u64 or a type error

pub fn as_float(&self) -> Result<f32, TypeError>[src]

Returns a result with the inner f32 value or a type error

pub fn as_double(&self) -> Result<f64, TypeError>[src]

Returns a result with the inner f64 value or a type error

pub fn as_mut_hash(&mut self) -> Result<&BTreeMap<String, Byml>, TypeError>[src]

Returns a result with a mutable reference to the inner BYML hash or a type error

pub fn as_mut_array(&mut self) -> Result<&Vec<Byml>, TypeError>[src]

Returns a result with a mutable reference to the inner BYML array or a type error

pub fn as_mut_binary(&mut self) -> Result<&Vec<u8>, TypeError>[src]

Returns a result with a mutable reference to the inner binary data or a type error

pub fn as_mut_string(&mut self) -> Result<&String, TypeError>[src]

Returns a result with a mutable reference to the inner string or a type error

pub fn as_mut_int(&mut self) -> Result<&i32, TypeError>[src]

Returns a result with a mutable reference to the inner i32 or a type error

pub fn as_mut_int64(&mut self) -> Result<&i64, TypeError>[src]

Returns a result with a mutable reference to the inner i64 or a type error

pub fn as_mut_uint(&mut self) -> Result<&u32, TypeError>[src]

Returns a result with a mutable reference to the inner u32 or a type error

pub fn as_mut_uint64(&mut self) -> Result<&u64, TypeError>[src]

Returns a result with a mutable reference to the inner u64 or a type error

pub fn is_null(&self) -> bool[src]

Checks if the node is a null value

Trait Implementations

impl Clone for Byml[src]

impl Debug for Byml[src]

impl Default for Byml[src]

impl Eq for Byml[src]

impl Hash for Byml[src]

impl<'a, I> Index<I> for Byml where
    I: Into<BymlIndex<'a>>, 
[src]

type Output = Byml

The returned type after indexing.

impl PartialEq<Byml> for Byml[src]

impl StructuralEq for Byml[src]

Auto Trait Implementations

impl RefUnwindSafe for Byml

impl Send for Byml

impl Sync for Byml

impl Unpin for Byml

impl UnwindSafe for Byml

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.