Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
dev::RLP Class Reference

Class for interpreting Recursive Linear-Prefix Data. More...

#include <RLP.h>

Collaboration diagram for dev::RLP:
[legend]

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
 Subscript operator. More...
 
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 >
T convert (int _flags) const
 
 operator std::string () const
 Best-effort conversion operators. More...
 
 operator bytes () const
 
 operator RLPs () 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< TtoVector (int _flags=LaissezFaire) const
 
template<class T >
std::set< TtoSet (int _flags=LaissezFaire) const
 
template<class T >
std::unordered_set< TtoUnorderedSet (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 isString(), decodes as big-endian bytestream. More...
 
template<class _N >
_N toHash (int _flags=Strict) const
 
RLPs toList (int _flags=Strict) const
 Converts to RLPs collection object. Useful if you need random access to sub items or will iterate over multiple times. More...
 
bytesConstRef payload () const
 
size_t actualSize () const
 

Private Member Functions

 RLP (bytes const &&)
 Disable construction from rvalue. More...
 
void requireGood () const
 Throws if is non-canonical data (i.e. single byte done in two bytes that could be done in one). More...
 
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.

Gav Wood, 2013

Class for reading byte arrays of data in RLP format.

Definition at line 64 of file RLP.h.

Member Typedef Documentation

Definition at line 144 of file RLP.h.

using dev::RLP::Strictness = int

Definition at line 79 of file RLP.h.

Member Enumeration Documentation

anonymous enum

Conversion flags.

Enumerator
AllowNonCanon 
ThrowOnFail 
FailIfTooBig 
FailIfTooSmall 
Strict 
VeryStrict 
LaissezFaire 

Definition at line 68 of file RLP.h.

Constructor & Destructor Documentation

dev::RLP::RLP ( )
inline

Construct a null node.

Definition at line 82 of file RLP.h.

Here is the caller graph for this function:

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

Construct a node of value given in the bytes.

Definition at line 29 of file RLP.cpp.

Here is the call graph for this function:

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

Construct a node of value given in the bytes.

Definition at line 88 of file RLP.h.

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 91 of file RLP.h.

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

Construct a node to read RLP data in the string.

Definition at line 94 of file RLP.h.

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

Disable construction from rvalue.

Definition at line 329 of file RLP.h.

Member Function Documentation

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 108 of file RLP.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Definition at line 170 of file RLP.h.

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

Definition at line 378 of file RLP.h.

Here is the call graph for this function:

Here is the caller graph for this function:

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

The bare data of the RLP.

Definition at line 97 of file RLP.h.

Here is the caller graph for this function:

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

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

Definition at line 173 of file RLP.h.

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

String value.

Definition at line 109 of file RLP.h.

Here is the caller graph for this function:

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

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

Definition at line 106 of file RLP.h.

Here is the caller graph for this function:

bool RLP::isInt ( ) const

Integer value. Must not have a leading zero.

Definition at line 132 of file RLP.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

List value.

Definition at line 112 of file RLP.h.

Here is the caller graph for this function:

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

No value.

Definition at line 103 of file RLP.h.

Here is the caller graph for this function:

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

Single-byte data payload.

Definition at line 335 of file RLP.h.

Here is the caller graph for this function:

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 118 of file RLP.h.

Here is the caller graph for this function:

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

Definition at line 119 of file RLP.h.

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

Definition at line 217 of file RLP.cpp.

Here is the call graph for this function:

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.

Definition at line 159 of file RLP.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 338 of file RLP.h.

Here is the caller graph for this function:

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

Definition at line 187 of file RLP.h.

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

Definition at line 100 of file RLP.h.

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

Definition at line 179 of file RLP.h.

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

Definition at line 188 of file RLP.h.

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

Definition at line 180 of file RLP.h.

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

Definition at line 192 of file RLP.h.

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

Definition at line 189 of file RLP.h.

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

Definition at line 191 of file RLP.h.

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

Best-effort conversion operators.

Definition at line 178 of file RLP.h.

Here is the call graph for this function:

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

Definition at line 190 of file RLP.h.

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

Definition at line 185 of file RLP.h.

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

Definition at line 186 of file RLP.h.

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

Definition at line 182 of file RLP.h.

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

Definition at line 183 of file RLP.h.

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

Definition at line 184 of file RLP.h.

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

Definition at line 181 of file RLP.h.

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

Definition at line 127 of file RLP.h.

Here is the call graph for this function:

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

Definition at line 129 of file RLP.h.

Here is the call graph for this function:

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

Definition at line 131 of file RLP.h.

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

Definition at line 133 of file RLP.h.

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

Definition at line 135 of file RLP.h.

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

Definition at line 137 of file RLP.h.

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

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

Definition at line 126 of file RLP.h.

Here is the call graph for this function:

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

Definition at line 128 of file RLP.h.

Here is the call graph for this function:

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

Definition at line 130 of file RLP.h.

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

Definition at line 132 of file RLP.h.

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

Definition at line 134 of file RLP.h.

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

Definition at line 136 of file RLP.h.

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 76 of file RLP.cpp.

Here is the call graph for this function:

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

Definition at line 321 of file RLP.h.

Here is the caller graph for this function:

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

Definition at line 344 of file RLP.h.

Here is the caller graph for this function:

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

Definition at line 119 of file RLP.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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 122 of file RLP.h.

Here is the caller graph for this function:

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.

Definition at line 350 of file RLP.h.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 123 of file RLP.h.

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

Definition at line 259 of file RLP.h.

Here is the caller graph for this function:

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

Converts to bytearray.

Returns
the empty byte array if not a string.

Definition at line 195 of file RLP.h.

Here is the caller graph for this function:

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

Converts to bytearray.

Returns
the empty byte array if not a string.

Definition at line 197 of file RLP.h.

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

Definition at line 298 of file RLP.h.

Here is the call graph for this function:

Here is the caller graph for this function:

template<class _T = unsigned>
_T dev::RLP::toInt ( int  _flags = Strict) const
inline

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

Returns
0 if not an int or string.

Definition at line 275 of file RLP.h.

Here is the caller graph for this function:

RLPs RLP::toList ( int  _flags = Strict) const

Converts to RLPs collection object. Useful if you need random access to sub items or will iterate over multiple times.

Definition at line 93 of file RLP.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 243 of file RLP.h.

Here is the caller graph for this function:

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

Definition at line 219 of file RLP.h.

Here is the caller graph for this function:

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

Converts to string.

Returns
the empty string if not a string.

Definition at line 199 of file RLP.h.

Here is the caller graph for this function:

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

Converts to string.

Exceptions
BadCastif not a string.

Definition at line 201 of file RLP.h.

Here is the call graph for this function:

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

Definition at line 231 of file RLP.h.

Here is the caller graph for this function:

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

Definition at line 204 of file RLP.h.

Here is the caller graph for this function:

Member Data Documentation

bytesConstRef dev::RLP::m_data
private

Our byte data.

Definition at line 353 of file RLP.h.

size_t dev::RLP::m_lastEnd = 0
mutableprivate

Definition at line 357 of file RLP.h.

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

The list-indexing cache.

Definition at line 356 of file RLP.h.

bytesConstRef dev::RLP::m_lastItem
mutableprivate

Definition at line 358 of file RLP.h.


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