take limited amount from reader

This commit is contained in:
NikVolf 2018-02-15 20:30:36 +03:00
parent a178efea7e
commit 6e89dfbd9e

View File

@ -293,10 +293,13 @@ impl Deserialize for TypeSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let types: Vec<Type> = CountedList::deserialize(reader)?.into_inner(); Ok(
Ok(TypeSection(types)) TypeSection(CountedList::<Type>::deserialize(
&mut reader.by_ref().take(section_length)
)?.into_inner())
)
} }
} }
@ -355,10 +358,12 @@ impl Deserialize for ImportSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let entries: Vec<ImportEntry> = CountedList::deserialize(reader)?.into_inner();
Ok(ImportSection(entries)) Ok(ImportSection(
CountedList::<ImportEntry>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }
@ -403,11 +408,12 @@ impl Deserialize for FunctionSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let funcs: Vec<Func> = CountedList::<Func>::deserialize(reader)?
.into_inner(); Ok(FunctionSection(
Ok(FunctionSection(funcs)) CountedList::<Func>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }
@ -452,10 +458,12 @@ impl Deserialize for TableSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let entries: Vec<TableType> = CountedList::deserialize(reader)?.into_inner();
Ok(TableSection(entries)) Ok(TableSection(
CountedList::<TableType>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }
@ -500,10 +508,12 @@ impl Deserialize for MemorySection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let entries: Vec<MemoryType> = CountedList::deserialize(reader)?.into_inner();
Ok(MemorySection(entries)) Ok(MemorySection(
CountedList::<MemoryType>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }
@ -548,10 +558,12 @@ impl Deserialize for GlobalSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let entries: Vec<GlobalEntry> = CountedList::deserialize(reader)?.into_inner();
Ok(GlobalSection(entries)) Ok(GlobalSection(
CountedList::<GlobalEntry>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }
@ -596,10 +608,12 @@ impl Deserialize for ExportSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let entries: Vec<ExportEntry> = CountedList::deserialize(reader)?.into_inner();
Ok(ExportSection(entries)) Ok(ExportSection(
CountedList::<ExportEntry>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }
@ -644,10 +658,12 @@ impl Deserialize for CodeSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let entries: Vec<FuncBody> = CountedList::deserialize(reader)?.into_inner();
Ok(CodeSection(entries)) Ok(CodeSection(
CountedList::<FuncBody>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }
@ -692,10 +708,12 @@ impl Deserialize for ElementSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let entries: Vec<ElementSegment> = CountedList::deserialize(reader)?.into_inner();
Ok(ElementSection(entries)) Ok(ElementSection(
CountedList::<ElementSegment>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }
@ -740,10 +758,12 @@ impl Deserialize for DataSection {
type Error = Error; type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> { fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length) use std::io::Read;
let _section_length = VarUint32::deserialize(reader)?; let section_length = u32::from(VarUint32::deserialize(reader)?) as u64;
let entries: Vec<DataSegment> = CountedList::deserialize(reader)?.into_inner();
Ok(DataSection(entries)) Ok(DataSection(
CountedList::<DataSegment>::deserialize(&mut reader.by_ref().take(section_length))?.into_inner()
))
} }
} }