encoding/gob: handle encoding of different indirects of GobEncoder

Fixes issue 4647.

R=r, golang-dev
CC=golang-dev
https://codereview.appspot.com/7085051

Committer: Andrew Gerrand <adg@golang.org>