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

Error: The type of key must be string or number but object is thrown when decoding a object with null as key #164

Closed
ZumiKua opened this issue Mar 18, 2021 · 1 comment

Comments

@ZumiKua
Copy link

ZumiKua commented Mar 18, 2021

const b = Buffer.from("gaRkYXRhgaRzaG9wgqdhbGNoZW15gqltYXhfY291bnRGqmV4ZWNfY291bnQAr3JlY292ZXJfc3RhbWluYYbAAaVjb3VudB6pbWF4X2NvdW50HqpleGVjX2NvdW50AKhyZWNvdmVyeXikY29zdCg=", "base64");
msgpack5 = require("msgpack5");
console.log(msgpack5().decode(b));
msgpack = require("@msgpack/msgpack");
console.log(msgpack.decode(b));

with the above code, msgpack5 can successfully decode the content but msgpack throws Error: The type of key must be string or number but object

The version of msgpack I'm using is 2.4.1, Node version is v10.14.2

The json version of the message is:

{
    "data":{
        "shop":{
            "alchemy":{
                "max_count":70,
                "exec_count":0
            },
            "recover_stamina":{
                "":1,
                "count":30,
                "max_count":30,
                "exec_count":0,
                "recovery":120,
                "cost":40
            }
        }
    }
}

It seems that this is caused by an empty string key.

According to this link, an empty string is a valid json key, I think this applied to Msgpack as well?

@ZumiKua ZumiKua changed the title Error: The type of key must be string or number but object is thrown when decoding a valid content. Error: The type of key must be string or number but object is thrown when decoding a object with empty string key Mar 18, 2021
@ZumiKua ZumiKua changed the title Error: The type of key must be string or number but object is thrown when decoding a object with empty string key Error: The type of key must be string or number but object is thrown when decoding a object with null as key Mar 18, 2021
@ZumiKua
Copy link
Author

ZumiKua commented Mar 18, 2021

Sorry, my bad, the actual message is something like

{ shop:
   { alchemy: { max_count: 70, exec_count: 0 },
     recover_stamina:
      { null: 1,
        count: 30,
        max_count: 30,
        exec_count: 0,
        recovery: 120,
        cost: 40 } } }

the key here is null, which is not supported as the exception stated.

@ZumiKua ZumiKua closed this as completed Mar 18, 2021
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

1 participant