rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.73k stars 175 forks source link

serial bug #672

Closed zhuchuanjing closed 1 year ago

zhuchuanjing commented 1 year ago

let mut x = rhai::Map::new(); x.insert("a".into(), Dynamic::from_blob(vec![1, 2, 3, 5, 6])); println!("{:?}", x.get("a").map(|v| v.type_name())); let mut buf = Vec::new(); x.serialize(&mut Serializer::new(&mut buf)); let y = rmp_serde::from_slice::(&buf).unwrap(); println!("{:?}", y.get("a").map(|v| v.type_name()));

this blob will be change to array!

schungx commented 1 year ago

This should have you covered: https://rhai.rs/book/rust/serde.html#admonition-tip-working-with-blobs

schungx commented 1 year ago

However, I find that the current handling of serialize_bytes and deserialize_bytes is not optimal. Theoretically, you may be able to use a serializable format that can handle byte arrays, such as MessagePack.

I'll fix it up a bit and test it with rmp-serde.

zhuchuanjing commented 1 year ago

i have used msgpack,but it's won't wok

schungx commented 1 year ago

That's correct. I'll fix that. I just tested my changes with rmp-serde and it works fine.

let x = ...
let encoded = rmp_serde::to_vec(&x).unwrap();
let decoded: Dynamic = rmp_serde::from_slice(&encoded).unwrap();

I'll upload it to master in a bit for you to try out.

schungx commented 1 year ago

@zhuchuanjing you can pull from main to try it out. It should now work for serialization formats that support byte streams.

zhuchuanjing commented 1 year ago

@zhuchuanjing you can pull from main to try it out. It should now work for serialization formats that support byte streams.

thx,I have update the master branch,it's looks work fine!