35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
use wson::{Config, Node};
|
|
|
|
fn main() -> wson::Result<()> {
|
|
let cfg = Config {
|
|
serialize_references: true,
|
|
..Config::default()
|
|
};
|
|
|
|
let graph = wson::text::parse_str("(0){\"child\":$0,\"id\":25}", &cfg)?;
|
|
let root = graph.root();
|
|
let child = match graph.node(root) {
|
|
Node::Object(entries) => *entries.get("child").expect("child entry"),
|
|
other => panic!("expected object, got {other:?}"),
|
|
};
|
|
assert_eq!(root, child);
|
|
println!("root and child are the same node: {root:?}");
|
|
|
|
let text = wson::text::dump_graph(&graph, &cfg)?;
|
|
println!("text: {text}");
|
|
|
|
let jbon = wson::binary::dump_graph(&graph, &cfg)?;
|
|
println!("jbon length: {} bytes", jbon.len());
|
|
|
|
let reparsed = wson::binary::parse_slice(&jbon, &cfg)?;
|
|
let reparsed_root = reparsed.root();
|
|
let reparsed_child = match reparsed.node(reparsed_root) {
|
|
Node::Object(entries) => *entries.get("child").expect("child entry"),
|
|
other => panic!("expected object, got {other:?}"),
|
|
};
|
|
assert_eq!(reparsed_root, reparsed_child);
|
|
println!("binary round trip ok");
|
|
|
|
Ok(())
|
|
}
|