pub fn add_json<R>(&mut self, reader: &mut R) -> Result<()>
    where
        R: io::Read,
    {
        let input: Value = from_reader(reader)?;

        // Which schema should this follow.
        let schema_id: &str =
            input["version"].as_str().ok_or(format_err!("Missing version string"))?;

        // Validate the input against the schema.
        let mut scope = json_schema::Scope::new();

        let common_schema = from_str(include_str!("../../../../../../build/sdk/meta/common.json"))?;
        scope
            .compile(common_schema, /*ban_unknown=*/ true)
            .map_err(|e| format_err!("common.json failed to compile: {:?}", e))?;

        let common_schema =
            from_str(include_str!("../../../../../../build/sdk/meta/emu_manifest.json"))?;
        scope
            .compile(common_schema, /*ban_unknown=*/ true)
            .map_err(|e| format_err!("emu_manifest.json failed to compile: {:?}", e))?;

        let common_schema =
            from_str(include_str!("../../../../../../build/sdk/meta/flash_manifest-02.json"))?;
        scope
            .compile(common_schema, /*ban_unknown=*/ true)
            .map_err(|e| format_err!("flash_manifest-02.json failed to compile: {:?}", e))?;

        let common_schema =
            from_str(include_str!("../../../../../../build/sdk/meta/hardware.json"))?;
        scope
            .compile(common_schema, /*ban_unknown=*/ true)
            .map_err(|e| format_err!("hardware.json failed to compile: {:?}", e))?;

        let schema = self
            .schemata
            .get(schema_id)
            .ok_or(format_err!("No matching schema for version: {:?}", input["version"]))?;
        let compiled_schema = scope
            .compile_and_return(schema.to_owned(), /*ban_unknown=*/ true)
            .map_err(|e| format_err!(format!("Couldn't parse schema '{}': {:?}", schema_id, e)))?;
        let validation = compiled_schema.validate(&input);
        if !validation.is_strictly_valid() {
            let mut errors = Vec::new();
            for error in &validation.errors {
                errors.push(
                    format!("\n    {} at {}", error.get_title(), error.get_path()).into_boxed_str(),
                );
            }
            for missing in &validation.missing {
                errors.push(
                    format!("\n    schema definition is missing URL {}", missing).into_boxed_str(),
                );
            }
            errors.sort_unstable();
            bail!("{} {}", schema_id, errors.join(""));
        }

        // Create a new FMS Entry.
        let entry: Entry = match schema_id {
            "http://fuchsia.com/schemas/sdk/physical_device.json" => {
                Entry::Physical(from_value::<PhysicalDeviceSpec>(input["data"].to_owned())?)
            }
            "http://fuchsia.com/schemas/sdk/product_bundle-02.json" => {
                Entry::Product(from_value::<ProductBundle>(input["data"].to_owned())?)
            }
            _ => bail!("No matching struct for: {:?}", input["version"]),
        };

        // Store the new Entry using the entry's name as a key.
        let key = input["data"]["name"].as_str().expect("need name for FMS Entry");
        self.data.insert(key.to_string(), entry);
        Ok(())
    }
/// Add metadata from json text to the store of FMS entries.
///
/// If the an entry exists with a given name already exists, the entry will
/// be overwritten with the new metadata.
Add metadata from json text to the store of FMS entries.
If the an entry exists with a given name already exists, the entry will
be overwritten with the new metadata.
Add metadata from json text to the store of FMS entries . If the an entry exists with a given name already exists the entry will be overwritten with the new metadata .
pub fn add_json<R>(&mut self, reader: &mut R) -> Result<()>
    where
        R: io::Read,
    {
        let input: Value = from_reader(reader)?;
        // Which schema should this follow.
        let schema_id: &str =
            input["version"].as_str().ok_or(format_err!("Missing version string"))?;
        // Validate the input against the schema.
        let mut scope = json_schema::Scope::new();
        let common_schema = from_str(include_str!("../../../../../../build/sdk/meta/common.json"))?;
        scope
            .compile(common_schema, /*ban_unknown=*/ true)
            .map_err(|e| format_err!("common.json failed to compile: {:?}", e))?;
        let common_schema =
            from_str(include_str!("../../../../../../build/sdk/meta/emu_manifest.json"))?;
        scope
            .compile(common_schema, /*ban_unknown=*/ true)
            .map_err(|e| format_err!("emu_manifest.json failed to compile: {:?}", e))?;
        let common_schema =
            from_str(include_str!("../../../../../../build/sdk/meta/flash_manifest-02.json"))?;
        scope
            .compile(common_schema, /*ban_unknown=*/ true)
            .map_err(|e| format_err!("flash_manifest-02.json failed to compile: {:?}", e))?;
        let common_schema =
            from_str(include_str!("../../../../../../build/sdk/meta/hardware.json"))?;
        scope
            .compile(common_schema, /*ban_unknown=*/ true)
            .map_err(|e| format_err!("hardware.json failed to compile: {:?}", e))?;
        let schema = self
            .schemata
            .get(schema_id)
            .ok_or(format_err!("No matching schema for version: {:?}", input["version"]))?;
        let compiled_schema = scope
            .compile_and_return(schema.to_owned(), /*ban_unknown=*/ true)
            .map_err(|e| format_err!(format!("Couldn't parse schema '{}': {:?}", schema_id, e)))?;
        let validation = compiled_schema.validate(&input);
        if !validation.is_strictly_valid() {
            let mut errors = Vec::new();
            for error in &validation.errors {
                errors.push(
                    format!("\n    {} at {}", error.get_title(), error.get_path()).into_boxed_str(),
                );
            }
            for missing in &validation.missing {
                errors.push(
                    format!("\n    schema definition is missing URL {}", missing).into_boxed_str(),
                );
            }
            errors.sort_unstable();
            bail!("{} {}", schema_id, errors.join(""));
        }
        // Create a new FMS Entry.
        let entry: Entry = match schema_id {
            "http://fuchsia.com/schemas/sdk/physical_device.json" => {
                Entry::Physical(from_value::<PhysicalDeviceSpec>(input["data"].to_owned())?)
            }
            "http://fuchsia.com/schemas/sdk/product_bundle-02.json" => {
                Entry::Product(from_value::<ProductBundle>(input["data"].to_owned())?)
            }
            _ => bail!("No matching struct for: {:?}", input["version"]),
        };
        // Store the new Entry using the entry's name as a key.
        let key = input["data"]["name"].as_str().expect("need name for FMS Entry");
        self.data.insert(key.to_string(), entry);
        Ok(())
    }
pub fn add_json < R > ( & mut self , reader : & mut R ) -> Result < ( ) > where R : io :: Read , { let input : Value = from_reader ( reader ) ? ; // Which schema should this follow. let schema_id : & str = input [ " " ] . as_str ( ) . ok_or ( format_err ! ( " " ) ) ? ; // Validate the input against the schema. let mut scope = json_schema :: Scope :: new ( ) ; let common_schema = from_str ( include_str ! ( " " ) ) ? ; scope . compile ( common_schema , /*ban_unknown=*/ true ) . map_err ( | e | format_err ! ( " " e ) ) ? ; let common_schema = from_str ( include_str ! ( " " ) ) ? ; scope . compile ( common_schema , /*ban_unknown=*/ true ) . map_err ( | e | format_err ! ( " " e ) ) ? ; let common_schema = from_str ( include_str ! ( " " ) ) ? ; scope . compile ( common_schema , /*ban_unknown=*/ true ) . map_err ( | e | format_err ! ( " " e ) ) ? ; let common_schema = from_str ( include_str ! ( " " ) ) ? ; scope . compile ( common_schema , /*ban_unknown=*/ true ) . map_err ( | e | format_err ! ( " " e ) ) ? ; let schema = self . schemata . get ( schema_id ) . ok_or ( format_err ! ( " " input [ " " ] ) ) ? ; let compiled_schema = scope . compile_and_return ( schema . to_owned ( ) , /*ban_unknown=*/ true ) . map_err ( | e | format_err ! ( format ( " " schema_id e ) ) ) ? ; let validation = compiled_schema . validate ( & input ) ; if ! validation . is_strictly_valid ( ) { let mut errors = Vec :: new ( ) ; for error in & validation . errors { errors . push ( format ! ( " \n " error get_title ( ) error get_path ( ) ) . into_boxed_str ( ) , ) ; } for missing in & validation . missing { errors . push ( format ! ( " \n " missing ) . into_boxed_str ( ) , ) ; } errors . sort_unstable ( ) ; bail ! ( " " schema_id errors join ( " " ) ) ; } // Create a new FMS Entry. let entry : Entry = match schema_id { " " => { Entry :: Physical ( from_value :: < PhysicalDeviceSpec > ( input [ " " ] . to_owned ( ) ) ? ) } " " => { Entry :: Product ( from_value :: < ProductBundle > ( input [ " " ] . to_owned ( ) ) ? ) } _ => bail ! ( " " input [ " " ] ) , } ; // Store the new Entry using the entry's name as a key. let key = input [ " " ] [ " " ] . as_str ( ) . expect ( " " ) ; self . data . insert ( key . to_string ( ) , entry ) ; Ok ( ( ) ) }
Add metadata from json text to the store of FMS entries.
Add metadata from json text to the store of FMS entries .
&mut self
reader
&mut R
&mut self
reader
&mut R