mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-11 12:05:09 -05:00
lib: expose Node parsing from kbin
This commit is contained in:
12
src/lib.rs
12
src/lib.rs
@@ -46,7 +46,7 @@ pub use compression::Compression;
|
||||
pub use encoding_type::EncodingType;
|
||||
pub use printer::Printer;
|
||||
pub use error::{KbinError, KbinErrorKind, Result};
|
||||
pub use node::{ExtraNodes, Node};
|
||||
pub use node::{ExtraNodes, Node, NodeCollection};
|
||||
pub use options::Options;
|
||||
pub use de::from_bytes;
|
||||
pub use ser::to_bytes;
|
||||
@@ -309,6 +309,16 @@ impl KbinXml {
|
||||
kbinxml.from_binary_internal(input)
|
||||
}
|
||||
|
||||
pub fn node_from_binary(input: &[u8]) -> Result<(Node, EncodingType)> {
|
||||
let mut reader = Reader::new(input)?;
|
||||
let collection = NodeCollection::from_iter(&mut reader).ok_or(KbinErrorKind::InvalidState)?;
|
||||
|
||||
let node = collection.as_node()?;
|
||||
let encoding = reader.encoding();
|
||||
|
||||
Ok((node, encoding))
|
||||
}
|
||||
|
||||
pub fn to_binary(input: &Element) -> Result<Vec<u8>> {
|
||||
let mut kbinxml = KbinXml::new();
|
||||
kbinxml.to_binary_internal(input)
|
||||
|
||||
Reference in New Issue
Block a user