Browse Source

Use library encoding routines

Ben Hood 11 years ago
parent
commit
b9b84ebdc5
2 changed files with 5 additions and 4 deletions
  1. 3 1
      cassandra_test.go
  2. 2 3
      marshal.go

+ 3 - 1
cassandra_test.go

@@ -310,12 +310,14 @@ type Page struct {
 
 type Attachment []byte
 
+var rating, _ = inf.NewDec(0, 0).SetString("0.131")
+
 var pageTestData = []*Page{
 	&Page{
 		Title:    "Frontpage",
 		RevId:    TimeUUID(),
 		Body:     "Welcome to this wiki page!",
-		Rating:   inf.NewDec(871298379, 243),
+		Rating:   rating,
 		Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
 		Tags:     []string{"start", "important", "test"},
 		Attachments: map[string]Attachment{

+ 2 - 3
marshal.go

@@ -6,7 +6,6 @@ package gocql
 
 import (
 	"bytes"
-	"encoding/binary"
 	"fmt"
 	"math"
 	"math/big"
@@ -698,7 +697,7 @@ func marshalDecimal(info *TypeInfo, value interface{}) ([]byte, error) {
 		}
 		scale := v.Scale()
 		buf := make([]byte, 4+len(unscaled))
-		binary.BigEndian.PutUint32(buf, uint32(scale))
+		copy(buf[0:4], encInt(int32(scale)))
 		copy(buf[4:], unscaled)
 		return buf, nil
 	}
@@ -711,7 +710,7 @@ func unmarshalDecimal(info *TypeInfo, data []byte, value interface{}) error {
 		return v.UnmarshalCQL(info, data)
 	case **inf.Dec:
 		if len(data) > 4 {
-			scale := binary.BigEndian.Uint32(data[0:4])
+			scale := decInt(data[0:4])
 			unscaled := new(big.Int).SetBytes(data[4:])
 			*v = inf.NewDecBig(unscaled, inf.Scale(scale))
 		}