pub fn parse(input: &[u8]) -> Result<(Pool, Class)> {
    // create a new decoder from the byte array
    let mut cursor = 0;
    let mut decoder = Decoder::new(input, &mut cursor);

    // check if input is a class file
    if decoder.read_bytes(4)? != MAGIC {
        return Err(Error::NotAClass);
    }

    let minor_version = decoder.read_u16()?;
    let major_version = decoder.read_u16()?;

    let constant_pool = read_constant_pool(&mut decoder)?;

    let access_flags = AccessFlags::from_bits_truncate(decoder.read_u16()?);

    let name = decoder.read_u16()?;
    let super_name = decoder.read_u16()?;

    // Read interfaces
    let interface_count = decoder.read_u16()?;
    let mut interfaces = Vec::with_capacity(interface_count as usize);
    for _ in 0..interface_count {
        interfaces.push(decoder.read_u16()?);
    }

    let fields = parse_fields(&mut decoder, &constant_pool)?;
    let methods = parse_methods(&mut decoder, &constant_pool)?;
    let attributes = parse_attributes(&mut decoder, &constant_pool)?;

    let class = Class {
        minor_version,
        major_version,

        access_flags,
        name,
        super_name,

        interfaces,

        fields,
        methods,
        attributes,
    };

    Ok((constant_pool, class))
}
/// Parses the class file, which is represented as a byte array.
/// The constant pool and the class is returned, if no error occurred.
Parses the class file, which is represented as a byte array.
The constant pool and the class is returned, if no error occurred.
Parses the class file which is represented as a byte array . The constant pool and the class is returned if no error occurred .
pub fn parse(input: &[u8]) -> Result<(Pool, Class)> {
    // create a new decoder from the byte array
    let mut cursor = 0;
    let mut decoder = Decoder::new(input, &mut cursor);
    // check if input is a class file
    if decoder.read_bytes(4)? != MAGIC {
        return Err(Error::NotAClass);
    }
    let minor_version = decoder.read_u16()?;
    let major_version = decoder.read_u16()?;
    let constant_pool = read_constant_pool(&mut decoder)?;
    let access_flags = AccessFlags::from_bits_truncate(decoder.read_u16()?);
    let name = decoder.read_u16()?;
    let super_name = decoder.read_u16()?;
    // Read interfaces
    let interface_count = decoder.read_u16()?;
    let mut interfaces = Vec::with_capacity(interface_count as usize);
    for _ in 0..interface_count {
        interfaces.push(decoder.read_u16()?);
    }
    let fields = parse_fields(&mut decoder, &constant_pool)?;
    let methods = parse_methods(&mut decoder, &constant_pool)?;
    let attributes = parse_attributes(&mut decoder, &constant_pool)?;
    let class = Class {
        minor_version,
        major_version,
        access_flags,
        name,
        super_name,
        interfaces,
        fields,
        methods,
        attributes,
    };
    Ok((constant_pool, class))
}
pub fn parse ( input : & [ u8 ] ) -> Result < ( Pool , Class ) > { // create a new decoder from the byte array let mut cursor = 0 ; let mut decoder = Decoder :: new ( input , & mut cursor ) ; // check if input is a class file if decoder . read_bytes ( 4 ) ? != MAGIC { return Err ( Error :: NotAClass ) ; } let minor_version = decoder . read_u16 ( ) ? ; let major_version = decoder . read_u16 ( ) ? ; let constant_pool = read_constant_pool ( & mut decoder ) ? ; let access_flags = AccessFlags :: from_bits_truncate ( decoder . read_u16 ( ) ? ) ; let name = decoder . read_u16 ( ) ? ; let super_name = decoder . read_u16 ( ) ? ; // Read interfaces let interface_count = decoder . read_u16 ( ) ? ; let mut interfaces = Vec :: with_capacity ( interface_count as usize ) ; for _ in 0 .. interface_count { interfaces . push ( decoder . read_u16 ( ) ? ) ; } let fields = parse_fields ( & mut decoder , & constant_pool ) ? ; let methods = parse_methods ( & mut decoder , & constant_pool ) ? ; let attributes = parse_attributes ( & mut decoder , & constant_pool ) ? ; let class = Class { minor_version , major_version , access_flags , name , super_name , interfaces , fields , methods , attributes , } ; Ok ( ( constant_pool , class ) ) }
Parses the class file, which is represented as a byte array.
Parses the class file which is represented as a byte array .
input
&[u8]