aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBastien Gysler <basgys@gmail.com>2017-05-09 20:51:20 +0800
committerVictor Quinn <mail@victorquinn.com>2017-05-09 20:51:20 +0800
commit3868940cdd7294e8db0acf28108a9ace9ff7a36d (patch)
tree686e05bba7d57a9e5807e41eccc69e45f22daaf7
parent3526cd0bdb7f64e1178943b7dee81a0cc3d86a69 (diff)
downloaddexon-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.go2
-rw-r--r--decimal_test.go5
2 files changed, 6 insertions, 1 deletions
diff --git a/decimal.go b/decimal.go
index 2caf597..5fcb628 100644
--- a/decimal.go
+++ b/decimal.go
@@ -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)
+ }
}
}