Merge pull request #172 from paritytech/func-serde

Dedicated serialize/deserialze for Func struct
This commit is contained in:
Nikolay Volf 2018-02-14 18:55:26 +03:00 committed by GitHub
commit 51b44ecf34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -23,6 +23,22 @@ impl Func {
}
}
impl Serialize for Func {
type Error = Error;
fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
VarUint32::from(self.0).serialize(writer)
}
}
impl Deserialize for Func {
type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
Ok(Func(VarUint32::deserialize(reader)?.into()))
}
}
/// Local definition inside the function body.
#[derive(Debug, Copy, Clone)]
pub struct Local {

View File

@ -398,11 +398,8 @@ impl Deserialize for FunctionSection {
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length)
let _section_length = VarUint32::deserialize(reader)?;
let funcs: Vec<Func> = CountedList::<VarUint32>::deserialize(reader)?
.into_inner()
.into_iter()
.map(|f| Func::new(f.into()))
.collect();
let funcs: Vec<Func> = CountedList::<Func>::deserialize(reader)?
.into_inner();
Ok(FunctionSection(funcs))
}
}