-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
integer keys / Map encoding #63
Comments
I’m a bit lost, and if you would like to send a PR it would be fantastic.
Il giorno ven 16 feb 2018 alle 17:04 Ad34 <[email protected]> ha
scritto:
… In JSON and javascript , map keys have to be strings, but in MessagePack
keys can be numbers.
Is there a way to force keys in a javascript object to be numbers when
msgpack encoding is done?
javascript Map allows to use numbers as keys, but looks like objects
encoded from a map cannot be de decoded :
let mapExemple = new Map()
mapExemple.set(1,"map")
mapExemple.set(3,"test")
let mpackedEx = msgpack.encode(mapExemple)
console.log(msgPackDecode(mpackedEx))
{}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#63>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADL4-aJg3hwe-nxLvQsP2Zzrl56h-k1ks5tVacSgaJpZM4SIjHX>
.
|
I will try to write a working encoder and let you know , right now I cannot use msgpack.encode on a javascript Map object |
I wrote an ext encoder and decoder for this:
However, native support for |
This seems something we should provide. Would you like to send a PR to address this? Maybe a default encoder that we ship within this module. |
I'd be happy to open a PR with this feature as a native encoder - it would just be a bit of finnagling to remember what standard ES is 😄 If I was to do that, however, I have a few questions as it's your library:
|
Can we register this as a separate encoded type? |
We absolutely could - but it would bring it inconsistencies with the Do you mean registering it as a default I went ahead and threw the code together (using newer node features, so definitely not ready for any sort of merge) along with some tests showing off the weirdness of |
I mean having an |
There was another issue ( #10 ) which asked about having custom implementations of standard types. Perhaps something like that? Though I suppose it'd need to be benchmarked.. However, an |
By the way:
But:
So it's a bad idea, mixing ES6 Maps and object-based hashes. |
In JSON and javascript , map keys have to be strings, but in MessagePack keys can be numbers.
Is there a way to force keys in a javascript object to be numbers when msgpack encoding is done?
javascript Map allows to use numbers as keys, but looks like objects encoded from a map cannot be de decoded :
let mapExemple = new Map()
mapExemple.set(1,"map")
mapExemple.set(3,"test")
let mpackedEx = msgpack.encode(mapExemple)
console.log(msgPackDecode(mpackedEx))
The text was updated successfully, but these errors were encountered: