-1

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)
irom
  • 3,316
  • 14
  • 54
  • 86

1 Answers1

2

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)

David Budworth
  • 11,248
  • 1
  • 36
  • 45