aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/typecache.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-12-09 17:39:39 +0800
committerFelix Lange <fjl@twurst.com>2014-12-09 17:52:05 +0800
commit4f12f0697e645a567fac9f13ed8cdb25e1218b84 (patch)
tree92972f699f6236e09aee3ec7e197f31d60108298 /rlp/typecache.go
parent195b2d2ebdfe1e794c096c9b6c9fe91e9df7af1d (diff)
downloaddexon-4f12f0697e645a567fac9f13ed8cdb25e1218b84.tar.gz
dexon-4f12f0697e645a567fac9f13ed8cdb25e1218b84.tar.zst
dexon-4f12f0697e645a567fac9f13ed8cdb25e1218b84.zip
rlp: move decoder type switch to decode.go
Diffstat (limited to 'rlp/typecache.go')
-rw-r--r--rlp/typecache.go35
1 files changed, 3 insertions, 32 deletions
diff --git a/rlp/typecache.go b/rlp/typecache.go
index 75dbb43c2..f2595dac8 100644
--- a/rlp/typecache.go
+++ b/rlp/typecache.go
@@ -1,8 +1,6 @@
package rlp
import (
- "fmt"
- "math/big"
"reflect"
"sync"
)
@@ -51,39 +49,12 @@ func cachedTypeInfo1(typ reflect.Type) (*typeinfo, error) {
return typeCache[typ], err
}
-var (
- decoderInterface = reflect.TypeOf(new(Decoder)).Elem()
- bigInt = reflect.TypeOf(big.Int{})
-)
-
func genTypeInfo(typ reflect.Type) (info *typeinfo, err error) {
info = new(typeinfo)
- kind := typ.Kind()
- switch {
- case typ.Implements(decoderInterface):
- info.decoder = decodeDecoder
- case kind != reflect.Ptr && reflect.PtrTo(typ).Implements(decoderInterface):
- info.decoder = decodeDecoderNoPtr
- case typ.AssignableTo(reflect.PtrTo(bigInt)):
- info.decoder = decodeBigInt
- case typ.AssignableTo(bigInt):
- info.decoder = decodeBigIntNoPtr
- case isInteger(kind):
- info.decoder = makeNumDecoder(typ)
- case kind == reflect.String:
- info.decoder = decodeString
- case kind == reflect.Slice || kind == reflect.Array:
- info.decoder, err = makeListDecoder(typ)
- case kind == reflect.Struct:
- info.decoder, err = makeStructDecoder(typ)
- case kind == reflect.Ptr:
- info.decoder, err = makePtrDecoder(typ)
- case kind == reflect.Interface && typ.NumMethod() == 0:
- info.decoder = decodeInterface
- default:
- err = fmt.Errorf("rlp: type %v is not RLP-serializable", typ)
+ if info.decoder, err = makeDecoder(typ); err != nil {
+ return nil, err
}
- return info, err
+ return info, nil
}
func isInteger(k reflect.Kind) bool {