diff --git a/cassandra_test.go b/cassandra_test.go index 03d70c604..08596ce41 100644 --- a/cassandra_test.go +++ b/cassandra_test.go @@ -7,9 +7,9 @@ package gocql import ( "bytes" "flag" - "math/big" "reflect" "sort" + "speter.net/go/exp/math/dec/inf" "strings" "sync" "testing" @@ -303,7 +303,7 @@ type Page struct { Views int64 Protected bool Modified time.Time - Rating *big.Rat + Rating *inf.Dec Tags []string Attachments map[string]Attachment } @@ -315,7 +315,7 @@ var pageTestData = []*Page{ Title: "Frontpage", RevId: TimeUUID(), Body: "Welcome to this wiki page!", - Rating: big.NewRat(871298379, 243), + Rating: inf.NewDec(871298379, 243), Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC), Tags: []string{"start", "important", "test"}, Attachments: map[string]Attachment{ diff --git a/marshal.go b/marshal.go index ffe4a0a21..23fc65caa 100644 --- a/marshal.go +++ b/marshal.go @@ -693,6 +693,9 @@ func marshalDecimal(info *TypeInfo, value interface{}) ([]byte, error) { } unscaled := v.UnscaledBig().Bytes() + if len(unscaled) == 0 { + unscaled = []byte{0} + } scale := v.Scale() buf := make([]byte, 4+len(unscaled)) binary.BigEndian.PutUint32(buf, uint32(scale)) diff --git a/marshal_test.go b/marshal_test.go index c239f9d4a..d7c8a224b 100644 --- a/marshal_test.go +++ b/marshal_test.go @@ -126,7 +126,7 @@ var marshalTests = []struct { { &TypeInfo{Type: TypeDecimal}, []byte("\x00\x00\x00\x00\x00"), - inf.NewDec(0, 1), + inf.NewDec(0, 0), }, { &TypeInfo{Type: TypeTimestamp},