Fix GobDecode (#51)

This commit fixes GobDecode, which were mutating a copy of the receiver, rather than the intended pointed struct.
This commit is contained in:
Bastien Gysler 2017-05-09 14:51:20 +02:00 committed by Victor Quinn
parent 3526cd0bdb
commit 3868940cdd
2 changed files with 6 additions and 1 deletions

View file

@ -697,7 +697,7 @@ func (d Decimal) GobEncode() ([]byte, error) {
}
// GobDecode implements the gob.GobDecoder interface for gob serialization.
func (d Decimal) GobDecode(data []byte) error {
func (d *Decimal) GobDecode(data []byte) error {
return d.UnmarshalBinary(data)
}

View file

@ -1637,5 +1637,10 @@ func TestGobEncode(t *testing.T) {
if eq != true {
t.Errorf("Encoding then decoding mutated Decimal")
}
eq = d1.Equal(d3)
if eq != true {
t.Errorf("Error gobencoding/decoding %v, got %v", d1, d3)
}
}
}