wasmparser_nostd/readers/core/
tables.rs

1/* Copyright 2018 Mozilla Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16use crate::{BinaryReader, FromReader, Result, SectionLimited, TableType};
17
18/// A reader for the table section of a WebAssembly module.
19pub type TableSectionReader<'a> = SectionLimited<'a, TableType>;
20
21impl<'a> FromReader<'a> for TableType {
22    fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
23        let element_type = reader.read()?;
24        let has_max = match reader.read_u8()? {
25            0x00 => false,
26            0x01 => true,
27            _ => {
28                bail!(
29                    reader.original_position() - 1,
30                    "invalid table resizable limits flags",
31                )
32            }
33        };
34        let initial = reader.read()?;
35        let maximum = if has_max { Some(reader.read()?) } else { None };
36        Ok(TableType {
37            element_type,
38            initial,
39            maximum,
40        })
41    }
42}