[cleanup][inspect-node-hierarchy] Remove no longer used deprecated formatter

Tested: existing tests

Change-Id: Iae8e29f670022f28933b9c41c2861db1e24b9687
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/405080
Testability-Review: Miguel Flores <miguelfrde@google.com>
Reviewed-by: Luke Nicholson <lukenicholson@google.com>
Commit-Queue: Miguel Flores <miguelfrde@google.com>
diff --git a/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/deprecated_json.rs b/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/deprecated_json.rs
deleted file mode 100644
index e1963359..0000000
--- a/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/deprecated_json.rs
+++ /dev/null
@@ -1,244 +0,0 @@
-// Copyright 2019 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-use {
-    crate::serialization::{serialize::SerializableHierarchyFields, utils::format_parts, *},
-    anyhow::Error,
-    serde::ser::{Serialize, SerializeMap, SerializeStruct, Serializer},
-    serde_json::{
-        json,
-        ser::{PrettyFormatter, Serializer as JsonSerializer},
-    },
-    std::str::from_utf8,
-};
-
-/// A JSON formatter for an inspect node hierarchy.
-/// NOTE: This is deprecated. It's currently used by the Archivist and iquery but we are migrating
-/// away from it as we migrate to use the Unified Reader server. New clients should use
-/// `JsonHierarchySerializer`.
-// TODO(fxb/43112): remove
-pub struct DeprecatedJsonFormatter {}
-
-impl DeprecatedHierarchyFormatter for DeprecatedJsonFormatter {
-    fn format(hierarchy: DeprecatedHierarchyData) -> Result<String, Error> {
-        let mut bytes = Vec::new();
-        let mut serializer =
-            JsonSerializer::with_formatter(&mut bytes, PrettyFormatter::with_indent(b"    "));
-        json!(SerializableHierarchyData { hierarchy_data: hierarchy })
-            .serialize(&mut serializer)?;
-        Ok(from_utf8(&bytes)?.to_string())
-    }
-
-    fn format_multiple(hierarchies: Vec<DeprecatedHierarchyData>) -> Result<String, Error> {
-        let values = hierarchies
-            .into_iter()
-            .map(|hierarchy_data| SerializableHierarchyData { hierarchy_data })
-            .collect::<Vec<SerializableHierarchyData>>();
-        let mut bytes = Vec::new();
-        let mut serializer =
-            JsonSerializer::with_formatter(&mut bytes, PrettyFormatter::with_indent(b"    "));
-        json!(values).serialize(&mut serializer)?;
-        Ok(from_utf8(&bytes)?.to_string())
-    }
-}
-
-pub struct SerializableHierarchyData {
-    hierarchy_data: DeprecatedHierarchyData,
-}
-
-struct WrappedSerializableNodeHierarchy<'a> {
-    hierarchy: &'a NodeHierarchy,
-}
-
-impl<'a> Serialize for WrappedSerializableNodeHierarchy<'a> {
-    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
-        let mut s = serializer.serialize_map(Some(1))?;
-        let name = self.hierarchy.name.clone();
-        s.serialize_entry(&name, &SerializableHierarchyFields { hierarchy: &self.hierarchy })?;
-        s.end()
-    }
-}
-
-impl Serialize for SerializableHierarchyData {
-    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
-        let mut s = serializer.serialize_struct("NodeHierarchy", 2)?;
-        let path = format_parts(&self.hierarchy_data.file_path, &self.hierarchy_data.fields);
-        s.serialize_field("path", &path)?;
-        let hierarchy =
-            WrappedSerializableNodeHierarchy { hierarchy: &self.hierarchy_data.hierarchy };
-        s.serialize_field("contents", &hierarchy)?;
-        s.end()
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use {
-        super::*,
-        crate::{ArrayContent, ArrayFormat, Property},
-    };
-
-    #[test]
-    fn format_json() {
-        let hierarchy =
-            NodeHierarchy::new("root", vec![Property::Double("double".to_string(), 2.5)], vec![]);
-        let data = DeprecatedHierarchyData {
-            hierarchy,
-            file_path: "/some/path/out/diagnostics/root.inspect".to_string(),
-            fields: vec![],
-        };
-        let result = DeprecatedJsonFormatter::format(data).expect("failed to format hierarchy");
-        let expected = "{
-    \"contents\": {
-        \"root\": {
-            \"double\": 2.5
-        }
-    },
-    \"path\": \"/some/path/out/diagnostics/root.inspect\"
-}";
-        assert_eq!(result, expected);
-    }
-
-    #[test]
-    fn format_json_multiple() -> Result<(), Error> {
-        let (a, b) = get_hierarchies();
-        let datas = vec![
-            DeprecatedHierarchyData {
-                hierarchy: a,
-                file_path: "/some/path/out/diagnostics/root.inspect".to_string(),
-                fields: vec![],
-            },
-            DeprecatedHierarchyData {
-                hierarchy: b,
-                file_path: "/other/path/out/diagnostics".to_string(),
-                fields: vec!["root".to_string(), "x".to_string(), "y".to_string()],
-            },
-        ];
-        let result =
-            DeprecatedJsonFormatter::format_multiple(datas).expect("failed to format hierarchies");
-        assert_eq!(get_expected_multi_json(), result);
-        Ok(())
-    }
-
-    fn get_hierarchies() -> (NodeHierarchy, NodeHierarchy) {
-        (
-            NodeHierarchy::new(
-                "root",
-                vec![Property::UintArray(
-                    "array".to_string(),
-                    ArrayContent::new(vec![0, 2, 4], ArrayFormat::Default).unwrap(),
-                )],
-                vec![
-                    NodeHierarchy::new(
-                        "a",
-                        vec![
-                            Property::Double("double".to_string(), 2.5),
-                            Property::DoubleArray(
-                                "histogram".to_string(),
-                                ArrayContent::new(
-                                    vec![0.0, 2.0, 4.0, 1.0, 3.0, 4.0],
-                                    ArrayFormat::ExponentialHistogram,
-                                )
-                                .unwrap(),
-                            ),
-                        ],
-                        vec![],
-                    ),
-                    NodeHierarchy::new(
-                        "b",
-                        vec![
-                            Property::Int("int".to_string(), -2),
-                            Property::String("string".to_string(), "some value".to_string()),
-                            Property::IntArray(
-                                "histogram".to_string(),
-                                ArrayContent::new(
-                                    vec![0, 2, 4, 1, 3],
-                                    ArrayFormat::LinearHistogram,
-                                )
-                                .unwrap(),
-                            ),
-                        ],
-                        vec![],
-                    ),
-                ],
-            ),
-            NodeHierarchy::new(
-                "y",
-                vec![Property::Bytes("bytes".to_string(), vec![5u8, 0xf1, 0xab])],
-                vec![],
-            ),
-        )
-    }
-
-    fn get_expected_multi_json() -> String {
-        "[
-    {
-        \"contents\": {
-            \"root\": {
-                \"a\": {
-                    \"double\": 2.5,
-                    \"histogram\": {
-                        \"buckets\": [
-                            {
-                                \"count\": 1.0,
-                                \"floor\": \"-Infinity\",
-                                \"upper_bound\": 0.0
-                            },
-                            {
-                                \"count\": 3.0,
-                                \"floor\": 0.0,
-                                \"upper_bound\": 2.0
-                            },
-                            {
-                                \"count\": 4.0,
-                                \"floor\": 2.0,
-                                \"upper_bound\": \"Infinity\"
-                            }
-                        ]
-                    }
-                },
-                \"array\": [
-                    0,
-                    2,
-                    4
-                ],
-                \"b\": {
-                    \"histogram\": {
-                        \"buckets\": [
-                            {
-                                \"count\": 4,
-                                \"floor\": -9223372036854775808,
-                                \"upper_bound\": 0
-                            },
-                            {
-                                \"count\": 1,
-                                \"floor\": 0,
-                                \"upper_bound\": 2
-                            },
-                            {
-                                \"count\": 3,
-                                \"floor\": 2,
-                                \"upper_bound\": 9223372036854775807
-                            }
-                        ]
-                    },
-                    \"int\": -2,
-                    \"string\": \"some value\"
-                }
-            }
-        },
-        \"path\": \"/some/path/out/diagnostics/root.inspect\"
-    },
-    {
-        \"contents\": {
-            \"y\": {
-                \"bytes\": \"b64:BfGr\"
-            }
-        },
-        \"path\": \"/other/path/out/diagnostics#x/y\"
-    }
-]"
-        .to_string()
-    }
-}
diff --git a/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/mod.rs b/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/mod.rs
index d830d15..21ca9cc 100644
--- a/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/mod.rs
+++ b/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/mod.rs
@@ -33,13 +33,10 @@
 
 use {crate::NodeHierarchy, anyhow::Error};
 
