|
@@ -7,12 +7,14 @@ package gocql
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
"encoding/binary"
|
|
"encoding/binary"
|
|
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"math"
|
|
"math"
|
|
|
"math/big"
|
|
"math/big"
|
|
|
"net"
|
|
"net"
|
|
|
"reflect"
|
|
"reflect"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
|
|
+ "strings"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"speter.net/go/exp/math/dec/inf"
|
|
"speter.net/go/exp/math/dec/inf"
|
|
@@ -22,6 +24,10 @@ var (
|
|
|
bigOne = big.NewInt(1)
|
|
bigOne = big.NewInt(1)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var (
|
|
|
|
|
+ ErrorUDTUnavailable = errors.New("UDT are not available on protocols less than 3, please update config")
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
// Marshaler is the interface implemented by objects that can marshal
|
|
// Marshaler is the interface implemented by objects that can marshal
|
|
|
// themselves into values understood by Cassandra.
|
|
// themselves into values understood by Cassandra.
|
|
|
type Marshaler interface {
|
|
type Marshaler interface {
|
|
@@ -86,6 +92,12 @@ func Marshal(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
case TypeUDT:
|
|
case TypeUDT:
|
|
|
return marshalUDT(info, value)
|
|
return marshalUDT(info, value)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // detect protocol 2 UDT
|
|
|
|
|
+ if strings.HasPrefix(info.Custom(), "org.apache.cassandra.db.marshal.UserType") && info.Version() < 3 {
|
|
|
|
|
+ return nil, ErrorUDTUnavailable
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// TODO(tux21b): add the remaining types
|
|
// TODO(tux21b): add the remaining types
|
|
|
return nil, fmt.Errorf("can not marshal %T into %s", value, info)
|
|
return nil, fmt.Errorf("can not marshal %T into %s", value, info)
|
|
|
}
|
|
}
|
|
@@ -135,6 +147,12 @@ func Unmarshal(info TypeInfo, data []byte, value interface{}) error {
|
|
|
case TypeUDT:
|
|
case TypeUDT:
|
|
|
return unmarshalUDT(info, data, value)
|
|
return unmarshalUDT(info, data, value)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // detect protocol 2 UDT
|
|
|
|
|
+ if strings.HasPrefix(info.Custom(), "org.apache.cassandra.db.marshal.UserType") && info.Version() < 3 {
|
|
|
|
|
+ return ErrorUDTUnavailable
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// TODO(tux21b): add the remaining types
|
|
// TODO(tux21b): add the remaining types
|
|
|
return fmt.Errorf("can not unmarshal %s into %T", info, value)
|
|
return fmt.Errorf("can not unmarshal %s into %T", info, value)
|
|
|
}
|
|
}
|