TARAXA
dev::RLP Class Reference

#include <RLP.h>

Collaboration diagram for dev::RLP:

Classes

class  iterator
 Iterator class for iterating through items of RLP list. More...
 

Public Types

enum  {
  AllowNonCanon = 1 , ThrowOnFail = 4 , FailIfTooBig = 8 , FailIfTooSmall = 16 ,
  Strict = ThrowOnFail | FailIfTooBig , VeryStrict = ThrowOnFail | FailIfTooBig | FailIfTooSmall , LaissezFaire = AllowNonCanon
}
 Conversion flags. More...
 
using Strictness = int
 
using element_type = RLP
 

Public Member Functions

 RLP ()
 Construct a null node. More...
 
 RLP (bytesConstRef _d, Strictness _s=VeryStrict)
 Construct a node of value given in the bytes. More...
 
 RLP (bytes const &_d, Strictness _s=VeryStrict)
 Construct a node of value given in the bytes. More...
 
 RLP (::byte const *_b, unsigned _s, Strictness _st=VeryStrict)
 Construct a node to read RLP data in the bytes given. More...
 
 RLP (std::string const &_s, Strictness _st=VeryStrict)
 Construct a node to read RLP data in the string. More...
 
bytesConstRef data () const
 The bare data of the RLP. More...
 
bool isNull () const
 No value. More...
 
bool isEmpty () const
 Contains a zero-length string or zero-length list. More...
 
bool isData () const
 String value. More...
 
bool isList () const
 List value. More...
 
bool isInt () const
 Integer value. Must not have a leading zero. More...
 
size_t itemCount () const
 
size_t itemCountStrict () const
 
size_t size () const
 
size_t sizeStrict () const
 
bool operator== (char const *_s) const
 Equality operators; does best-effort conversion and checks for equality. More...
 
bool operator!= (char const *_s) const
 
bool operator== (std::string const &_s) const
 
bool operator!= (std::string const &_s) const
 
template<unsigned _N>
bool operator== (FixedHash< _N > const &_h) const
 
template<unsigned _N>
bool operator!= (FixedHash< _N > const &_s) const
 
bool operator== (unsigned const &_i) const
 
bool operator!= (unsigned const &_i) const
 
bool operator== (u256 const &_i) const
 
bool operator!= (u256 const &_i) const
 
bool operator== (bigint const &_i) const
 
bool operator!= (bigint const &_i) const
 
RLP operator[] (size_t _i) const
 
iterator begin () const
 Iterator into beginning of sub-item list (valid only if we are a list). More...
 
iterator end () const
 Iterator into end of sub-item list (valid only if we are a list). More...
 
template<class T >
convert (int _flags) const
 
 operator std::string () const
 Best-effort conversion operators. More...
 
 operator bytes () const
 
 operator uint8_t () const
 
 operator uint16_t () const
 
 operator uint32_t () const
 
 operator uint64_t () const
 
 operator u160 () const
 
 operator u256 () const
 
 operator bigint () const
 
template<unsigned N>
 operator FixedHash< N > () const
 
template<class T , class U >
 operator std::pair< T, U > () const
 
template<class T >
 operator std::vector< T > () const
 
template<class T >
 operator std::set< T > () const
 
template<class T , size_t N>
 operator std::array< T, N > () const
 
bytes toBytes (int _flags=LaissezFaire) const
 Converts to bytearray. More...
 
bytesConstRef toBytesConstRef (int _flags=LaissezFaire) const
 Converts to bytearray. More...
 
std::string toString (int _flags=LaissezFaire) const
 Converts to string. More...
 
std::string toStringStrict () const
 Converts to string. More...
 
template<class T >
std::vector< T > toVector (int _flags=LaissezFaire) const
 
template<class T >
std::set< T > toSet (int _flags=LaissezFaire) const
 
template<class T >
std::unordered_set< T > toUnorderedSet (int _flags=LaissezFaire) const
 
template<class T , class U >
std::pair< T, U > toPair (int _flags=Strict) const
 
template<class T , size_t N>
std::array< T, N > toArray (int _flags=LaissezFaire) const
 
template<class _T = unsigned>
std::enable_if_t< is_integer< _T >Signedness::any), _T > toInt (int _flags=Strict) const
 
int64_t toPositiveInt64 (int _flags=Strict) const
 
template<class _N >
_N toHash (int _flags=Strict) const
 
bytesConstRef payload () const
 
size_t actualSize () const
 

Private Member Functions

 RLP (bytes const &&)
 Disable construction from rvalue. More...
 
void requireGood () const
 
bool isSingleByte () const
 Single-byte data payload. More...
 
unsigned lengthSize () const
 
size_t length () const
 
size_t payloadOffset () const
 
size_t items () const
 

Static Private Member Functions

static size_t sizeAsEncoded (bytesConstRef _data)
 

Private Attributes

bytesConstRef m_data
 Our byte data. More...
 
