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