aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/decode.go
diff options
context:
space:
mode:
Diffstat (limited to 'rlp/decode.go')
-rw-r--r--rlp/decode.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/rlp/decode.go b/rlp/decode.go
index 0e99d9caa..0fde0a947 100644
--- a/rlp/decode.go
+++ b/rlp/decode.go
@@ -540,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