jameshartig commented on code in PR #1855:
URL:
https://github.com/apache/cassandra-gocql-driver/pull/1855#discussion_r2131532650
##########
marshal.go:
##########
@@ -232,95 +176,97 @@ func Unmarshal(info TypeInfo, data []byte, value
interface{}) error {
return v.UnmarshalCQL(info, data)
}
- if isNullableValue(value) {
- return unmarshalNullable(info, data, value)
- }
-
- switch info.Type() {
- case TypeVarchar, TypeAscii, TypeBlob, TypeText:
- return unmarshalVarchar(info, data, value)
- case TypeBoolean:
- return unmarshalBool(info, data, value)
- case TypeInt:
- return unmarshalInt(info, data, value)
- case TypeBigInt, TypeCounter:
- return unmarshalBigInt(info, data, value)
- case TypeVarint:
- return unmarshalVarint(info, data, value)
- case TypeSmallInt:
- return unmarshalSmallInt(info, data, value)
- case TypeTinyInt:
- return unmarshalTinyInt(info, data, value)
- case TypeFloat:
- return unmarshalFloat(info, data, value)
- case TypeDouble:
- return unmarshalDouble(info, data, value)
- case TypeDecimal:
- return unmarshalDecimal(info, data, value)
- case TypeTime:
- return unmarshalTime(info, data, value)
- case TypeTimestamp:
- return unmarshalTimestamp(info, data, value)
- case TypeList, TypeSet:
- return unmarshalList(info, data, value)
- case TypeMap:
- return unmarshalMap(info, data, value)
- case TypeTimeUUID:
- return unmarshalTimeUUID(info, data, value)
- case TypeUUID:
- return unmarshalUUID(info, data, value)
- case TypeInet:
- return unmarshalInet(info, data, value)
- case TypeTuple:
- return unmarshalTuple(info, data, value)
- case TypeUDT:
- return unmarshalUDT(info, data, value)
- case TypeDate:
- return unmarshalDate(info, data, value)
- case TypeDuration:
- return unmarshalDuration(info, data, value)
- case TypeCustom:
- if vector, ok := info.(VectorType); ok {
- return unmarshalVector(vector, data, value)
+ // check for pointer
+ // we don't error for non-pointers because certain types support
unmarshalling
+ // into maps/slices
+ valueRef := reflect.ValueOf(value)
+ if valueRef.Kind() == reflect.Ptr {
+ // handle pointers and nil data
+ valueElemRef := valueRef.Elem()
+ switch valueElemRef.Kind() {
+ case reflect.Ptr:
+ if data == nil {
+ if valueElemRef.IsNil() {
+ return nil
+ }
+
valueRef.Elem().Set(reflect.Zero(valueElemRef.Type()))
+ return nil
+ }
+ // TODO: can we do this?
Review Comment:
@joao-r-reis we technically don't need to be allocating a new value if the
existing pointer is non-nil but this would be considered a breaking change. The
[original commit](https://github.com/jackc/pgx/issues/1174) doesn't mention
this as a goal and there was a [related issue filed regarding reuse of byte
slices](https://github.com/apache/cassandra-gocql-driver/issues/1348) that was
closed as working-as-intended. `json`'s unmarshaller does not allocate a new
value. But I also found at least [one case of someone in another
driver](https://github.com/jackc/pgx/issues/1174) saying this is confusing.
Thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]