parity-wasm/src/elements/section.rs

24 lines
632 B
Rust
Raw Normal View History

2017-03-29 18:16:58 +03:00
use std::io;
use super::{Deserialize, Unparsed, Error, VarUint7};
pub struct Section {
id: u8,
unparsed: Unparsed,
}
impl Deserialize for Section {
type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
2017-03-29 19:40:51 +03:00
let id = match VarUint7::deserialize(reader) {
// todo: be more selective detecting no more section
Err(_) => { return Err(Error::UnexpectedEof); },
Ok(id) => id,
};
2017-03-29 18:16:58 +03:00
let unparsed = Unparsed::deserialize(reader)?;
Ok(Section {
id: id.0,
unparsed: unparsed,
})
}
}