Use Encoder instead of MarshalBinary.

To be more similar to the encoding/gob code.