-pub use crate::serialization::deprecated_json::*;
 pub use crate::serialization::json::*;
 
-pub mod deprecated_json;
 pub mod json;
 mod serialize;
-mod utils;
 
 /// Implementers of this trait will be able to convert an `Object` type data format that
 /// is encoding a diagnostics data hierarchy into a NodeHierarchy.
@@ -47,37 +44,3 @@
     type Object;
     fn deserialize(data_format: Self::Object) -> Result<NodeHierarchy<Key>, Error>;
 }
-
-/// DEPRECATED:
-/// Node hierarchies to be formatted including information about the path.
-/// Example:
-///
-/// ```
-/// DeprecatedHierarchyData {
-///     hierarchy: SOME_HIERARCHY,
-///     file_path: "/some/path",
-///     fields: vec!["root", "node1", "node2"],
-/// }
-/// ```
-///
-/// Means that the hierarchy `SOME_HIERARCHY` points to the inspect node named
-/// `node2` that is child of the node `node1` under `root` in an inspect file
-/// located at `/some/path`.
-///
-pub struct DeprecatedHierarchyData {
-    /// The node hierarchy to be formatted.
-    pub hierarchy: NodeHierarchy,
-
-    /// The path where the inspect file is.
-    pub file_path: String,
-
-    /// The path to the node within the inspect tree.
-    pub fields: Vec<String>,
-}
-
-/// Implementers of this trait will provide different ways of formatting an
-/// inspect hierarchy.
-pub trait DeprecatedHierarchyFormatter {
-    fn format(hierarchy: DeprecatedHierarchyData) -> Result<String, Error>;
-    fn format_multiple(hierarchies: Vec<DeprecatedHierarchyData>) -> Result<String, Error>;
-}
diff --git a/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/utils.rs b/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/utils.rs
deleted file mode 100644
index ada3dc7c..0000000
--- a/src/lib/inspect/rust/fuchsia-inspect-node-hierarchy/src/serialization/utils.rs
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2019 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-/// Returns an inspect path representation given a prefix file path and a sorted
-/// path of node hierarchy subproperties.
-///
-/// Example:
-///     format_parts("/some/path/root.inspect", vec!["root", "a", "b"]) will return
-///     "/some/path/root.inspect#a/b"
-///
-pub fn format_parts(file_path: &str, parts: &[String]) -> String {
-    if parts.is_empty() || (parts[0] == "root" && parts.len() == 1) {
-        file_path.to_string()
-    } else if parts[0] == "root" {
-        format!("{}#{}", file_path, parts[1..].join("/"))
-    } else {
-        format!("{}#{}", file_path, parts.join("/"))
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    fn test_format_parts() {
-        let path = "/my/inspect_file/path";
-        assert_eq!(format_parts(path, &vec![]), path);
-        assert_eq!(format_parts(path, &vec!["root".to_string()]), path);
-        assert_eq!(
-            format_parts(path, &vec!["root".to_string(), "some_node".to_string()]),
-            format!("{}#some_node", path)
-        );
-        assert_eq!(
-            format_parts(
-                path,
-                &vec!["root".to_string(), "some_node".to_string(), "some_property".to_string()]
-            ),
-            format!("{}#some_node/some_property", path)
-        );
-    }
-}