Standard library / encoding/gob

encoding/gob.Decoder

Stateful receiver of Gob values. Matching exported struct fields can be decoded across different struct types. Do not treat its basic size checks as a defense against untrusted streams. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
type Decoder struct {  // Has unexported fields.}

Working Example

Example Snippetgo
package main
import (  "bytes"  "encoding/gob"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var buf bytes.Buffer  must(gob.NewEncoder(&buf).Encode(struct {    N     int    Label string  }{7, "new"}))  var old struct{ N int }  must(gob.NewDecoder(&buf).Decode(&old))  fmt.Println(old.N)}
Go Reference