iterx: Move isScannable to Iterx

Signed-off-by: Michał Matczuk <michal@scylladb.com>
This commit is contained in:
Michał Matczuk
2020-01-17 14:54:46 +01:00
committed by Michal Jan Matczuk
parent bd53297a6c
commit 7c0a35d621
2 changed files with 18 additions and 22 deletions

View File

@@ -74,6 +74,22 @@ func (iter *Iterx) Get(dest interface{}) error {
return iter.checkErrAndNotFound()
}
// isScannable takes the reflect.Type and the actual dest value and returns
// whether or not it's Scannable. t is scannable if:
// * ptr to t implements gocql.Unmarshaler
// * it is not a struct
// * it has no exported fields
func (iter *Iterx) isScannable(t reflect.Type) bool {
if reflect.PtrTo(t).Implements(_unmarshallerInterface) {
return true
}
if t.Kind() != reflect.Struct {
return true
}
return len(iter.Mapper.TypeMap(t).Index) == 0
}
func (iter *Iterx) scanAny(dest interface{}, structOnly bool) bool {
value := reflect.ValueOf(dest)
if value.Kind() != reflect.Ptr {
@@ -86,7 +102,7 @@ func (iter *Iterx) scanAny(dest interface{}, structOnly bool) bool {
}
base := reflectx.Deref(value.Type())
scannable := isScannable(base)
scannable := iter.isScannable(base)
if structOnly && scannable {
iter.err = structOnlyError(base)
@@ -140,7 +156,7 @@ func (iter *Iterx) scanAll(dest interface{}, structOnly bool) bool {
isPtr := slice.Elem().Kind() == reflect.Ptr
base := reflectx.Deref(slice.Elem())
scannable := isScannable(base)
scannable := iter.isScannable(base)
if structOnly && scannable {
iter.err = structOnlyError(base)