size_t m_lastIndex = (size_t)-1
 The list-indexing cache. More...
 
size_t m_lastEnd = 0
 
bytesConstRef m_lastItem
 

Detailed Description

Class for interpreting Recursive Linear-Prefix Data.

Member Typedef Documentation

◆ element_type

◆ Strictness

using dev::RLP::Strictness = int

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Conversion flags.

Enumerator
AllowNonCanon 
ThrowOnFail 
FailIfTooBig 
FailIfTooSmall 
Strict 
VeryStrict 
LaissezFaire 

Constructor & Destructor Documentation

◆ RLP() [1/6]

dev::RLP::RLP ( )
inline

Construct a null node.

◆ RLP() [2/6]

RLP::RLP ( bytesConstRef  _d,
Strictness  _s = VeryStrict 
)
explicit

Construct a node of value given in the bytes.

◆ RLP() [3/6]

dev::RLP::RLP ( bytes const &  _d,
Strictness  _s = VeryStrict 
)
inlineexplicit

Construct a node of value given in the bytes.

◆ RLP() [4/6]

dev::RLP::RLP ( ::byte const *  _b,
unsigned  _s,
Strictness  _st = VeryStrict 
)
inline

Construct a node to read RLP data in the bytes given.

◆ RLP() [5/6]

dev::RLP::RLP ( std::string const &  _s,
Strictness  _st = VeryStrict 
)
inlineexplicit

Construct a node to read RLP data in the string.

◆ RLP() [6/6]

dev::RLP::RLP ( bytes const &&  )
inlineexplicitprivate

Disable construction from rvalue.

Member Function Documentation

◆ actualSize()

size_t RLP::actualSize ( ) const
Returns
the theoretical size of this item as encoded in the data.
Note
Under normal circumstances, is equivalent to m_data.size() - use that unless you know it won't work.

◆ begin()

iterator dev::RLP::begin ( ) const
inline

Iterator into beginning of sub-item list (valid only if we are a list).

◆ convert()

template<class T >
T dev::RLP::convert ( int  _flags) const
inline

◆ data()

bytesConstRef dev::RLP::data ( ) const
inline

The bare data of the RLP.

◆ end()

iterator dev::RLP::end ( ) const
inline

Iterator into end of sub-item list (valid only if we are a list).

◆ isData()

bool dev::RLP::isData ( ) const
inline

String value.

◆ isEmpty()

bool dev::RLP::isEmpty ( ) const
inline

Contains a zero-length string or zero-length list.

◆ isInt()

bool RLP::isInt ( ) const

Integer value. Must not have a leading zero.

◆ isList()

bool dev::RLP::isList ( ) const
inline

List value.

◆ isNull()

bool dev::RLP::isNull ( ) const
inline

No value.

◆ isSingleByte()

bool dev::RLP::isSingleByte ( ) const
inlineprivate

Single-byte data payload.

◆ itemCount()

size_t dev::RLP::itemCount ( ) const
inline
Returns
the number of items in the list, or zero if it isn't a list.

◆ itemCountStrict()

size_t dev::RLP::itemCountStrict ( ) const
inline

◆ items()

size_t RLP::items ( ) const
private
Returns
the number of data items.

◆ length()

size_t RLP::length ( ) const
private
Returns
the size in bytes of the payload, as given by the RLP as opposed to as inferred from m_data.

◆ lengthSize()

unsigned dev::RLP::lengthSize ( ) const
inlineprivate
Returns
the amount of bytes used to encode the length of the data. Valid for all types.

◆ operator bigint()

dev::RLP::operator bigint ( ) const
inlineexplicit

◆ operator bytes()

dev::RLP::operator bytes ( ) const
inlineexplicit

◆ operator FixedHash< N >()

template<unsigned N>
dev::RLP::operator FixedHash< N > ( ) const
inlineexplicit

◆ operator std::array< T, N >()

template<class T , size_t N>
dev::RLP::operator std::array< T, N > ( ) const
inlineexplicit

◆ operator std::pair< T, U >()

template<class T , class U >
dev::RLP::operator std::pair< T, U > ( ) const
inlineexplicit

◆ operator std::set< T >()

template<class T >
dev::RLP::operator std::set< T > ( ) const
inlineexplicit

◆ operator std::string()

dev::RLP::operator std::string ( ) const
inlineexplicit

Best-effort conversion operators.

◆ operator std::vector< T >()

template<class T >
dev::RLP::operator std::vector< T > ( ) const
inlineexplicit

◆ operator u160()

dev::RLP::operator u160 ( ) const
inlineexplicit

◆ operator u256()

dev::RLP::operator u256 ( ) const
inlineexplicit

◆ operator uint16_t()

dev::RLP::operator uint16_t ( ) const
inlineexplicit

◆ operator uint32_t()

dev::RLP::operator uint32_t ( ) const
inlineexplicit

◆ operator uint64_t()

dev::RLP::operator uint64_t ( ) const
inlineexplicit

◆ operator uint8_t()

