[release/1.3.4] rlp: add "tail" struct tag
This commit is contained in:
committed by
Jeffrey Wilcke
parent
8cb69b9e9b
commit
93077941d3
@ -312,6 +312,26 @@ type recstruct struct {
|
||||
Child *recstruct `rlp:"nil"`
|
||||
}
|
||||
|
||||
type invalidTail1 struct {
|
||||
A uint `rlp:"tail"`
|
||||
B string
|
||||
}
|
||||
|
||||
type invalidTail2 struct {
|
||||
A uint
|
||||
B string `rlp:"tail"`
|
||||
}
|
||||
|
||||
type tailRaw struct {
|
||||
A uint
|
||||
Tail []RawValue `rlp:"tail"`
|
||||
}
|
||||
|
||||
type tailUint struct {
|
||||
A uint
|
||||
Tail []uint `rlp:"tail"`
|
||||
}
|
||||
|
||||
var (
|
||||
veryBigInt = big.NewInt(0).Add(
|
||||
big.NewInt(0).Lsh(big.NewInt(0xFFFFFFFFFFFFFF), 16),
|
||||
@ -437,6 +457,38 @@ var decodeTests = []decodeTest{
|
||||
ptr: new(recstruct),
|
||||
error: "rlp: expected input string or byte for uint, decoding into (rlp.recstruct).Child.I",
|
||||
},
|
||||
{
|
||||
input: "C0",
|
||||
ptr: new(invalidTail1),
|
||||
error: "rlp: invalid struct tag \"tail\" for rlp.invalidTail1.A (must be on last field)",
|
||||
},
|
||||
{
|
||||
input: "C0",
|
||||
ptr: new(invalidTail2),
|
||||
error: "rlp: invalid struct tag \"tail\" for rlp.invalidTail2.B (field type is not slice)",
|
||||
},
|
||||
{
|
||||
input: "C50102C20102",
|
||||
ptr: new(tailUint),
|
||||
error: "rlp: expected input string or byte for uint, decoding into (rlp.tailUint).Tail[1]",
|
||||
},
|
||||
|
||||
// struct tag "tail"
|
||||
{
|
||||
input: "C3010203",
|
||||
ptr: new(tailRaw),
|
||||
value: tailRaw{A: 1, Tail: []RawValue{unhex("02"), unhex("03")}},
|
||||
},
|
||||
{
|
||||
input: "C20102",
|
||||
ptr: new(tailRaw),
|
||||
value: tailRaw{A: 1, Tail: []RawValue{unhex("02")}},
|
||||
},
|
||||
{
|
||||
input: "C101",
|
||||
ptr: new(tailRaw),
|
||||
value: tailRaw{A: 1, Tail: []RawValue{}},
|
||||
},
|
||||
|
||||
// RawValue
|
||||
{input: "01", ptr: new(RawValue), value: RawValue(unhex("01"))},
|
||||
|
Reference in New Issue
Block a user