Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion udt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ var (
)

type udt struct {
mapper *reflectx.Mapper
field map[string]reflect.Value
value reflect.Value
strict bool
}

func makeUDT(value reflect.Value, mapper *reflectx.Mapper, strict bool) udt {
return udt{
mapper: mapper,
value: value,
field: mapper.FieldMap(value),
strict: strict,
Expand All @@ -40,7 +42,12 @@ func makeUDT(value reflect.Value, mapper *reflectx.Mapper, strict bool) udt {
func (u udt) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
value, ok := u.field[name]
if ok {
return gocql.Marshal(info, value.Interface())
switch info.(type) {
case gocql.UDTTypeInfo:
return gocql.Marshal(info, makeUDT(value, u.mapper, u.strict))
default:
return gocql.Marshal(info, value.Interface())
}
}
if !u.strict {
return nil, nil
Expand All @@ -51,6 +58,10 @@ func (u udt) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
func (u udt) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
value, ok := u.field[name]
if ok {
if value.Addr().Type().Implements(autoUDTInterface) {
return gocql.Unmarshal(info, data, makeUDT(value.Addr(), u.mapper, u.strict))
}

return gocql.Unmarshal(info, data, value.Addr().Interface())
}
if !u.strict {
Expand Down