Ethereum  PoC-8
The C++ Implementation of Ethereum
RLP.h
Go to the documentation of this file.
1 /* Aleth: Ethereum C++ client, tools and libraries.
2  * Copyright 2018 Aleth Autors.
3  * Licensed under the GNU General Public License, Version 3. See the LICENSE file.
4  */
5 
11 #pragma once
12 
13 #include "Exceptions.h"
14 #include "FixedHash.h"
15 #include "vector_ref.h"
16 
17 #include <array>
18 #include <exception>
19 #include <iomanip>
20 #include <iosfwd>
21 #include <vector>
22 
23 namespace dev
24 {
25 
26 class RLP;
27 
28 template <class _T> struct intTraits { static const unsigned maxSize = sizeof(_T); };
29 template <> struct intTraits<u160> { static const unsigned maxSize = 20; };
30 template <> struct intTraits<u256> { static const unsigned maxSize = 32; };
31 template <> struct intTraits<bigint> { static const unsigned maxSize = ~(unsigned)0; };
32 
33 static const byte c_rlpMaxLengthBytes = 8;
34 static const byte c_rlpDataImmLenStart = 0x80;
35 static const byte c_rlpListStart = 0xc0;
36 
37 static const byte c_rlpDataImmLenCount = c_rlpListStart - c_rlpDataImmLenStart - c_rlpMaxLengthBytes;
38 static const byte c_rlpDataIndLenZero = c_rlpDataImmLenStart + c_rlpDataImmLenCount - 1;
39 static const byte c_rlpListImmLenCount = 256 - c_rlpListStart - c_rlpMaxLengthBytes;
40 static const byte c_rlpListIndLenZero = c_rlpListStart + c_rlpListImmLenCount - 1;
41 
42 template <class T> struct Converter { static T convert(RLP const&, int) { BOOST_THROW_EXCEPTION(BadCast()); } };
43 
47 class RLP
48 {
49 public:
51  enum
52  {
60  };
61 
62  using Strictness = int;
63 
65  RLP() {}
66 
68  explicit RLP(bytesConstRef _d, Strictness _s = VeryStrict);
69 
71  explicit RLP(bytes const& _d, Strictness _s = VeryStrict): RLP(&_d, _s) {}
72 
74  RLP(byte const* _b, unsigned _s, Strictness _st = VeryStrict): RLP(bytesConstRef(_b, _s), _st) {}
75 
77  explicit RLP(std::string const& _s, Strictness _st = VeryStrict): RLP(bytesConstRef((byte const*)_s.data(), _s.size()), _st) {}
78 
80  bytesConstRef data() const { return m_data; }
81 
83  explicit operator bool() const { return !isNull(); }
84 
86  bool isNull() const { return m_data.size() == 0; }
87 
89  bool isEmpty() const { return !isNull() && (m_data[0] == c_rlpDataImmLenStart || m_data[0] == c_rlpListStart); }
90 
92  bool isData() const { return !isNull() && m_data[0] < c_rlpListStart; }
93 
95  bool isList() const { return !isNull() && m_data[0] >= c_rlpListStart; }
96 
98  bool isInt() const;
99 
101  size_t itemCount() const { return isList() ? items() : 0; }
102  size_t itemCountStrict() const { if (!isList()) BOOST_THROW_EXCEPTION(BadCast()); return items(); }
103 
105  size_t size() const { return isData() ? length() : 0; }
106  size_t sizeStrict() const { if (!isData()) BOOST_THROW_EXCEPTION(BadCast()); return length(); }
107 
109  bool operator==(char const* _s) const { return isData() && toString() == _s; }
110  bool operator!=(char const* _s) const { return isData() && toString() != _s; }
111  bool operator==(std::string const& _s) const { return isData() && toString() == _s; }
112  bool operator!=(std::string const& _s) const { return isData() && toString() != _s; }
113  template <unsigned _N> bool operator==(FixedHash<_N> const& _h) const { return isData() && toHash<_N>() == _h; }
114  template <unsigned _N> bool operator!=(FixedHash<_N> const& _s) const { return isData() && toHash<_N>() != _s; }
115  bool operator==(unsigned const& _i) const { return isInt() && toInt<unsigned>() == _i; }
116  bool operator!=(unsigned const& _i) const { return isInt() && toInt<unsigned>() != _i; }
117  bool operator==(u256 const& _i) const { return isInt() && toInt<u256>() == _i; }
118  bool operator!=(u256 const& _i) const { return isInt() && toInt<u256>() != _i; }
119  bool operator==(bigint const& _i) const { return isInt() && toInt<bigint>() == _i; }
120  bool operator!=(bigint const& _i) const { return isInt() && toInt<bigint>() != _i; }
121 
125  RLP operator[](size_t _i) const;
126 
127  using element_type = RLP;
128 
130  class iterator
131  {
132  friend class RLP;
133 
134  public:
135  using value_type = RLP;
136  using element_type = RLP;
137 
138  iterator& operator++();
139  iterator operator++(int) { auto ret = *this; operator++(); return ret; }
140  RLP operator*() const { return RLP(m_currentItem); }
141  bool operator==(iterator const& _cmp) const { return m_currentItem == _cmp.m_currentItem; }
142  bool operator!=(iterator const& _cmp) const { return !operator==(_cmp); }
143 
144  private:
145  iterator() {}
146  iterator(RLP const& _parent, bool _begin);
147 
148  size_t m_remaining = 0;
149  bytesConstRef m_currentItem;
150  };
151 
153  iterator begin() const { return iterator(*this, true); }
154 
156  iterator end() const { return iterator(*this, false); }
157 
158  template <class T> inline T convert(int _flags) const;
159 
161  explicit operator std::string() const { return toString(); }
162  explicit operator bytes() const { return toBytes(); }
163  explicit operator uint8_t() const { return toInt<uint8_t>(); }
164  explicit operator uint16_t() const { return toInt<uint16_t>(); }
165  explicit operator uint32_t() const { return toInt<uint32_t>(); }
166  explicit operator uint64_t() const { return toInt<uint64_t>(); }
167  explicit operator u160() const { return toInt<u160>(); }
168  explicit operator u256() const { return toInt<u256>(); }
169  explicit operator bigint() const { return toInt<bigint>(); }
170  template <unsigned N> explicit operator FixedHash<N>() const { return toHash<FixedHash<N>>(); }
171  template <class T, class U> explicit operator std::pair<T, U>() const { return toPair<T, U>(); }
172  template <class T> explicit operator std::vector<T>() const { return toVector<T>(); }
173  template <class T> explicit operator std::set<T>() const { return toSet<T>(); }
174  template <class T, size_t N> explicit operator std::array<T, N>() const { return toArray<T, N>(); }
175 
177  bytes toBytes(int _flags = LaissezFaire) const { if (!isData()) { if (_flags & ThrowOnFail) BOOST_THROW_EXCEPTION(BadCast()); else return bytes(); } return bytes(payload().data(), payload().data() + length()); }
179  bytesConstRef toBytesConstRef(int _flags = LaissezFaire) const { if (!isData()) { if (_flags & ThrowOnFail) BOOST_THROW_EXCEPTION(BadCast()); else return bytesConstRef(); } return payload().cropped(0, length()); }
181  std::string toString(int _flags = LaissezFaire) const { if (!isData()) { if (_flags & ThrowOnFail) BOOST_THROW_EXCEPTION(BadCast()); else return std::string(); } return payload().cropped(0, length()).toString(); }
183  std::string toStringStrict() const { return toString(Strict); }
184 
185  template <class T>
186  std::vector<T> toVector(int _flags = LaissezFaire) const
187  {
188  std::vector<T> ret;
189  if (isList())
190  {
191  ret.reserve(itemCount());
192  for (auto const& i: *this)
193  ret.push_back(i.convert<T>(_flags));
194  }
195  else if (_flags & ThrowOnFail)
196  BOOST_THROW_EXCEPTION(BadCast());
197  return ret;
198  }
199 
200  template <class T>
201  std::set<T> toSet(int _flags = LaissezFaire) const
202  {
203  std::set<T> ret;
204  if (isList())
205  for (auto const& i: *this)
206  ret.insert(i.convert<T>(_flags));
207  else if (_flags & ThrowOnFail)
208  BOOST_THROW_EXCEPTION(BadCast());
209  return ret;
210  }
211 
212  template <class T>
213  std::unordered_set<T> toUnorderedSet(int _flags = LaissezFaire) const
214  {
215  std::unordered_set<T> ret;
216  if (isList())
217  for (auto const& i: *this)
218  ret.insert(i.convert<T>(_flags));
219  else if (_flags & ThrowOnFail)
220  BOOST_THROW_EXCEPTION(BadCast());
221  return ret;
222  }
223 
224  template <class T, class U>
225  std::pair<T, U> toPair(int _flags = Strict) const
226  {
227  std::pair<T, U> ret;
228  if (itemCountStrict() != 2)
229  {
230  if (_flags & ThrowOnFail)
231  BOOST_THROW_EXCEPTION(BadCast());
232  else
233  return ret;
234  }
235  ret.first = (*this)[0].convert<T>(_flags);
236  ret.second = (*this)[1].convert<U>(_flags);
237  return ret;
238  }
239 
240  template <class T, size_t N>
241  std::array<T, N> toArray(int _flags = LaissezFaire) const
242  {
243  if (itemCountStrict() != N)
244  {
245  if (_flags & ThrowOnFail)
246  BOOST_THROW_EXCEPTION(BadCast());
247  else
248  return std::array<T, N>();
249  }
250  std::array<T, N> ret;
251  for (size_t i = 0; i < N; ++i)
252  ret[i] = operator[](i).convert<T>(_flags);
253  return ret;
254  }
255 
257  template <class _T = unsigned> _T toInt(int _flags = Strict) const
258  {
259  requireGood();
260  if ((!isInt() && !(_flags & AllowNonCanon)) || isList() || isNull())
261  {
262  if (_flags & ThrowOnFail)
263  BOOST_THROW_EXCEPTION(BadCast());
264  else
265  return 0;
266  }
267 
268  auto p = payload();
269  if (p.size() > intTraits<_T>::maxSize && (_flags & FailIfTooBig))
270  {
271  if (_flags & ThrowOnFail)
272  BOOST_THROW_EXCEPTION(BadCast());
273  else
274  return 0;
275  }
276 
277  return fromBigEndian<_T>(p);
278  }
279 
280  int64_t toPositiveInt64(int _flags = Strict) const
281  {
282  int64_t i = toInt<int64_t>(_flags);
283  if ((_flags & ThrowOnFail) && i < 0)
284  BOOST_THROW_EXCEPTION(BadCast());
285  return i;
286  }
287 
288  template <class _N> _N toHash(int _flags = Strict) const
289  {
290  requireGood();
291  auto p = payload();
292  auto l = p.size();
293  if (!isData() || (l > _N::size && (_flags & FailIfTooBig)) || (l < _N::size && (_flags & FailIfTooSmall)))
294  {
295  if (_flags & ThrowOnFail)
296  BOOST_THROW_EXCEPTION(BadCast());
297  else
298  return _N();
299  }
300 
301  _N ret;
302  size_t s = std::min<size_t>(_N::size, l);
303  memcpy(ret.data() + _N::size - s, p.data(), s);
304  return ret;
305  }
306 
308  bytesConstRef payload() const { auto l = length(); if (l > m_data.size()) BOOST_THROW_EXCEPTION(BadRLP()); return m_data.cropped(payloadOffset(), l); }
309 
312  size_t actualSize() const;
313 
314 private:
316  explicit RLP(bytes const&&) {}
317 
319  void requireGood() const;
320 
322  bool isSingleByte() const { return !isNull() && m_data[0] < c_rlpDataImmLenStart; }
323 
325  unsigned lengthSize() const { if (isData() && m_data[0] > c_rlpDataIndLenZero) return m_data[0] - c_rlpDataIndLenZero; if (isList() && m_data[0] > c_rlpListIndLenZero) return m_data[0] - c_rlpListIndLenZero; return 0; }
326 
328  size_t length() const;
329 
331  size_t payloadOffset() const { return isSingleByte() ? 0 : (1 + lengthSize()); }
332 
334  size_t items() const;
335 
337  static size_t sizeAsEncoded(bytesConstRef _data) { return RLP(_data, ThrowOnFail | FailIfTooSmall).actualSize(); }
338 
340  bytesConstRef m_data;
341 
343  mutable size_t m_lastIndex = (size_t)-1;
344  mutable size_t m_lastEnd = 0;
345  mutable bytesConstRef m_lastItem;
346 };
347 
348 template <> struct Converter<std::string> { static std::string convert(RLP const& _r, int _flags) { return _r.toString(_flags); } };
349 template <> struct Converter<bytes> { static bytes convert(RLP const& _r, int _flags) { return _r.toBytes(_flags); } };
350 template <> struct Converter<uint8_t> { static uint8_t convert(RLP const& _r, int _flags) { return _r.toInt<uint8_t>(_flags); } };
351 template <> struct Converter<uint16_t> { static uint16_t convert(RLP const& _r, int _flags) { return _r.toInt<uint16_t>(_flags); } };
352 template <> struct Converter<uint32_t> { static uint32_t convert(RLP const& _r, int _flags) { return _r.toInt<uint32_t>(_flags); } };
353 template <> struct Converter<uint64_t> { static uint64_t convert(RLP const& _r, int _flags) { return _r.toInt<uint64_t>(_flags); } };
354 template <> struct Converter<u160> { static u160 convert(RLP const& _r, int _flags) { return _r.toInt<u160>(_flags); } };
355 template <> struct Converter<u256> { static u256 convert(RLP const& _r, int _flags) { return _r.toInt<u256>(_flags); } };
356 template <> struct Converter<bigint> { static bigint convert(RLP const& _r, int _flags) { return _r.toInt<bigint>(_flags); } };
357 template <unsigned N> struct Converter<FixedHash<N>> { static FixedHash<N> convert(RLP const& _r, int _flags) { return _r.toHash<FixedHash<N>>(_flags); } };
358 template <class T, class U> struct Converter<std::pair<T, U>> { static std::pair<T, U> convert(RLP const& _r, int _flags) { return _r.toPair<T, U>(_flags); } };
359 template <class T> struct Converter<std::vector<T>> { static std::vector<T> convert(RLP const& _r, int _flags) { return _r.toVector<T>(_flags); } };
360 template <class T> struct Converter<std::set<T>> { static std::set<T> convert(RLP const& _r, int _flags) { return _r.toSet<T>(_flags); } };
361 template <class T> struct Converter<std::unordered_set<T>> { static std::unordered_set<T> convert(RLP const& _r, int _flags) { return _r.toUnorderedSet<T>(_flags); } };
362 template <class T, size_t N> struct Converter<std::array<T, N>> { static std::array<T, N> convert(RLP const& _r, int _flags) { return _r.toArray<T, N>(_flags); } };
363 
364 template <class T> inline T RLP::convert(int _flags) const { return Converter<T>::convert(*this, _flags); }
365 
370 {
371 public:
374 
376  explicit RLPStream(size_t _listItems) { appendList(_listItems); }
377 
379 
381  RLPStream& append(unsigned _s) { return append(bigint(_s)); }
382  RLPStream& append(u160 _s) { return append(bigint(_s)); }
383  RLPStream& append(u256 _s) { return append(bigint(_s)); }
384  RLPStream& append(bigint _s);
385  RLPStream& append(bytesConstRef _s, bool _compact = false);
386  RLPStream& append(bytes const& _s) { return append(bytesConstRef(&_s)); }
387  RLPStream& append(std::string const& _s) { return append(bytesConstRef(_s)); }
388  RLPStream& append(char const* _s) { return append(std::string(_s)); }
389  template <unsigned N> RLPStream& append(FixedHash<N> _s, bool _compact = false, bool _allOrNothing = false) { return _allOrNothing && !_s ? append(bytesConstRef()) : append(_s.ref(), _compact); }
390 
392  RLPStream& append(RLP const& _rlp, size_t _itemCount = 1) { return appendRaw(_rlp.data(), _itemCount); }
393 
395  template <class _T> RLPStream& append(std::vector<_T> const& _s) { return appendVector(_s); }
396  template <class _T> RLPStream& appendVector(std::vector<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
397  template <class _T, size_t S> RLPStream& append(std::array<_T, S> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
398  template <class _T> RLPStream& append(std::set<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
399  template <class _T> RLPStream& append(std::unordered_set<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
400  template <class T, class U> RLPStream& append(std::pair<T, U> const& _s) { appendList(2); append(_s.first); append(_s.second); return *this; }
401 
403  RLPStream& appendList(size_t _items);
405  RLPStream& appendList(bytes const& _rlp) { return appendList(&_rlp); }
406  RLPStream& appendList(RLPStream const& _s) { return appendList(&_s.out()); }
407 
409  RLPStream& appendRaw(bytesConstRef _rlp, size_t _itemCount = 1);
410  RLPStream& appendRaw(bytes const& _rlp, size_t _itemCount = 1) { return appendRaw(&_rlp, _itemCount); }
411 
413  template <class T> RLPStream& operator<<(T _data) { return append(_data); }
414 
416  void clear() { m_out.clear(); m_listStack.clear(); }
417 
419  bytes const& out() const { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); return m_out; }
420 
422  bytes&& invalidate() { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); return std::move(m_out); }
423 
425  void swapOut(bytes& _dest) { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); swap(m_out, _dest); }
426 
427 private:
428  void noteAppended(size_t _itemCount = 1);
429 
432  void pushCount(size_t _count, byte _offset);
433 
435  template <class _T> void pushInt(_T _i, size_t _br)
436  {
437  m_out.resize(m_out.size() + _br);
438  byte* b = &m_out.back();
439  for (; _i; _i >>= 8)
440  *(b--) = (byte)(_i & 0xff);
441  }
442 
444  bytes m_out;
445 
446  std::vector<std::pair<size_t, size_t>> m_listStack;
447 };
448 
449 template <class _T> void rlpListAux(RLPStream& _out, _T _t) { _out << _t; }
450 template <class _T, class ... _Ts> void rlpListAux(RLPStream& _out, _T _t, _Ts ... _ts) { rlpListAux(_out << _t, _ts...); }
451 
453 template <class _T> bytes rlp(_T _t) { return (RLPStream() << _t).out(); }
454 
456 inline bytes rlpList() { return RLPStream(0).out(); }
457 template <class ... _Ts> bytes rlpList(_Ts ... _ts)
458 {
459  RLPStream out(sizeof ...(_Ts));
460  rlpListAux(out, _ts...);
461  return out.out();
462 }
463 
465 extern bytes RLPNull;
466 
468 extern bytes RLPEmptyList;
469 
471 std::ostream& operator<<(std::ostream& _out, dev::RLP const& _d);
472 
473 }
dev::RLPStream::appendList
RLPStream & appendList(RLPStream const &_s)
Definition: RLP.h:406
dev::Converter< FixedHash< N > >::convert
static FixedHash< N > convert(RLP const &_r, int _flags)
Definition: RLP.h:357
dev::Converter
Definition: RLP.h:42
dev::RLP::operator==
bool operator==(std::string const &_s) const
Definition: RLP.h:111
dev::RLP::toPair
std::pair< T, U > toPair(int _flags=Strict) const
Definition: RLP.h:225
dev::intTraits
Definition: RLP.h:28
dev::RLPStream::append
RLPStream & append(u160 _s)
Definition: RLP.h:382
dev::RLP::VeryStrict
@ VeryStrict
Definition: RLP.h:58
dev::RLPStream::append
RLPStream & append(std::pair< T, U > const &_s)
Definition: RLP.h:400
dev::RLP::operator!=
bool operator!=(unsigned const &_i) const
Definition: RLP.h:116
dev::Converter< bigint >::convert
static bigint convert(RLP const &_r, int _flags)
Definition: RLP.h:356
dev::Converter< uint32_t >::convert
static uint32_t convert(RLP const &_r, int _flags)
Definition: RLP.h:352
dev::Converter< std::string >::convert
static std::string convert(RLP const &_r, int _flags)
Definition: RLP.h:348
dev::Converter< u256 >::convert
static u256 convert(RLP const &_r, int _flags)
Definition: RLP.h:355
dev::vector_ref< byte const >
byte
uint8_t byte
Definition: Common.h:57
dev::RLP::RLP
RLP(byte const *_b, unsigned _s, Strictness _st=VeryStrict)
Construct a node to read RLP data in the bytes given.
Definition: RLP.h:74
dev::RLPStream::append
RLPStream & append(RLP const &_rlp, size_t _itemCount=1)
Appends an arbitrary RLP fragment - this must be a single item unless _itemCount is given.
Definition: RLP.h:392
dev::RLPStream::~RLPStream
~RLPStream()
Definition: RLP.h:378
dev::RLPStream::RLPStream
RLPStream(size_t _listItems)
Initializes the RLPStream as a list of _listItems items.
Definition: RLP.h:376
dev::RLP::operator!=
bool operator!=(std::string const &_s) const
Definition: RLP.h:112
dev::RLP::iterator::operator++
iterator & operator++()
Definition: RLP.cpp:55
dev::rlpListAux
void rlpListAux(RLPStream &_out, _T _t)
Definition: RLP.h:449
FixedHash.h
dev::FixedHash::ref
bytesRef ref()
Definition: FixedHash.h:132
std::swap
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
Definition: Interface.h:282
dev::RLP::Strictness
int Strictness
Definition: RLP.h:62
dev::RLPStream::append
RLPStream & append(std::array< _T, S > const &_s)
Definition: RLP.h:397
dev::Converter< std::set< T > >::convert
static std::set< T > convert(RLP const &_r, int _flags)
Definition: RLP.h:360
dev::RLPStream::out
bytes const & out() const
Read the byte stream.
Definition: RLP.h:419
Exceptions.h
dev::intTraits::maxSize
static const unsigned maxSize
Definition: RLP.h:28
dev::RLP::isData
bool isData() const
String value.
Definition: RLP.h:92
dev::RLPException
Base class for all RLP exceptions.
Definition: Exceptions.h:50
dev::RLP::actualSize
size_t actualSize() const
Definition: RLP.cpp:100
dev::RLP::begin
iterator begin() const
Iterator into beginning of sub-item list (valid only if we are a list).
Definition: RLP.h:153
dev::rlp
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
Definition: RLP.h:453
dev::RLP::isList
bool isList() const
List value.
Definition: RLP.h:95
dev::Converter< std::array< T, N > >::convert
static std::array< T, N > convert(RLP const &_r, int _flags)
Definition: RLP.h:362
dev::FixedHash
Definition: FixedHash.h:47
dev::Converter< bytes >::convert
static bytes convert(RLP const &_r, int _flags)
Definition: RLP.h:349
dev::RLP::isNull
bool isNull() const
No value.
Definition: RLP.h:86
dev::RLP::iterator::RLP
friend class RLP
Definition: RLP.h:132
dev::RLP::Strict
@ Strict
Definition: RLP.h:57
dev::RLP::sizeStrict
size_t sizeStrict() const
Definition: RLP.h:106
dev::operator<<
std::ostream & operator<<(std::ostream &_out, bytes const &_e)
Definition: CommonIO.h:77
dev::RLP::operator==
bool operator==(bigint const &_i) const
Definition: RLP.h:119
dev::RLP::iterator::operator==
bool operator==(iterator const &_cmp) const
Definition: RLP.h:141
dev::RLP::iterator::operator*
RLP operator*() const
Definition: RLP.h:140
dev::RLP::AllowNonCanon
@ AllowNonCanon
Definition: RLP.h:53
dev::RLP::toVector
std::vector< T > toVector(int _flags=LaissezFaire) const
Definition: RLP.h:186
dev::RLP::size
size_t size() const
Definition: RLP.h:105
dev::Converter< uint16_t >::convert
static uint16_t convert(RLP const &_r, int _flags)
Definition: RLP.h:351
dev::RLPStream::appendVector
RLPStream & appendVector(std::vector< _T > const &_s)
Definition: RLP.h:396
dev::RLPStream::append
RLPStream & append(std::set< _T > const &_s)
Definition: RLP.h:398
dev::RLP::operator!=
bool operator!=(char const *_s) const
Definition: RLP.h:110
dev::RLPStream::clear
void clear()
Clear the output stream so far.
Definition: RLP.h:416
dev::Converter::convert
static T convert(RLP const &, int)
Definition: RLP.h:42
dev::RLP::toBytesConstRef
bytesConstRef toBytesConstRef(int _flags=LaissezFaire) const
Converts to bytearray.
Definition: RLP.h:179
dev::RLPStream::append
RLPStream & append(bytes const &_s)
Definition: RLP.h:386
dev::RLP::operator!=
bool operator!=(bigint const &_i) const
Definition: RLP.h:120
dev::RLP::operator==
bool operator==(char const *_s) const
Equality operators; does best-effort conversion and checks for equality.
Definition: RLP.h:109
dev::RLPStream::appendRaw
RLPStream & appendRaw(bytes const &_rlp, size_t _itemCount=1)
Definition: RLP.h:410
dev::vector_ref::cropped
vector_ref< _T > cropped(size_t _begin, size_t _count) const
Definition: vector_ref.h:60
dev::RLP::RLP
RLP(bytes const &_d, Strictness _s=VeryStrict)
Construct a node of value given in the bytes.
Definition: RLP.h:71
dev::RLPStream::append
RLPStream & append(std::unordered_set< _T > const &_s)
Definition: RLP.h:399
dev::RLP::isInt
bool isInt() const
Integer value. Must not have a leading zero.
Definition: RLP.cpp:124
dev::bytes
std::vector< byte > bytes
Definition: Common.h:72
dev::RLP::RLP
RLP()
Construct a null node.
Definition: RLP.h:65
dev::vector_ref::toString
std::string toString() const
Definition: vector_ref.h:44
dev::RLPStream::append
RLPStream & append(FixedHash< N > _s, bool _compact=false, bool _allOrNothing=false)
Definition: RLP.h:389
dev::bytesConstRef
vector_ref< byte const > bytesConstRef
Definition: Common.h:74
dev::Converter< u160 >::convert
static u160 convert(RLP const &_r, int _flags)
Definition: RLP.h:354
dev::RLP::toString
std::string toString(int _flags=LaissezFaire) const
Converts to string.
Definition: RLP.h:181
dev::RLP::LaissezFaire
@ LaissezFaire
Definition: RLP.h:59
dev::RLP::operator==
bool operator==(FixedHash< _N > const &_h) const
Definition: RLP.h:113
dev::u160
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 160, 160, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u160
Definition: Common.h:123
dev::RLP::end
iterator end() const
Iterator into end of sub-item list (valid only if we are a list).
Definition: RLP.h:156
dev::Converter< std::vector< T > >::convert
static std::vector< T > convert(RLP const &_r, int _flags)
Definition: RLP.h:359
dev::RLP::operator!=
bool operator!=(FixedHash< _N > const &_s) const
Definition: RLP.h:114
dev::RLPStream::appendList
RLPStream & appendList(bytes const &_rlp)
Definition: RLP.h:405
dev::vector_ref::size
size_t size() const
Definition: vector_ref.h:53
dev::RLP::toArray
std::array< T, N > toArray(int _flags=LaissezFaire) const
Definition: RLP.h:241
dev::RLP::toUnorderedSet
std::unordered_set< T > toUnorderedSet(int _flags=LaissezFaire) const
Definition: RLP.h:213
dev::RLP::data
bytesConstRef data() const
The bare data of the RLP.
Definition: RLP.h:80
dev::RLPStream::append
RLPStream & append(std::string const &_s)
Definition: RLP.h:387
dev::RLPStream::append
RLPStream & append(char const *_s)
Definition: RLP.h:388
dev::RLP::payload
bytesConstRef payload() const
Definition: RLP.h:308
dev::RLPStream
Class for writing to an RLP bytestream.
Definition: RLP.h:370
vector_ref.h
dev::Converter< uint8_t >::convert
static uint8_t convert(RLP const &_r, int _flags)
Definition: RLP.h:350
dev::RLPStream::append
RLPStream & append(unsigned _s)
Append given datum to the byte stream.
Definition: RLP.h:381
dev::RLPNull
bytes RLPNull
The empty string in RLP format.
Definition: RLP.cpp:22
dev::RLP::toSet
std::set< T > toSet(int _flags=LaissezFaire) const
Definition: RLP.h:201
dev::RLP::iterator::operator++
iterator operator++(int)
Definition: RLP.h:139
dev::bigint
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<> > bigint
Definition: Common.h:118
dev::RLP::convert
T convert(int _flags) const
Definition: RLP.h:364
dev::RLPStream::invalidate
bytes && invalidate()
Invalidate the object and steal the output byte stream.
Definition: RLP.h:422
dev::RLP::operator!=
bool operator!=(u256 const &_i) const
Definition: RLP.h:118
dev::RLP::FailIfTooBig
@ FailIfTooBig
Definition: RLP.h:55
dev::RLP::itemCount
size_t itemCount() const
Definition: RLP.h:101
std
Definition: FixedHash.h:393
dev::RLP::operator[]
RLP operator[](size_t _i) const
Definition: RLP.cpp:83
dev::u256
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
Definition: Common.h:121
dev::RLP::toInt
_T toInt(int _flags=Strict) const
Converts to int of type given; if isData(), decodes as big-endian bytestream.
Definition: RLP.h:257
dev::RLP::iterator::operator!=
bool operator!=(iterator const &_cmp) const
Definition: RLP.h:142
dev::RLP::toHash
_N toHash(int _flags=Strict) const
Definition: RLP.h:288
dev::RLP::iterator
Iterator class for iterating through items of RLP list.
Definition: RLP.h:131
dev::RLP::itemCountStrict
size_t itemCountStrict() const
Definition: RLP.h:102
dev::RLPStream::swapOut
void swapOut(bytes &_dest)
Swap the contents of the output stream out for some other byte array.
Definition: RLP.h:425
dev
Definition: Address.cpp:21
dev::RLP::toStringStrict
std::string toStringStrict() const
Converts to string.
Definition: RLP.h:183
dev::rlpList
bytes rlpList()
Export a list of items in RLP format, returning a byte array.
Definition: RLP.h:456
dev::RLPStream::operator<<
RLPStream & operator<<(T _data)
Shift operators for appending data items.
Definition: RLP.h:413
dev::RLP::ThrowOnFail
@ ThrowOnFail
Definition: RLP.h:54
dev::RLP::FailIfTooSmall
@ FailIfTooSmall
Definition: RLP.h:56
dev::RLP::operator==
bool operator==(u256 const &_i) const
Definition: RLP.h:117
dev::RLP::operator==
bool operator==(unsigned const &_i) const
Definition: RLP.h:115
dev::RLP::toPositiveInt64
int64_t toPositiveInt64(int _flags=Strict) const
Definition: RLP.h:280
dev::RLPStream::appendRaw
RLPStream & appendRaw(bytesConstRef _rlp, size_t _itemCount=1)
Appends raw (pre-serialised) RLP data. Use with caution.
Definition: RLP.cpp:222
dev::Converter< std::unordered_set< T > >::convert
static std::unordered_set< T > convert(RLP const &_r, int _flags)
Definition: RLP.h:361
dev::RLPStream::append
RLPStream & append(std::vector< _T > const &_s)
Appends a sequence of data to the stream as a list.
Definition: RLP.h:395
dev::RLP::RLP
RLP(std::string const &_s, Strictness _st=VeryStrict)
Construct a node to read RLP data in the string.
Definition: RLP.h:77
dev::RLPStream::append
RLPStream & append(u256 _s)
Definition: RLP.h:383
dev::Converter< std::pair< T, U > >::convert
static std::pair< T, U > convert(RLP const &_r, int _flags)
Definition: RLP.h:358
dev::RLP
Definition: RLP.h:48
dev::RLPEmptyList
bytes RLPEmptyList
The empty list in RLP format.
Definition: RLP.cpp:23
dev::RLP::isEmpty
bool isEmpty() const
Contains a zero-length string or zero-length list.
Definition: RLP.h:89
dev::RLPStream::appendList
RLPStream & appendList(size_t _items)
Appends a list.
Definition: RLP.cpp:268
dev::Converter< uint64_t >::convert
static uint64_t convert(RLP const &_r, int _flags)
Definition: RLP.h:353
dev::errinfo_comment
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition: Assertions.h:69
dev::RLP::toBytes
bytes toBytes(int _flags=LaissezFaire) const
Converts to bytearray.
Definition: RLP.h:177
dev::RLPStream::RLPStream
RLPStream()
Initializes empty RLPStream.
Definition: RLP.h:373