Ethereum  PoC-8
The C++ Implementation of Ethereum
dev::RLP Class Reference

#include <RLP.h>

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...
 
 operator bool () const
 
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>
_T toInt (int _flags=Strict) const
 Converts to int of type given; if isData(), decodes as big-endian bytestream. More...
 
int64_t toPositiveInt64 (int _flags=Strict) const
 
template<class _N >
_N toHash (int _flags=Strict) const
 
bytesConstRef payload () const
 
size_t actualSize () const
 

Detailed Description

Class for interpreting Recursive Linear-Prefix Data.

Definition at line 47 of file RLP.h.

Member Typedef Documentation

◆ element_type

Definition at line 127 of file RLP.h.

◆ Strictness

using dev::RLP::Strictness = int

Definition at line 62 of file RLP.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Conversion flags.

Enumerator
AllowNonCanon 
ThrowOnFail 
FailIfTooBig 
FailIfTooSmall 
Strict 
VeryStrict 
LaissezFaire 

Definition at line 51 of file RLP.h.

Constructor & Destructor Documentation

◆ RLP() [1/5]

dev::RLP::RLP ( )
inline

Construct a null node.

Definition at line 65 of file RLP.h.

◆ RLP() [2/5]

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

Construct a node of value given in the bytes.

Definition at line 36 of file RLP.cpp.

◆ RLP() [3/5]

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

Construct a node of value given in the bytes.

Definition at line 71 of file RLP.h.

◆ RLP() [4/5]

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

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

Definition at line 74 of file RLP.h.

◆ RLP() [5/5]

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

Construct a node to read RLP data in the string.

Definition at line 77 of file RLP.h.

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.

Definition at line 100 of file RLP.cpp.

◆ begin()

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

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

Definition at line 153 of file RLP.h.

◆ convert()

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

Definition at line 364 of file RLP.h.

◆ data()

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

The bare data of the RLP.

Definition at line 80 of file RLP.h.

◆ end()

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

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

Definition at line 156 of file RLP.h.

◆ isData()

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

String value.

Definition at line 92 of file RLP.h.

◆ isEmpty()

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

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

Definition at line 89 of file RLP.h.

◆ isInt()

bool RLP::isInt ( ) const

Integer value. Must not have a leading zero.

Definition at line 124 of file RLP.cpp.

◆ isList()

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

List value.

Definition at line 95 of file RLP.h.

◆ isNull()

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

No value.

Definition at line 86 of file RLP.h.

◆ itemCount()

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

Definition at line 101 of file RLP.h.

◆ itemCountStrict()

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

Definition at line 102 of file RLP.h.

◆ operator bigint()

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

Definition at line 169 of file RLP.h.

◆ operator bool()

dev::RLP::operator bool ( ) const
inlineexplicit
Returns
true if the RLP is non-null.

Definition at line 83 of file RLP.h.

◆ operator bytes()

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

Definition at line 162 of file RLP.h.

◆ operator FixedHash< N >()

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

Definition at line 170 of file RLP.h.

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

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

Definition at line 174 of file RLP.h.

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

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

Definition at line 171 of file RLP.h.

◆ operator std::set< T >()

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

Definition at line 173 of file RLP.h.

◆ operator std::string()

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

Best-effort conversion operators.

Definition at line 161 of file RLP.h.

◆ operator std::vector< T >()

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

Definition at line 172 of file RLP.h.

◆ operator u160()

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

Definition at line 167 of file RLP.h.

◆ operator u256()

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

Definition at line 168 of file RLP.h.

◆ operator uint16_t()

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

Definition at line 164 of file RLP.h.

◆ operator uint32_t()

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

Definition at line 165 of file RLP.h.

◆ operator uint64_t()

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

Definition at line 166 of file RLP.h.

◆ operator uint8_t()

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

Definition at line 163 of file RLP.h.

◆ operator!=() [1/6]

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

Definition at line 120 of file RLP.h.

◆ operator!=() [2/6]

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

Definition at line 110 of file RLP.h.

◆ operator!=() [3/6]

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

Definition at line 114 of file RLP.h.

◆ operator!=() [4/6]

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

Definition at line 112 of file RLP.h.

◆ operator!=() [5/6]

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

Definition at line 118 of file RLP.h.

◆ operator!=() [6/6]

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

Definition at line 116 of file RLP.h.

◆ operator==() [1/6]

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

Definition at line 119 of file RLP.h.

◆ operator==() [2/6]

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

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

Definition at line 109 of file RLP.h.

◆ operator==() [3/6]

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

Definition at line 113 of file RLP.h.

◆ operator==() [4/6]

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

Definition at line 111 of file RLP.h.

◆ operator==() [5/6]

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

Definition at line 117 of file RLP.h.

◆ operator==() [6/6]

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

Definition at line 115 of file RLP.h.

◆ 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.

Definition at line 83 of file RLP.cpp.

◆ payload()

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

Definition at line 308 of file RLP.h.

◆ size()

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

Definition at line 105 of file RLP.h.

◆ sizeStrict()

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

Definition at line 106 of file RLP.h.

◆ toArray()

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

Definition at line 241 of file RLP.h.

◆ toBytes()

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

Converts to bytearray.

Returns
the empty byte array if not a string.

Definition at line 177 of file RLP.h.

◆ toBytesConstRef()

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

Converts to bytearray.

Returns
the empty byte array if not a string.

Definition at line 179 of file RLP.h.

◆ toHash()

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

Definition at line 288 of file RLP.h.

◆ toInt()

template<class _T = unsigned>
_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.

Definition at line 257 of file RLP.h.

◆ toPair()

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

Definition at line 225 of file RLP.h.

◆ toPositiveInt64()

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

Definition at line 280 of file RLP.h.

◆ toSet()

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

Definition at line 201 of file RLP.h.

◆ toString()

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

Converts to string.

Returns
the empty string if not a string.

Definition at line 181 of file RLP.h.

◆ toStringStrict()

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

Converts to string.

Exceptions
BadCastif not a string.

Definition at line 183 of file RLP.h.

◆ toUnorderedSet()

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

Definition at line 213 of file RLP.h.

◆ toVector()

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

Definition at line 186 of file RLP.h.


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