Expand description
WebAssembly binary container — parse + byte-identical write.
WASM modules are a flat sequence of sections:
magic : '\0' 'a' 's' 'm' (4 bytes)
version : u32 little-endian (4 bytes; 1 for current MVP)
sections : (section_id:u8, size:LEB128, body:[u8; size])*For round-trip byte identity we preserve every byte of the
header and every section. LEB128 size encodings vary in
width — LLVM pads them to 5 bytes so post-link patching
can adjust section sizes without shifting the rest of the
module — and WasmFile keeps the encoded form verbatim so
a parse → write_to_vec cycle reproduces the input exactly.
Section interpretation (decoding function bodies, names, types, …) lives in higher layers. The format crate only offers: where each section starts, what its id is, and a handle to its raw bytes.
Structs§
- Section
- Metadata for one section, located by byte range into the
parent
WasmFile’sbytes. Theheader_rangecovers the section id byte plus the size-LEB;body_rangecovers just the section’s payload. - Wasm
File - A parsed WASM module.
bytesis the verbatim input; thesectionslist records where each section starts and ends so callers can read or rewrite them without re-parsing.
Enums§
- Error
- Errors raised by
WasmFile::parse.
Constants§
- MAGIC
- 4-byte WASM magic.
- SECTION_
CODE - SECTION_
CUSTOM - Standard section IDs. The custom id (0) groups everything non-standard — debug info, name maps, producer metadata, …
- SECTION_
DATA - SECTION_
DATA_ COUNT - SECTION_
ELEMENT - SECTION_
EXPORT - SECTION_
FUNCTION - SECTION_
GLOBAL - SECTION_
IMPORT - SECTION_
MEMORY - SECTION_
START - SECTION_
TABLE - SECTION_
TYPE