You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm sending data from a rust server to a js client. The rust side is using rmp_serde a messagepack crate. And on the JS side is msgpackr. Sending across an object like this gives.
#[derive(Serialize,Deserialize,Debug)]structPerson{name:String,best_friend:Option<Box<Person>>,age:usize,address:Vec<String>,}// Convert bob to bytes and send itlet data_bob = to_vec_named(&bob).expect("Serialization failed");
This map has to explicitly be converted into a JS object. Ideally the output should be as below. When doing both encoding and decoding using msgpackr outputs a JS object, as is expected.
The default unpack/decode method should be deserializing as objects, but if you created a Unpackr/Packr instance, you can set useRecords: false or mapsAsObjects: true:
const packr = new Packr({ useRecords: false });
unpackr.decode(data);
Thanks for sharing these options both of them work. useRecords: false and mapsAsObjects: true.
I was trying to do something similar by explicitly creating objects like this below. Do these options do something more efficient? I'm asking because this step will be part in the hot path of the api logic and the most CPU efficient solution will be preferable.
It's also a bit weird that packing and unpacking with msgpackr decodes it to objects just fine. But packing with rmp_serde makes it behave differently.
kravetsone
added a commit
to kravetsone/elysia-msgpack
that referenced
this issue
Jun 24, 2024
I'm sending data from a rust server to a js client. The rust side is using
rmp_serde
a messagepack crate. And on the JS side is msgpackr. Sending across an object like this gives.This map has to explicitly be converted into a JS object. Ideally the output should be as below. When doing both encoding and decoding using msgpackr outputs a JS object, as is expected.
Is there some data/configuration missing on either side for messagepack style ser/de? Am I missing something here?
The text was updated successfully, but these errors were encountered: