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

Method process_payload

crates/parser/src/module.rs:78–177  ·  view source on GitHub ↗
(&mut self, payload: Payload<'_>, validator: &mut Validator)

Source from the content-addressed store, hash-verified

76 }
77
78 pub(crate) fn process_payload(&mut self, payload: Payload<'_>, validator: &mut Validator) -> Result<()> {
79 fn check_section(section: &str, duplicate: bool) -> Result<()> {
80 debug!("found {section} section");
81 if duplicate {
82 return Err(ParseError::DuplicateSection(format!("{section} section")));
83 }
84 Ok(())
85 }
86
87 match payload {
88 Payload::Version { num, encoding, range } => {
89 validator.version(num, encoding, &range)?;
90 self.version = Some(num);
91 if let wasmparser::Encoding::Component = encoding {
92 return Err(ParseError::InvalidEncoding(encoding));
93 }
94 }
95 Payload::StartSection { func, range } => {
96 check_section("start", self.start_func.is_some())?;
97 validator.start_section(func, &range)?;
98 self.start_func = Some(func);
99 }
100 Payload::TypeSection(reader) => {
101 check_section("type", !self.func_types.is_empty())?;
102 validator.type_section(&reader)?;
103 self.func_types = reader.into_iter().map(|t| convert_module_type(t?)).collect::<Result<_>>()?;
104 }
105 Payload::GlobalSection(reader) => {
106 check_section("global", !self.globals.is_empty())?;
107 validator.global_section(&reader)?;
108 self.globals = convert_module_globals(reader)?;
109 }
110 Payload::TableSection(reader) => {
111 check_section("table", !self.table_types.is_empty())?;
112 validator.table_section(&reader)?;
113 self.table_types =
114 reader.into_iter().map(|table| convert_module_table(table?)).collect::<Result<_>>()?;
115 }
116 Payload::MemorySection(reader) => {
117 check_section("memory", !self.memory_types.is_empty())?;
118 validator.memory_section(&reader)?;
119 self.memory_types =
120 reader.into_iter().map(|memory| Ok(convert_module_memory(memory?))).collect::<Result<_>>()?;
121 }
122 Payload::ElementSection(reader) => {
123 debug!("Found element section");
124 validator.element_section(&reader)?;
125 self.elements =
126 reader.into_iter().map(|element| convert_module_element(element?)).collect::<Result<_>>()?;
127 }
128 Payload::DataSection(reader) => {
129 check_section("data", !self.data.is_empty())?;
130 validator.data_section(&reader)?;
131 self.data = reader.into_iter().map(|data| convert_module_data(data?)).collect::<Result<_>>()?;
132 }
133 Payload::DataCountSection { count, range } => {
134 debug!("Found data count section");
135 if !self.data.is_empty() {

Callers 2

parse_module_bytesMethod · 0.80
parse_module_streamMethod · 0.80

Calls 10

convert_module_typeFunction · 0.85
convert_module_globalsFunction · 0.85
convert_module_tableFunction · 0.85
convert_module_memoryFunction · 0.85
convert_module_elementFunction · 0.85
convert_module_dataFunction · 0.85
convert_module_importFunction · 0.85
convert_module_exportFunction · 0.85
mapMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected