rlp: add Stream.Raw
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user