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

Function load_module_from_bytes

crates/cli/src/load.rs:60–89  ·  view source on GitHub ↗
(input: &str, bytes: &[u8])

Source from the content-addressed store, hash-verified

58}
59
60fn load_module_from_bytes(input: &str, bytes: &[u8]) -> Result<LoadedModule> {
61 if bytes.starts_with(b"TWAS") {
62 let module = Module::try_from_twasm(bytes).with_context(|| format!("failed to read twasm input `{input}`"))?;
63 return Ok(LoadedModule { module, format: InputFormat::Twasm });
64 }
65
66 #[cfg(feature = "wat")]
67 if input != "-" && has_extension(input, "wat") {
68 let wasm = wat::parse_bytes(bytes).with_context(|| format!("failed to parse WAT input `{input}`"))?;
69 let module =
70 tinywasm::parse_bytes(&wasm).with_context(|| format!("failed to parse Wasm generated from `{input}`"))?;
71 return Ok(LoadedModule { module, format: InputFormat::Wat });
72 }
73
74 #[cfg(not(feature = "wat"))]
75 if input != "-" && has_extension(input, "wat") {
76 bail!("wat support is not enabled in this build")
77 }
78
79 #[cfg(feature = "wat")]
80 if input == "-"
81 && let Ok(wasm) = wat::parse_bytes(bytes)
82 {
83 let module = tinywasm::parse_bytes(&wasm).context("failed to parse Wasm generated from stdin WAT input")?;
84 return Ok(LoadedModule { module, format: InputFormat::Wat });
85 }
86
87 let module = tinywasm::parse_bytes(bytes).with_context(|| format!("failed to parse Wasm input `{input}`"))?;
88 Ok(LoadedModule { module, format: InputFormat::Wasm })
89}
90
91fn read_input_bytes(input: &str) -> Result<Vec<u8>> {
92 if input == "-" {

Callers 1

load_moduleFunction · 0.85

Calls 2

has_extensionFunction · 0.85
parse_bytesFunction · 0.85

Tested by

no test coverage detected