diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-18 21:16:07 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-18 21:16:07 +0800 |
commit | 4d0ae8b0cb32e9de63092bc36022ea4af76cad8b (patch) | |
tree | 240356371b44765d64c9ceed9be84064258e8c1d /rlp | |
parent | 48dd601de0ffea4e1bf57a8923f2a6126553b575 (diff) | |
parent | 064279c0ec2f048cbdd965c095ea332bb8666f94 (diff) | |
download | dexon-4d0ae8b0cb32e9de63092bc36022ea4af76cad8b.tar dexon-4d0ae8b0cb32e9de63092bc36022ea4af76cad8b.tar.gz dexon-4d0ae8b0cb32e9de63092bc36022ea4af76cad8b.tar.bz2 dexon-4d0ae8b0cb32e9de63092bc36022ea4af76cad8b.tar.lz dexon-4d0ae8b0cb32e9de63092bc36022ea4af76cad8b.tar.xz dexon-4d0ae8b0cb32e9de63092bc36022ea4af76cad8b.tar.zst dexon-4d0ae8b0cb32e9de63092bc36022ea4af76cad8b.zip |
Merge branch 'conversion' of github.com-obscure:ethereum/go-ethereum into conversion
Diffstat (limited to 'rlp')
-rw-r--r-- | rlp/decode.go | 7 | ||||
-rw-r--r-- | rlp/encode.go | 7 | ||||
-rw-r--r-- | rlp/encode_test.go | 1 |
3 files changed, 14 insertions, 1 deletions
diff --git a/rlp/decode.go b/rlp/decode.go index 55f7187a3..6d7e670c2 100644 --- a/rlp/decode.go +++ b/rlp/decode.go @@ -2,6 +2,7 @@ package rlp import ( "bufio" + "bytes" "encoding/binary" "errors" "fmt" @@ -73,6 +74,12 @@ func Decode(r io.Reader, val interface{}) error { return NewStream(r).Decode(val) } +// DecodeBytes parses RLP data from b into val. +// Please see the documentation of Decode for the decoding rules. +func DecodeBytes(b []byte, val interface{}) error { + return NewStream(bytes.NewReader(b)).Decode(val) +} + type decodeError struct { msg string typ reflect.Type diff --git a/rlp/encode.go b/rlp/encode.go index 9d11d66bf..42bbb876c 100644 --- a/rlp/encode.go +++ b/rlp/encode.go @@ -386,7 +386,12 @@ func writeUint(val reflect.Value, w *encbuf) error { } func writeBigIntPtr(val reflect.Value, w *encbuf) error { - return writeBigInt(val.Interface().(*big.Int), w) + ptr := val.Interface().(*big.Int) + if ptr == nil { + w.str = append(w.str, 0x80) + return nil + } + return writeBigInt(ptr, w) } func writeBigIntNoPtr(val reflect.Value, w *encbuf) error { diff --git a/rlp/encode_test.go b/rlp/encode_test.go index c283fbd57..852cb6f59 100644 --- a/rlp/encode_test.go +++ b/rlp/encode_test.go @@ -196,6 +196,7 @@ var encTests = []encTest{ {val: (*uint)(nil), output: "80"}, {val: (*string)(nil), output: "80"}, {val: (*[]byte)(nil), output: "80"}, + {val: (*big.Int)(nil), output: "80"}, {val: (*[]string)(nil), output: "C0"}, {val: (*[]interface{})(nil), output: "C0"}, {val: (*[]struct{ uint })(nil), output: "C0"}, |