128-bit packed serialization

This commit is contained in:
NikVolf
2017-04-03 15:03:18 +03:00
parent a5fdfa57cf
commit 5adcae761c
3 changed files with 127 additions and 6 deletions

View File

@ -1,5 +1,7 @@
use std::io;
use std::io::Write;
use super::{
Serialize,
Deserialize,
Unparsed,
Error,
@ -15,6 +17,7 @@ use super::{
FuncBody,
ElementSegment,
DataSegment,
CountedWriter,
};
use super::types::Type;
@ -279,7 +282,7 @@ impl DataSection {
}
impl Deserialize for DataSection {
type Error = Error;
type Error = Error;
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
// todo: maybe use reader.take(section_length)
@ -289,6 +292,18 @@ impl Deserialize for DataSection {
}
}
impl Serialize for DataSection {
type Error = Error;
fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
let mut counted_writer = CountedWriter::new(writer);
let test = vec![0u8; 12];
counted_writer.write(&test[..])?;
counted_writer.done()?;
Ok(())
}
}
#[cfg(test)]
mod tests {