gob解码器尝试解码为非指针

In my Go program I am encoding []byte data with gob

buf := new(bytes.Buffer)
    enc := gob.NewEncoder(buf)
        //data is []byte
        buf.Reset()
        enc.Encode(data)

but getting 'gob decoder attempting to decode into a non-pointer' when I am trying to decoded

buf := new(bytes.Buffer)
    d := gob.NewDecoder(buf)
        d.Decode(data)
        log.Printf("%s", d)

Gob requires you to pass a pointer to decode.

In your case, you would do:

    d.Decode(&data)

reason being, it may have to modify the slice (ie: to make it bigger, to fit the decoded array)