aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/decode.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-21 21:36:20 +0800
committerobscuren <geffobscura@gmail.com>2015-03-21 21:36:20 +0800
commit06697775d1edc3263a7915cee02a94bea488494c (patch)
tree1d39f205327ee47115a7fe2947ccd5a4ba7a4073 /rlp/decode.go
parentabce6804a085087770be587e039fd4669d5eac26 (diff)
parent069c87b960c48864dc4f1b9086adf582e1dc88a9 (diff)
downloaddexon-06697775d1edc3263a7915cee02a94bea488494c.tar
dexon-06697775d1edc3263a7915cee02a94bea488494c.tar.gz
dexon-06697775d1edc3263a7915cee02a94bea488494c.tar.bz2
dexon-06697775d1edc3263a7915cee02a94bea488494c.tar.lz
dexon-06697775d1edc3263a7915cee02a94bea488494c.tar.xz
dexon-06697775d1edc3263a7915cee02a94bea488494c.tar.zst
dexon-06697775d1edc3263a7915cee02a94bea488494c.zip
Merge branch 'conversion' of github.com-obscure:ethereum/go-ethereum into conversion
Diffstat (limited to 'rlp/decode.go')
-rw-r--r--rlp/decode.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/rlp/decode.go b/rlp/decode.go
index 6d7e670c2..0fde0a947 100644
--- a/rlp/decode.go
+++ b/rlp/decode.go
@@ -367,7 +367,12 @@ func makePtrDecoder(typ reflect.Type) (decoder, error) {
dec := func(s *Stream, val reflect.Value) (err error) {
_, size, err := s.Kind()
if err != nil || size == 0 && s.byteval == 0 {
- val.Set(reflect.Zero(typ)) // set to nil
+ // rearm s.Kind. This is important because the input
+ // position must advance to the next value even though
+ // we don't read anything.
+ s.kind = -1
+ // set the pointer to nil.
+ val.Set(reflect.Zero(typ))
return err
}
newval := val
@@ -535,6 +540,31 @@ func (s *Stream) Bytes() ([]byte, error) {
}
}
+// Raw reads a raw encoded value including RLP type information.
+func (s *Stream) Raw() ([]byte, error) {
+ kind, size, err := s.Kind()
+ if err != nil {
+ return nil, err
+ }
+ if kind == Byte {
+ s.kind = -1 // rearm Kind
+ return []byte{s.byteval}, nil
+ }
+ // the original header has already been read and is no longer
+ // available. read content and put a new header in front of it.
+ start := headsize(size)
+ buf := make([]byte, uint64(start)+size)
+ if err := s.readFull(buf[start:]); err != nil {
+ return nil, err
+ }
+ if kind == String {
+ puthead(buf, 0x80, 0xB8, size)
+ } else {
+ puthead(buf, 0xC0, 0xF7, size)
+ }
+ return buf, nil
+}
+
var errUintOverflow = errors.New("rlp: uint overflow")
// Uint reads an RLP string of up to 8 bytes and returns its contents