[−][src]Crate rbx_xml
Configurable Roblox XML place/model format (rbxmx and rbxlx) serializer and deserializer.
rbx_xml uses the rbx_dom_weak crate as its DOM.
This crate implements most of the format and is driven by an up-to-date reflection database.
Deserialization
To decode a place or model, use a method like
from_reader_default
if you're reading from a file,
or from_str_default
if you already have a string.
These methods also have variants like from_str
that let you
pass in custom options.
use rbx_dom_weak::RbxValue; let model_file = r#" <roblox version="4"> <Item class="NumberValue" referent="RBX3B3D9D3DB43D4E6793B190B081E0A886"> <Properties> <string name="Name">My NumberValue</string> <double name="Value">12345</double> </Properties> </Item> </roblox> "#; let model = rbx_xml::from_str_default(model_file) .expect("Couldn't decode model file"); let data_model = model.get_instance(model.get_root_id()).unwrap(); let number_value_id = data_model.get_children_ids()[0]; let number_value = model.get_instance(number_value_id).unwrap(); assert_eq!( number_value.properties.get("Value"), Some(&RbxValue::Float64 { value: 12345.0 }), );
If you're decoding from a file, you'll want to do your own I/O buffering,
like with BufReader
:
use std::{ io::BufReader, fs::File, }; let file = BufReader::new(File::open("place.rbxlx")?); let place = rbx_xml::from_reader_default(file)?;
Note that the RbxTree
instance returned by the rbx_xml decode methods will
have a root instance with the class name DataModel
. This is great for
deserializing a place, but kind of strange for deserializing a model.
Because models can have multiple instances at the top level, rbx_xml can't
just return an RbxTree
with your single instance at the top. Instead, the
crate instead always creates a top-level DataModel
instance which is
pretty close to free.
Serialization
To serialize an existing RbxTree
instance, use methods like
to_writer_default
or to_writer
.
For example, to re-save the place file we loaded above:
use std::{ io::BufWriter, fs::File, }; // A Roblox place file contains all of its top-level instances. let data_model = place.get_instance(place.get_root_id()).unwrap(); let top_level_ids = data_model.get_children_ids(); // Just like when reading a place file, we should buffer our I/O. let file = BufWriter::new(File::create("place-2.rbxlx")?); rbx_xml::to_writer_default(file, &place, top_level_ids)?;
Configuration
rbx_xml exposes no useful configuration yet, but there are methods that
accept DecodeOptions
and
EncodeOptions
that will be useful when it does.
Structs
DecodeError | An error that can occur when deserializing an XML-format model or place. |
DecodeOptions | Options available for deserializing an XML-format model or place. |
EncodeError | An error that can occur when serializing an XML-format model or place. |
EncodeOptions | Options available for serializing an XML-format model or place. |
Enums
DecodePropertyBehavior | Describes the strategy that rbx_xml should use when deserializing properties. |
EncodePropertyBehavior | Describes the strategy that rbx_xml should use when serializing properties. |
Functions
from_reader | Decodes an XML-format model or place from something that implements the
|
from_reader_default | Decodes an XML-format model or place from something that implements the
|
from_str | Decodes an XML-format model or place from a string. |
from_str_default | Decodes an XML-format model or place from a string using the default decoder options. |
to_writer | Serializes a subset of the given tree to an XML format model or place,
writing to something that implements the |
to_writer_default | Serializes a subset of the given tree to an XML format model or place,
writing to something that implements the |