usecrate::{BinaryReader, Result}; use core::fmt; use core::ops::Range;
/// A reader for custom sections of a WebAssembly module. #[derive(Clone)] pubstruct CustomSectionReader<'a> {
name: &'a str,
reader: BinaryReader<'a>,
}
impl<'a> CustomSectionReader<'a> { /// Constructs a new `CustomSectionReader` for the given data and offset. pubfn new(mut reader: BinaryReader<'a>) -> Result<CustomSectionReader<'a>> { let name = reader.read_string()?;
Ok(CustomSectionReader { name, reader })
}
/// The name of the custom section. pubfn name(&self) -> &'a str { self.name
}
/// The offset, relative to the start of the original module or component, /// that the `data` payload for this custom section starts at. pubfn data_offset(&self) -> usize { self.reader.original_position()
}
/// The actual contents of the custom section. pubfn data(&self) -> &'a [u8] { self.reader.remaining_buffer()
}
/// The range of bytes that specify this whole custom section (including /// both the name of this custom section and its data) specified in /// offsets relative to the start of the byte stream. pubfn range(&self) -> Range<usize> { self.reader.range()
}
/// Attempts to match and see if this custom section is statically known to /// `wasmparser` with any known section reader. /// /// This will inspect `self.name()` and return a [`KnownCustom`] if the name /// matches a known custom section where there is a parser available for it. /// This can also be used as a convenience function for creating such /// parsers. /// /// If the custom section name is not known, or if a reader could not be /// created, then `KnownCustom::Unknown` is returned. pubfn as_known(&self) -> KnownCustom<'a> { matchself.name() { "name" => KnownCustom::Name(crate::NameSectionReader::new(self.reader.shrink())), #[cfg(feature = "component-model")] "component-name" => KnownCustom::ComponentName(crate::ComponentNameSectionReader::new( self.reader.shrink(),
)), "metadata.code.branch_hint" => { matchcrate::BranchHintSectionReader::new(self.reader.shrink()) {
Ok(s) => KnownCustom::BranchHints(s),
Err(_) => KnownCustom::Unknown,
}
} "producers" => matchcrate::ProducersSectionReader::new(self.reader.shrink()) {
Ok(s) => KnownCustom::Producers(s),
Err(_) => KnownCustom::Unknown,
}, "dylink.0" => {
KnownCustom::Dylink0(crate::Dylink0SectionReader::new(self.reader.shrink()))
} "core" => matchcrate::CoreDumpSection::new(self.reader.shrink()) {
Ok(s) => KnownCustom::CoreDump(s),
Err(_) => KnownCustom::Unknown,
}, "coremodules" => matchcrate::CoreDumpModulesSection::new(self.reader.shrink()) {
Ok(s) => KnownCustom::CoreDumpModules(s),
Err(_) => KnownCustom::Unknown,
}, "coreinstances" => matchcrate::CoreDumpInstancesSection::new(self.reader.shrink()) {
Ok(s) => KnownCustom::CoreDumpInstances(s),
Err(_) => KnownCustom::Unknown,
}, "corestack" => matchcrate::CoreDumpStackSection::new(self.reader.shrink()) {
Ok(s) => KnownCustom::CoreDumpStack(s),
Err(_) => KnownCustom::Unknown,
}, "linking" => matchcrate::LinkingSectionReader::new(self.reader.shrink()) {
Ok(s) => KnownCustom::Linking(s),
Err(_) => KnownCustom::Unknown,
},
s if s.starts_with("reloc.") => { matchcrate::RelocSectionReader::new(self.reader.shrink()) {
Ok(s) => KnownCustom::Reloc(s),
Err(_) => KnownCustom::Unknown,
}
}
_ => KnownCustom::Unknown,
}
}
}
/// Return value of [`CustomSectionReader::as_known`]. /// /// Note that this is `#[non_exhaustive]` because depending on crate features /// this enumeration will different entries. #[allow(missing_docs)] #[non_exhaustive] pubenum KnownCustom<'a> {
Name(crate::NameSectionReader<'a>), #[cfg(feature = "component-model")]
ComponentName(crate::ComponentNameSectionReader<'a>),
BranchHints(crate::BranchHintSectionReader<'a>),
Producers(crate::ProducersSectionReader<'a>),
Dylink0(crate::Dylink0SectionReader<'a>),
CoreDump(crate::CoreDumpSection<'a>),
CoreDumpStack(crate::CoreDumpStackSection<'a>),
CoreDumpInstances(crate::CoreDumpInstancesSection),
CoreDumpModules(crate::CoreDumpModulesSection<'a>),
Linking(crate::LinkingSectionReader<'a>),
Reloc(crate::RelocSectionReader<'a>),
Unknown,
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.