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

@ -137,7 +137,7 @@ func makeDecoder(typ reflect.Type) (dec decoder, err error) {
return makeStructDecoder(typ)
case kind == reflect.Ptr:
return makePtrDecoder(typ)
case kind == reflect.Interface && typ.NumMethod() == 0:
case kind == reflect.Interface:
return decodeInterface, nil
default:
return nil, fmt.Errorf("rlp: type %v is not RLP-serializable", typ)
@ -378,6 +378,9 @@ func makePtrDecoder(typ reflect.Type) (decoder, error) {
var ifsliceType = reflect.TypeOf([]interface{}{})
func decodeInterface(s *Stream, val reflect.Value) error {
if val.Type().NumMethod() != 0 {
return fmt.Errorf("rlp: type %v is not RLP-serializable", val.Type())
}
kind, _, err := s.Kind()
if err != nil {
return err