github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/utilities/rlp/decode_tail_test.go (about)

     1  package rlp
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  )
     7  
     8  type structWithTail struct {
     9  	A, B uint
    10  	C    []uint `rlp:"tail"`
    11  }
    12  
    13  func ExampleDecode_structTagTail() {
    14  
    15  	var val structWithTail
    16  
    17  	err := Decode(bytes.NewReader([]byte{0xC4, 0x01, 0x02, 0x03, 0x04}), &val)
    18  	fmt.Printf("with 4 elements: err=%v val=%v\n", err, val)
    19  
    20  	err = Decode(bytes.NewReader([]byte{0xC6, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}), &val)
    21  	fmt.Printf("with 6 elements: err=%v val=%v\n", err, val)
    22  
    23  	err = Decode(bytes.NewReader([]byte{0xC1, 0x01}), &val)
    24  	fmt.Printf("with 1 element: err=%q\n", err)
    25  
    26  }