Created
October 19, 2021 00:07
-
-
Save willemolding/1caa56ffd7dc8ca60ee86784928e46d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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