Skip to content

Instantly share code, notes, and snippets.

@willemolding
Created October 19, 2021 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willemolding/1caa56ffd7dc8ca60ee86784928e46d8 to your computer and use it in GitHub Desktop.
Save willemolding/1caa56ffd7dc8ca60ee86784928e46d8 to your computer and use it in GitHub Desktop.
const SIMPLE_RULE: &str = r#"
[
"Record",
[
{ "field_name": "first", "field_rule": ["Int"] },
{ "field_name": "second", "field_rule": ["Record", [{ "field_name": "inner", "field_rule": ["Bool"] }] ] },
{ "field_name": "third", "field_rule": ["Bool"] }
]
]
"#;
// deserialize the rule from the string
let rule: BinProtRule = serde_json::from_str(SIMPLE_RULE).unwrap();
let example = vec![0x05, 0x00, 0x01]; // { first: 5, second: { inner: false }, third: true }
// create our loose type deserializer and get the result
let mut de = Deserializer::from_reader_with_layout(example.as_slice(), &rule);
let result: Value = Deserialize::deserialize(&mut de).unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment