diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-21 07:49:31 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-21 07:49:31 +0800 |
commit | a829a5658723ff3681f14650818ef050cb0a7fa8 (patch) | |
tree | 5736f714715fb5f229f7854bec6e76d333485fc6 /rlp/decode.go | |
parent | 81800ca39ea03da7f63d8ecfbd74773f4ca73323 (diff) | |
download | go-tangerine-a829a5658723ff3681f14650818ef050cb0a7fa8.tar go-tangerine-a829a5658723ff3681f14650818ef050cb0a7fa8.tar.gz go-tangerine-a829a5658723ff3681f14650818ef050cb0a7fa8.tar.bz2 go-tangerine-a829a5658723ff3681f14650818ef050cb0a7fa8.tar.lz go-tangerine-a829a5658723ff3681f14650818ef050cb0a7fa8.tar.xz go-tangerine-a829a5658723ff3681f14650818ef050cb0a7fa8.tar.zst go-tangerine-a829a5658723ff3681f14650818ef050cb0a7fa8.zip |
rlp: add Stream.Raw
Diffstat (limited to 'rlp/decode.go')
-rw-r--r-- | rlp/decode.go | 25 |
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 |