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
Can encode a map[int][whatever type], but cannot decode into the any type. Get invalid code=1 decoding string/bytes length, only in v5, works in v4
#372
Was doing some decoding on a weird message that requires using any. Ran into an issue where I was able to encode the message but not decode it. Tracking it down, I was able to isolate it into code that I have running on the go playground:
This will work if you decode to a non-any type (such as Msg). So it is some type of interaction there on the encoder or decoder. It will also work if you change the key type to a non-integer type, like map[string]string.
If you decode into a concrete type, then this works as expected.
Expected Behavior
If you switch to v4 instead, you can see the correct behavior.
Current Behavior
It returns an error: invalid code=1 decoding string/bytes length
Possible Solution
I'm sure there is something in the decoder that isn't reflecting right or something in the encoder not encoding correctly.
Trying to test an encoding on some msgpack being sent on a net.Conn .
The text was updated successfully, but these errors were encountered:
element-of-surprise
changed the title
Can encode a struct{map[int]Struct}, but cannot decode. Get invalid code=1 decoding string/bytes length, only in v5, works in v4
Can encode a map[int][whatever type], but cannot decode in the any type. Get invalid code=1 decoding string/bytes length, only in v5, works in v4
Apr 21, 2024
element-of-surprise
changed the title
Can encode a map[int][whatever type], but cannot decode in the any type. Get invalid code=1 decoding string/bytes length, only in v5, works in v4
Can encode a map[int][whatever type], but cannot decode into the any type. Get invalid code=1 decoding string/bytes length, only in v5, works in v4
Apr 21, 2024
Was doing some decoding on a weird message that requires using
any
. Ran into an issue where I was able to encode the message but not decode it. Tracking it down, I was able to isolate it into code that I have running on the go playground:https://go.dev/play/p/GbriQkE8RqN
I've then been able to isolate it further:
https://go.dev/play/p/FAhH3EckyEi
The essence is, if you encode:
You cannot decode out to the
any
type:This results in:
panic: msgpack: invalid code=1 decoding string/bytes length
This will work if you decode to a non-
any
type (such asMsg
). So it is some type of interaction there on the encoder or decoder. It will also work if you change the key type to a non-integer type, likemap[string]string
.If you decode into a concrete type, then this works as expected.
Expected Behavior
If you switch to v4 instead, you can see the correct behavior.
Current Behavior
It returns an error: invalid code=1 decoding string/bytes length
Possible Solution
I'm sure there is something in the decoder that isn't reflecting right or something in the encoder not encoding correctly.
Steps to Reproduce
https://go.dev/play/p/FAhH3EckyEi
Context (Environment)
Trying to test an encoding on some msgpack being sent on a net.Conn .
The text was updated successfully, but these errors were encountered: