aboutsummaryrefslogtreecommitdiffstats
path: root/rlp
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-18 21:16:07 +0800
committerobscuren <geffobscura@gmail.com>2015-03-18 21:16:07 +0800
commit4d0ae8b0cb32e9de63092bc36022ea4af76cad8b (patch)
tree240356371b44765d64c9ceed9be84064258e8c1d /rlp
parent48dd601de0ffea4e1bf57a8923f2a6126553b575 (diff)
parent064279c0ec2f048cbdd965c095ea332bb8666f94 (diff)
downloaddexon-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.go7
-rw-r--r--rlp/encode.go7
-rw-r--r--rlp/encode_test.go1
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"},