Fix "Error converting from js 'float' into type 'i32'" error.

This commit is contained in:
Orne Brocaar 2022-09-12 12:28:23 +01:00
parent 90c5af20df
commit 331f4bce40
2 changed files with 6 additions and 4 deletions

View File

@ -170,7 +170,11 @@ pub async fn encode(
} }
} }
let v: Vec<u8> = res.get("bytes")?; // Directly into u8 can result into the following error:
// Error converting from js 'float' into type 'i32'
let v: Vec<f64> = res.get("bytes")?;
let v: Vec<u8> = v.iter().map(|v| *v as u8).collect();
Ok(v) Ok(v)
}) })
} }

View File

@ -89,9 +89,7 @@ pub async fn struct_to_binary(
Ok(match codec { Ok(match codec {
Codec::NONE => Vec::new(), Codec::NONE => Vec::new(),
Codec::CAYENNE_LPP => cayenne_lpp::encode(obj).context("CayenneLpp encode")?, Codec::CAYENNE_LPP => cayenne_lpp::encode(obj).context("CayenneLpp encode")?,
Codec::JS => js::encode(f_port, variables, encoder_config, obj) Codec::JS => js::encode(f_port, variables, encoder_config, obj).await?,
.await
.context("JavaScript encoder")?,
}) })
} }