use crate::attribute::method::MethodAttribute;
use crate::constant_pool::ConstantPool;
use crate::error::ClassFormatErr;
use crate::flags::MethodFlags;
use lvm_common::utils::cursor::ByteCursor;
#[derive(Debug, Clone)]
pub struct MethodInfo {
pub access_flags: MethodFlags,
pub name_index: u16,
pub descriptor_index: u16,
pub attributes: Vec<MethodAttribute>,
}
impl<'a> MethodInfo {
pub(crate) fn read(
constant_pool: &ConstantPool,
cursor: &mut ByteCursor<'a>,
) -> Result<Self, ClassFormatErr> {
let access_flags = MethodFlags::new(cursor.u16()?);
let name_index = cursor.u16()?;
let descriptor_index = cursor.u16()?;
let attribute_count = cursor.u16()?;
let mut attributes = Vec::with_capacity(attribute_count as usize);
for _ in 0..attribute_count {
attributes.push(MethodAttribute::read(constant_pool, cursor)?);
}
Ok(Self {
access_flags,
name_index,
descriptor_index,
attributes,
})
}
}