rlp: allow encoding non-empty interface values

This needs to be supported because []someInterface does occur sometimes.

Funny enough, the fix involves changes to the decoder. makeDecoder
cannot return an error for non-empty interfaces anymore because the type
cache builds both decoder and writer. Do the check at 'runtime' instead.
This commit is contained in:
Felix Lange
2015-01-15 23:21:41 +01:00
parent 29c46cdf34
commit fc92abec2c
4 changed files with 23 additions and 3 deletions

View File

@@ -280,7 +280,6 @@ func (r *encReader) next() []byte {
var (
encoderInterface = reflect.TypeOf(new(Encoder)).Elem()
emptyInterface = reflect.TypeOf(new(interface{})).Elem()
big0 = big.NewInt(0)
)
@@ -292,7 +291,7 @@ func makeWriter(typ reflect.Type) (writer, error) {
return writeEncoder, nil
case kind != reflect.Ptr && reflect.PtrTo(typ).Implements(encoderInterface):
return writeEncoderNoPtr, nil
case typ == emptyInterface:
case kind == reflect.Interface:
return writeInterface, nil
case typ.AssignableTo(reflect.PtrTo(bigInt)):
return writeBigIntPtr, nil