Skip to content

Instantly share code, notes, and snippets.

@DarkFenX
Created May 25, 2020 06:31
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 DarkFenX/4b9345802249579a50bba3aae912c42b to your computer and use it in GitHub Desktop.
Save DarkFenX/4b9345802249579a50bba3aae912c42b to your computer and use it in GitHub Desktop.
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