rlp: fixes for two corner cases and documentation (#19527)
These changes fix two corner cases related to internal handling of types in package rlp: The "tail" struct tag can only be applied to the last field. The check for this was wrong and didn't allow for private fields after the field with the tag. Unsupported types (e.g. structs containing int) which implement either the Encoder or Decoder interface but not both couldn't be encoded/decoded. Also fixes #19367
This commit is contained in:
@ -49,6 +49,13 @@ func (e byteEncoder) EncodeRLP(w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type undecodableEncoder func()
|
||||
|
||||
func (f undecodableEncoder) EncodeRLP(w io.Writer) error {
|
||||
_, err := w.Write(EmptyList)
|
||||
return err
|
||||
}
|
||||
|
||||
type encodableReader struct {
|
||||
A, B uint
|
||||
}
|
||||
@ -239,6 +246,8 @@ var encTests = []encTest{
|
||||
{val: (*testEncoder)(nil), output: "00000000"},
|
||||
{val: &testEncoder{}, output: "00010001000100010001"},
|
||||
{val: &testEncoder{errors.New("test error")}, error: "test error"},
|
||||
// verify that the Encoder interface works for unsupported types like func().
|
||||
{val: undecodableEncoder(func() {}), output: "C0"},
|
||||
// verify that pointer method testEncoder.EncodeRLP is called for
|
||||
// addressable non-pointer values.
|
||||
{val: &struct{ TE testEncoder }{testEncoder{}}, output: "CA00010001000100010001"},
|
||||
|
Reference in New Issue
Block a user