-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decoding to Map
instead of Object
for data serialized using rmp_serde
rust messagepack crate
#120
Comments
The default unpack/decode method should be deserializing as objects, but if you created a Unpackr/Packr instance, you can set
|
Thanks for sharing these options both of them work. 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. function convertToJsObject(obj) {
if (obj instanceof Map) {
const jsObject = {}
obj.forEach((value, key) => {
jsObject[key] = convertToJsObject(value)
})
return jsObject
} else if (Array.isArray(obj)) {
return obj.map((item) => convertToJsObject(item))
}
return obj
} 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. |
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: