Standard library / encoding/gob

encoding/gob.NewDecoder()

Create a decoder for a Gob stream. It consumes type descriptions and values; decoding hostile input is not a hardened parsing boundary. Expected stdout: '42\n'.

Formal Syntax & Structure

go syntaxgo
func NewDecoder(r io.Reader) *Decoder

Parameters & Attributes

NameTypeDescription
rio.ReaderReader supplying encoded data.

Return Value

*Decoder

New Gob decoder.

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(42))  var n int  must(gob.NewDecoder(&buf).Decode(&n))  fmt.Println(n)}
Go Reference