|
|
@@ -43,9 +43,6 @@ type Unmarshaler interface {
|
|
|
// Marshal returns the CQL encoding of the value for the Cassandra
|
|
|
// internal type described by the info parameter.
|
|
|
func Marshal(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
- if value == nil {
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
if info.Version() < protoVersion1 {
|
|
|
panic("protocol version not set")
|
|
|
}
|
|
|
@@ -290,7 +287,16 @@ func marshalInt(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
}
|
|
|
return encInt(int32(i)), nil
|
|
|
}
|
|
|
+
|
|
|
+ if value == nil {
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+
|
|
|
rv := reflect.ValueOf(value)
|
|
|
+ if rv.IsNil() {
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+
|
|
|
switch rv.Type().Kind() {
|
|
|
case reflect.Int, reflect.Int64, reflect.Int32, reflect.Int16, reflect.Int8:
|
|
|
v := rv.Int()
|
|
|
@@ -881,9 +887,6 @@ func marshalList(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
k := t.Kind()
|
|
|
switch k {
|
|
|
case reflect.Slice, reflect.Array:
|
|
|
- if k == reflect.Slice && rv.IsNil() {
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
buf := &bytes.Buffer{}
|
|
|
n := rv.Len()
|
|
|
|
|
|
@@ -989,9 +992,7 @@ func marshalMap(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
if t.Kind() != reflect.Map {
|
|
|
return nil, marshalErrorf("can not marshal %T into %s", value, info)
|
|
|
}
|
|
|
- if rv.IsNil() {
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
+
|
|
|
buf := &bytes.Buffer{}
|
|
|
n := rv.Len()
|
|
|
|
|
|
@@ -1285,9 +1286,12 @@ func marshalUDT(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- n := len(data)
|
|
|
- buf = appendInt(buf, int32(n))
|
|
|
- buf = append(buf, data...)
|
|
|
+ if data == nil && typeCanBeNull(e.Type) {
|
|
|
+ buf = appendInt(buf, -1)
|
|
|
+ } else {
|
|
|
+ buf = appendInt(buf, int32(len(data)))
|
|
|
+ buf = append(buf, data...)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return buf, nil
|
|
|
@@ -1304,9 +1308,12 @@ func marshalUDT(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- n := len(data)
|
|
|
- buf = appendInt(buf, int32(n))
|
|
|
- buf = append(buf, data...)
|
|
|
+ if data == nil && typeCanBeNull(e.Type) {
|
|
|
+ buf = appendInt(buf, -1)
|
|
|
+ } else {
|
|
|
+ buf = appendInt(buf, int32(len(data)))
|
|
|
+ buf = append(buf, data...)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return buf, nil
|
|
|
@@ -1342,8 +1349,12 @@ func marshalUDT(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
}
|
|
|
|
|
|
if !f.IsValid() {
|
|
|
- buf = appendInt(buf, -1)
|
|
|
- continue
|
|
|
+ if _, ok := e.Type.(CollectionType); ok {
|
|
|
+ f = reflect.Zero(goType(e.Type))
|
|
|
+ } else {
|
|
|
+ buf = appendInt(buf, -1)
|
|
|
+ continue
|
|
|
+ }
|
|
|
} else if f.Kind() == reflect.Ptr {
|
|
|
if f.IsNil() {
|
|
|
buf = appendInt(buf, -1)
|
|
|
@@ -1358,9 +1369,12 @@ func marshalUDT(info TypeInfo, value interface{}) ([]byte, error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- n := len(data)
|
|
|
- buf = appendInt(buf, int32(n))
|
|
|
- buf = append(buf, data...)
|
|
|
+ if data == nil && typeCanBeNull(e.Type) {
|
|
|
+ buf = appendInt(buf, -1)
|
|
|
+ } else {
|
|
|
+ buf = appendInt(buf, int32(len(data)))
|
|
|
+ buf = append(buf, data...)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return buf, nil
|