diff options
author | Bastien Gysler <basgys@gmail.com> | 2017-05-09 20:51:20 +0800 |
---|---|---|
committer | Victor Quinn <mail@victorquinn.com> | 2017-05-09 20:51:20 +0800 |
commit | 3868940cdd7294e8db0acf28108a9ace9ff7a36d (patch) | |
tree | 686e05bba7d57a9e5807e41eccc69e45f22daaf7 | |
parent | 3526cd0bdb7f64e1178943b7dee81a0cc3d86a69 (diff) | |
download | dexon-decimal-3868940cdd7294e8db0acf28108a9ace9ff7a36d.tar.gz dexon-decimal-3868940cdd7294e8db0acf28108a9ace9ff7a36d.tar.zst dexon-decimal-3868940cdd7294e8db0acf28108a9ace9ff7a36d.zip |
Fix GobDecode (#51)
This commit fixes GobDecode, which were mutating a copy of the receiver, rather than the intended pointed struct.
-rw-r--r-- | decimal.go | 2 | ||||
-rw-r--r-- | decimal_test.go | 5 |
2 files changed, 6 insertions, 1 deletions
@@ -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) } diff --git a/decimal_test.go b/decimal_test.go index bdfc27c..a0ad37c 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -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) + } } } |