mirror of
https://github.com/fluencelabs/marine.git
synced 2025-06-22 11:11:37 +00:00
feat!: decouple wasmer from Marine, replace it with generic backend interface (#219)
This commit is contained in:
24
crates/wasm-backend-traits/src/impl_utils.rs
Normal file
24
crates/wasm-backend-traits/src/impl_utils.rs
Normal file
@ -0,0 +1,24 @@
|
||||
pub use multimap::MultiMap;
|
||||
|
||||
pub fn custom_sections(bytes: &[u8]) -> Result<MultiMap<String, Vec<u8>>, String> {
|
||||
use wasmparser::Parser;
|
||||
use wasmparser::Payload;
|
||||
|
||||
Parser::new(0)
|
||||
.parse_all(bytes)
|
||||
.filter_map(|payload| {
|
||||
let payload = match payload {
|
||||
Ok(payload) => payload,
|
||||
Err(e) => return Some(Err(e.to_string())),
|
||||
};
|
||||
match payload {
|
||||
Payload::CustomSection(reader) => {
|
||||
let name = reader.name().to_string();
|
||||
let data = reader.data().to_vec();
|
||||
Some(Ok((name, data)))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
Reference in New Issue
Block a user