use crate::{BinaryReader, FromReader, Result, SectionLimited};
pub type ExportSectionReader<'a> = SectionLimited<'a, Export<'a>>;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ExternalKind {
Func,
Table,
Memory,
Global,
Tag,
FuncExact,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Export<'a> {
pub name: &'a str,
pub kind: ExternalKind,
pub index: u32,
}
impl<'a> FromReader<'a> for Export<'a> {
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
Ok(Export {
name: reader.read_string()?,
kind: match reader.read()? {
ExternalKind::FuncExact => {
bail!(
reader.original_position(),
"Exact type is not allowed in the exports",
);
}
x => x,
},
index: reader.read_var_u32()?,
})
}
}
impl<'a> FromReader<'a> for ExternalKind {
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
let offset = reader.original_position();
let byte = reader.read_u8()?;
BinaryReader::external_kind_from_byte(byte, offset)
}
}