简体   繁体   中英

gob decoder attempting to decode into a non-pointer

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM