aboutsummaryrefslogtreecommitdiffstats
path: root/rlp
diff options
context:
space:
mode:
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"},