Created
May 6, 2019 08:32
-
-
Save dshulyak/f3101ae6ad7234addece4d2ee228ddba to your computer and use it in GitHub Desktop.
rlp.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/ethereum/go-ethereum/rlp" | |
) | |
type Envelope struct { | |
A uint | |
} | |
func encodeSeparately(envelopes ...Envelope) [][]byte { | |
rst := [][]byte{} | |
for _, e := range envelopes { | |
buf, err := rlp.EncodeToBytes(e) | |
if err != nil { | |
panic(err) | |
} | |
rst = append(rst, buf) | |
} | |
return rst | |
} | |
func main() { | |
first := Envelope{A: 10} | |
second := Envelope{A: 20} | |
data := []Envelope{first, second} | |
buf1, err := rlp.EncodeToBytes(data) | |
if err != nil { | |
panic(err) | |
} | |
buf2, err := rlp.EncodeToBytes(encodeSeparately(first, second)) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(buf1, buf2) | |
var rst []Envelope | |
err = rlp.DecodeBytes(buf1, &rst) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(rst) | |
err = rlp.DecodeBytes(buf2, &rst) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(rst) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[196 193 10 193 20] [198 130 193 10 130 193 20]
[{10} {20}]
panic: rlp: expected input list for main.Envelope, decoding into ([]main.Envelope)[0]
goroutine 1 [running]:
main.main()
/home/dd/status/src/github.com/status-im/status-go/triage.go:48 +0x493
exit status 2