Golang encoding/gob.Decoder.Decode() function example

package encoding/gob

Decode reads the next value from the input stream and stores it in the data represented by the empty interface value. If e (1st parameter) is nil, the value will be discarded. Otherwise, the value underlying e must be a pointer to the correct type for the next data item received. If the input is at EOF, Decode returns io.EOF and does not modify e.

Golang encoding/gob.Decoder.Decode() function usage example

  type Item struct {
 Data interface{}
 Name string
  }

  func decode_gob(data []byte, output *Item) error {
 buffer := bytes.NewBuffer(data)
 decoder := gob.NewDecoder(buffer)  
 return decoder.Decode(&output)  // <-- here
  }

Reference :

http://golang.org/pkg/encoding/gob/#Decoder.Decode

Advertisement