mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-25 12:42:03 +00:00
globals and types
This commit is contained in:
@ -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(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user