MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / parse_module_bytes

Method parse_module_bytes

crates/parser/src/lib.rs:189–212  ·  view source on GitHub ↗

Parse a [`Module`] from bytes

(&self, wasm: impl AsRef<[u8]>)

Source from the content-addressed store, hash-verified

187
188 /// Parse a [`Module`] from bytes
189 pub fn parse_module_bytes(&self, wasm: impl AsRef<[u8]>) -> Result<Module> {
190 let wasm = wasm.as_ref();
191 let mut validator = Self::create_validator(self.options.clone());
192 let mut reader = ModuleReader::default();
193
194 for payload in wasmparser::Parser::new(0).parse_all(wasm) {
195 match payload? {
196 wasmparser::Payload::CodeSectionStart { count, range, size } => {
197 reader.begin_code_section(count, range, size, &mut validator, &self.options)?;
198 }
199 wasmparser::Payload::CodeSectionEntry(function) => {
200 reader.process_borrowed_code_section_entry(function, &mut validator, &self.options)?;
201 }
202 payload => reader.process_payload(payload, &mut validator)?,
203 }
204 }
205
206 if !reader.end_reached {
207 return Err(ParseError::EndNotReached);
208 }
209
210 reader.process_pending_functions(&self.options)?;
211 reader.into_module(&self.options)
212 }
213
214 #[cfg(feature = "std")]
215 /// Parse a [`Module`] from a file. Requires `std` feature.

Callers 8

mainFunction · 0.80
runFunction · 0.80
parse_bytesFunction · 0.80
tinywasm_parseFunction · 0.80
fibonacci_parseFunction · 0.80
tinywasm_parseFunction · 0.80
argon2id_parseFunction · 0.80

Calls 6

as_refMethod · 0.80
begin_code_sectionMethod · 0.80
process_payloadMethod · 0.80
into_moduleMethod · 0.80