dedis / protobuf

Reflection-based Protocol Buffers for Go
GNU General Public License v2.0
76 stars 15 forks source link

Cannot encode map[[16]byte]string #52

Closed kc1212 closed 5 years ago

kc1212 commented 6 years ago

I wrote the following test in encoding_test.go:

type ArrayMapT struct {
    Dummy string
    Map   map[[16]byte]string
}

func TestArrayMap(t *testing.T) {
    m := make(map[[16]byte]string)
    m[[16]byte{0}] = "zero"
    m[[16]byte{1}] = "one"
    t0 := ArrayMapT{
        Dummy: "test",
        Map:   m,
    }
    buf, err := Encode(&t0)
    assert.Nil(t, err)

    var t1 ArrayMapT
    err = Decode(buf, &t1)
    assert.Nil(t, err)
}

But it fails at the Encode part with error "reflect.Value.Slice: slice of unaddressable array (field Map)". Is encoding go maps that uses arrays as its key supported?

ineiti commented 6 years ago

I was not even aware that we could use arrays in map-indexes ;) One thing I saw also is that map[string]otherStruct doesn't work, but map[string]*otherStruct does work.

jeffallen commented 5 years ago

This works as of commit 62ad0cc155.