Add README and examples

This commit is contained in:
2026-09-05 23:30:06 +00:00
parent d4b77ddcb9
commit 51b6c635d7
4 changed files with 206 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
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(())
}