Skip to content
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

Unable to serialise maps and UInt8Arrays at the same time #122

Open
redhog opened this issue Oct 18, 2023 · 3 comments
Open

Unable to serialise maps and UInt8Arrays at the same time #122

redhog opened this issue Oct 18, 2023 · 3 comments

Comments

@redhog
Copy link

redhog commented Oct 18, 2023

> a = new Map()
Map(0) {size: 0}
> a.set("test", 123);
Map(1) {'test' => 123}
> msgpack.decode(msgpack.encode(a))
{}
> msgpack.decode(msgpack.encode(a, {codec: msgpack.createCodec({usemap: true})}))
{test: 123}
> msgpack.decode(msgpack.encode(enc.encode("test")))
Uint8Array(4) [116, 101, 115, 116, buffer: ArrayBuffer(4), byteLength: 4, byteOffset: 0, length: 4, Symbol(Symbol.toStringTag): 'Uint8Array']
> msgpack.decode(msgpack.encode(enc.encode("test"), {codec: msgpack.createCodec({usemap: true})}))
{0: 116, 1: 101, 2: 115, 3: 116}

The last output is wrong. Note that deserialisation is without usemap in all examples; the issue is only at the serialization side (where, ideally, you'd not have to specify usemap at all, there is no reason you can't automatically detect that an object is a Map object just like you detect that it's a UInt8Array and handle it specially).

@redhog
Copy link
Author

redhog commented Oct 18, 2023

I'm using version 0.1.26 btw

@agam-gupta
Copy link

agam-gupta commented Jan 24, 2024

I'm also facing the same issue. Though, this is happening only if i use webpack5 to build my webapp.
It works fine when I use webpack3. Not sure about the reason yet.

Did you find a solution for it?

@redhog
Copy link
Author

redhog commented Jan 29, 2024

Nope, just worked around the issue (accepted that keys are garbled and recurse over object and ungarble them; all of mine are byte arrays, so the string representation of them are deterministic and the mapping reversable). But far from ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants