globals and types

This commit is contained in:
NikVolf
2017-04-03 22:29:44 +03:00
parent b9194c8e0b
commit f5aa3de18c
5 changed files with 183 additions and 5 deletions

View File

@ -1,5 +1,5 @@
use std::io;
use super::{Deserialize, Error, VarUint7, VarUint32};
use super::{Deserialize, Serialize, Error, VarUint7, VarUint32};
pub enum Internal {
Function(u32),
@ -23,6 +23,24 @@ impl Deserialize for Internal {
}
}
impl Serialize for Internal {
type Error = Error;
fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
let (bt, arg) = match self {
Internal::Function(arg) => (0x00, arg),
Internal::Table(arg) => (0x01, arg),
Internal::Memory(arg) => (0x02, arg),
Internal::Global(arg) => (0x03, arg),
};
VarUint7::from(bt).serialize(writer)?;
VarUint32::from(arg).serialize(writer)?;
Ok(())
}
}
pub struct ExportEntry {
field_str: String,
internal: Internal,
@ -45,4 +63,14 @@ impl Deserialize for ExportEntry {
internal: internal,
})
}
}
impl Serialize for ExportEntry {
type Error = Error;
fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
self.field_str.serialize(writer)?;
self.internal.serialize(writer)?;
Ok(())
}
}