mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-08 21:28:07 +00:00
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:
parent
0ade4b8cac
commit
eb73e05b7a
@ -224,7 +224,7 @@ fn extract_programs(module: &mut Module) -> Vec<shared::Program> {
|
|||||||
((payload[3] as usize) << 24);
|
((payload[3] as usize) << 24);
|
||||||
let (a, b) = payload[4..].split_at(len as usize);
|
let (a, b) = payload[4..].split_at(len as usize);
|
||||||
payload = b;
|
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,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
panic!("failed to decode what looked like wasm-bindgen data: {}", 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);
|
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);
|
ret.push(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,12 @@ extern crate serde_derive;
|
|||||||
|
|
||||||
pub const SCHEMA_VERSION: &str = "2";
|
pub const SCHEMA_VERSION: &str = "2";
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct ProgramOnlySchema {
|
||||||
|
pub schema_version: String,
|
||||||
|
pub version: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct Program {
|
pub struct Program {
|
||||||
pub exports: Vec<Export>,
|
pub exports: Vec<Export>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user