Created
May 25, 2020 06:31
-
-
Save DarkFenX/4b9345802249579a50bba3aae912c42b 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
fn flatten_l1(json: serde_json::Value, key_name: &'static str) -> Result<Flattened> { | |
match json { | |
serde_json::Value::Object(outer_map) => { | |
let mut data = HashMap::new(); | |
let mut failed: u32 = 0; | |
for (k, v) in outer_map.into_iter() { | |
match (v, k.parse::<ReeInt>()) { | |
(serde_json::Value::Object(mut inner_map), Ok(id)) => { | |
insert_int(&mut inner_map, key_name, id); | |
data.insert(id, serde_json::Value::Object(inner_map)); | |
} | |
(_, Err(e)) => { | |
log::debug!("error while flattening due to ID parsing: {}", e); | |
failed += 1; | |
} | |
(_, Ok(id)) => { | |
log::debug!("error while flattening due to non-map item with ID {}", id); | |
failed += 1; | |
} | |
} | |
} | |
Ok(Flattened { data, failed }) | |
} | |
_ => Err(Error::new( | |
"FSD Lite decomposition failed: highest-level structure is not a map", | |
)), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment