Byml

Enum Byml 

Source
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),
}
Expand description

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

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.

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:

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.

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>)

§

Hash(BTreeMap<String, Byml>)

§

Bool(bool)

§

Int(i32)

§

Float(Float)

§

UInt(u32)

§

Int64(i64)

§

UInt64(u64)

§

Double(Double)

Implementations§

Source§

impl Byml

Source

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

Source

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

Source§

impl Byml

Source

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

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

Source

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

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.

Source

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

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

Source§

impl Byml

Source

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

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

Source§

impl Byml

Source

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

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.

Source§

impl Byml

Source

pub fn is_container(&self) -> bool

Returns whether the node is an array or hash

Source

pub fn is_value(&self) -> bool

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

Source

pub fn is_string(&self) -> bool

Do I even need to document this one?

Source

pub fn get_type(&self) -> NodeType

Gets the node type

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

pub fn is_null(&self) -> bool

Checks if the node is a null value

Trait Implementations§

Source§

impl Clone for Byml

Source§

fn clone(&self) -> Byml

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Byml

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Byml

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for Byml

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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

Source§

type Output = Byml

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for Byml

Source§

fn eq(&self, other: &Byml) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Byml

Auto Trait Implementations§

§

impl Freeze for Byml

§

impl RefUnwindSafe for Byml

§

impl Send for Byml

§

impl Sync for Byml

§

impl Unpin for Byml

§

impl UnwindSafe for Byml

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.