dev::RLP::operator uint8_t ( ) const
inlineexplicit

◆ operator!=() [1/6]

bool dev::RLP::operator!= ( bigint const &  _i) const
inline

◆ operator!=() [2/6]

bool dev::RLP::operator!= ( char const *  _s) const
inline

◆ operator!=() [3/6]

template<unsigned _N>
bool dev::RLP::operator!= ( FixedHash< _N > const &  _s) const
inline

◆ operator!=() [4/6]

bool dev::RLP::operator!= ( std::string const &  _s) const
inline

◆ operator!=() [5/6]

bool dev::RLP::operator!= ( u256 const &  _i) const
inline

◆ operator!=() [6/6]

bool dev::RLP::operator!= ( unsigned const &  _i) const
inline

◆ operator==() [1/6]

bool dev::RLP::operator== ( bigint const &  _i) const
inline

◆ operator==() [2/6]

bool dev::RLP::operator== ( char const *  _s) const
inline

Equality operators; does best-effort conversion and checks for equality.

◆ operator==() [3/6]

template<unsigned _N>
bool dev::RLP::operator== ( FixedHash< _N > const &  _h) const
inline

◆ operator==() [4/6]

bool dev::RLP::operator== ( std::string const &  _s) const
inline

◆ operator==() [5/6]

bool dev::RLP::operator== ( u256 const &  _i) const
inline

◆ operator==() [6/6]

bool dev::RLP::operator== ( unsigned const &  _i) const
inline

◆ operator[]()

RLP RLP::operator[] ( size_t  _i) const

Subscript operator.

Returns
the list item _i if isList() and _i < listItems(), or RLP() otherwise.
Note
if used to access items in ascending order, this is efficient.

◆ payload()

bytesConstRef dev::RLP::payload ( ) const
inline
Returns
the data payload. Valid for all types.

◆ payloadOffset()

size_t dev::RLP::payloadOffset ( ) const
inlineprivate
Returns
the number of bytes into the data that the payload starts.

◆ requireGood()

void RLP::requireGood ( ) const
private

Throws if is non-canonical data (i.e. single byte done in two bytes that could be done in one).

◆ size()

size_t dev::RLP::size ( ) const
inline
Returns
the number of bytes in the data, or zero if it isn't data.

◆ sizeAsEncoded()

static size_t dev::RLP::sizeAsEncoded ( bytesConstRef  _data)
inlinestaticprivate
Returns
the size encoded into the RLP in _data and throws if _data is too short.

◆ sizeStrict()

size_t dev::RLP::sizeStrict ( ) const
inline

◆ toArray()

template<class T , size_t N>
std::array<T, N> dev::RLP::toArray ( int  _flags = LaissezFaire) const
inline

◆ toBytes()

bytes dev::RLP::toBytes ( int  _flags = LaissezFaire) const
inline

Converts to bytearray.

Returns
the empty byte array if not a string.

◆ toBytesConstRef()

bytesConstRef dev::RLP::toBytesConstRef ( int  _flags = LaissezFaire) const
inline

Converts to bytearray.

Returns
the empty byte array if not a string.

◆ toHash()

template<class _N >
_N dev::RLP::toHash ( int  _flags = Strict) const
inline

◆ toInt()

template<class _T = unsigned>
std::enable_if_t<is_integer<_T>Signedness::any), _T> dev::RLP::toInt ( int  _flags = Strict) const
inline

Converts to int of type given; if isData(), decodes as big-endian bytestream.

Returns
0 if not an int or data.

◆ toPair()

template<class T , class U >
std::pair<T, U> dev::RLP::toPair ( int  _flags = Strict) const
inline

◆ toPositiveInt64()

int64_t dev::RLP::toPositiveInt64 ( int  _flags = Strict) const
inline

◆ toSet()

template<class T >
std::set<T> dev::RLP::toSet ( int  _flags = LaissezFaire) const
inline

◆ toString()

std::string dev::RLP::toString ( int  _flags = LaissezFaire) const
inline

Converts to string.

Returns
the empty string if not a string.

◆ toStringStrict()

std::string dev::RLP::toStringStrict ( ) const
inline

Converts to string.

Exceptions
BadCastif not a string.

◆ toUnorderedSet()

template<class T >
std::unordered_set<T> dev::RLP::toUnorderedSet ( int  _flags = LaissezFaire) const
inline

◆ toVector()

template<class T >
std::vector<T> dev::RLP::toVector ( int  _flags = LaissezFaire) const
inline

Member Data Documentation

◆ m_data

bytesConstRef dev::RLP::m_data
private

Our byte data.

◆ m_lastEnd

size_t dev::RLP::m_lastEnd = 0
mutableprivate

◆ m_lastIndex

size_t dev::RLP::m_lastIndex = (size_t)-1
mutableprivate

The list-indexing cache.

◆ m_lastItem

bytesConstRef dev::RLP::m_lastItem
mutableprivate

The documentation for this class was generated from the following files: