mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-05-23 12:41:34 +00:00
Merge pull request #172 from paritytech/func-serde
Dedicated serialize/deserialze for Func struct
This commit is contained in:
commit
51b44ecf34
@ -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 {
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user