Closed zhuchuanjing closed 1 year ago
This should have you covered: https://rhai.rs/book/rust/serde.html#admonition-tip-working-with-blobs
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
.
i have used msgpack,but it's won't wok
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.
@zhuchuanjing you can pull from main
to try it out. It should now work for serialization formats that support byte streams.
@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!
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!