3
// Copyright 2011 The Go Authors. All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
27
// Initialize the encoder and decoder. Normally enc and dec would be
28
// bound to network connections and the encoder and decoder would
29
// run in different processes.
30
var network bytes.Buffer // Stand-in for a network connection
31
enc := gob.NewEncoder(&network) // Will write to network.
32
dec := gob.NewDecoder(&network) // Will read from network.
33
// Encode (send) the value.
34
err := enc.Encode(P{3, 4, 5, "Pythagoras"})
36
log.Fatal("encode error:", err)
38
// Decode (receive) the value.
42
log.Fatal("decode error:", err)
44
fmt.Printf("%q: {%d,%d}\n", q.Name, *q.X, *q.Y)