Deserialize less to match schema versions

Currently the entire `Program` is deserialized to match schema versions but this
is likely to fail when the schema changes. Instead just deserialize the
schema/version fields, compare those, and if successful go ahead and deserialize
everything.
This commit is contained in:
Alex Crichton 2018-04-19 13:36:59 -07:00
parent 0ade4b8cac
commit eb73e05b7a
2 changed files with 13 additions and 1 deletions

View File

@ -224,7 +224,7 @@ fn extract_programs(module: &mut Module) -> Vec<shared::Program> {
((payload[3] as usize) << 24);
let (a, b) = payload[4..].split_at(len as usize);
payload = b;
let p: shared::Program = match serde_json::from_slice(&a) {
let p: shared::ProgramOnlySchema = match serde_json::from_slice(&a) {
Ok(f) => f,
Err(e) => {
panic!("failed to decode what looked like wasm-bindgen data: {}", e)
@ -255,6 +255,12 @@ to open an issue at https://github.com/alexcrichton/wasm-bindgen/issues!
",
p.version, version);
}
let p: shared::Program = match serde_json::from_slice(&a) {
Ok(f) => f,
Err(e) => {
panic!("failed to decode what looked like wasm-bindgen data: {}", e)
}
};
ret.push(p);
}

View File

@ -3,6 +3,12 @@ extern crate serde_derive;
pub const SCHEMA_VERSION: &str = "2";
#[derive(Deserialize)]
pub struct ProgramOnlySchema {
pub schema_version: String,
pub version: String,
}
#[derive(Deserialize, Serialize)]
pub struct Program {
pub exports: Vec<Export>,