-
Notifications
You must be signed in to change notification settings - Fork 78
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
Empty slices round-trip as nil #275
Comments
Thanks! A similar problem was noticed a while ago regarding byte slices: #209 (comment) This is probably a rather simple change: we need to initialize slices differently (on decoding). Note to myself: Investigate if this is relevant for https:/tendermint/go-amino/milestone/1 |
Actually, given this protobuf message: message IntSlice {
repeated int64 Slice = 1;
} and this test: func TestEmptySlicesCompat(t *testing.T) {
var slin, slout p3.IntSlice
// Make an empty proto3 slice:
slin.Slice = []int64{}
pb, err := proto.Marshal(&slin)
require.NoError(t, err)
err = proto.Unmarshal(pb, &slout)
require.NoError(t, err)
assert.Equal(t, slin, slout)
} reveals that this is exactly the same behaviour as protobuf:
In other words: gogoproto, given an encoded The only difference here is that the byte encoding differs but not semantically (amino returns |
Description
I'm using go-amino as the codec in the cosmos-sdk. I expect that when a zero-length slice
is marshalled then unmarshalled, it would be returned as a zero-length slice (just as
encoding/json
does).However, what amino actually returns is a
nil
slice.Running the test program
The below program shows this output:
As you see, JSON roundtrips, but Amino does not.
Test program sources
Here is
amino-empty-slice-roundtrip.go
:Thanks for any help you can offer.
The text was updated successfully, but these errors were encountered: