pub fn load_native(bytes: &[u8]) -> Result<NativeMappings, Error> {
    let mut cursor = Cursor::new(bytes);

    let header = read_header(&mut cursor)?;

    if !header.is_native {
        return Err(MappingsError::MismatchedHeader.into());
    }

    // Read number of mappings
    let len = cursor.read_u32::<LittleEndian>()?;

    let mut blocks = HashMap::with_capacity(len as usize);

    // Read mappings
    for _ in 0..len {
        // Read mapping
        let block_name = cursor.read_string()?;

        // Read properties
        let num_props = cursor.read_u32::<LittleEndian>()?;
        let mut props = vec![];

        for _ in 0..num_props {
            let key = cursor.read_string()?;
            let value = cursor.read_string()?;
            props.push((key, value));
        }

        let identifier = (block_name, props);
        blocks.insert(identifier, cursor.read_u16::<LittleEndian>()?);
    }

    Ok(NativeMappings {
        version: header.version,
        proto: header.proto,
        blocks,
    })
}
/// Loads a native mappings file.
Loads a native mappings file.
Loads a native mappings file .
pub fn load_native(bytes: &[u8]) -> Result<NativeMappings, Error> {
    let mut cursor = Cursor::new(bytes);
    let header = read_header(&mut cursor)?;
    if !header.is_native {
        return Err(MappingsError::MismatchedHeader.into());
    }
    // Read number of mappings
    let len = cursor.read_u32::<LittleEndian>()?;
    let mut blocks = HashMap::with_capacity(len as usize);
    // Read mappings
    for _ in 0..len {
        // Read mapping
        let block_name = cursor.read_string()?;
        // Read properties
        let num_props = cursor.read_u32::<LittleEndian>()?;
        let mut props = vec![];
        for _ in 0..num_props {
            let key = cursor.read_string()?;
            let value = cursor.read_string()?;
            props.push((key, value));
        }
        let identifier = (block_name, props);
        blocks.insert(identifier, cursor.read_u16::<LittleEndian>()?);
    }
    Ok(NativeMappings {
        version: header.version,
        proto: header.proto,
        blocks,
    })
}
pub fn load_native ( bytes : & [ u8 ] ) -> Result < NativeMappings , Error > { let mut cursor = Cursor :: new ( bytes ) ; let header = read_header ( & mut cursor ) ? ; if ! header . is_native { return Err ( MappingsError :: MismatchedHeader . into ( ) ) ; } // Read number of mappings let len = cursor . read_u32 :: < LittleEndian > ( ) ? ; let mut blocks = HashMap :: with_capacity ( len as usize ) ; // Read mappings for _ in 0 .. len { // Read mapping let block_name = cursor . read_string ( ) ? ; // Read properties let num_props = cursor . read_u32 :: < LittleEndian > ( ) ? ; let mut props = vec ! [ ] ; for _ in 0 .. num_props { let key = cursor . read_string ( ) ? ; let value = cursor . read_string ( ) ? ; props . push ( ( key , value ) ) ; } let identifier = ( block_name , props ) ; blocks . insert ( identifier , cursor . read_u16 :: < LittleEndian > ( ) ? ) ; } Ok ( NativeMappings { version : header . version , proto : header . proto , blocks , } ) }
Loads a native mappings file.
Loads a native mappings file .
bytes
&[u8]
bytes
&[u8]