Fabcoin Core  0.16.2
P2P Digital Currency
RLP.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
24 #pragma once
25 
26 #include <vector>
27 #include <array>
28 #include <exception>
29 #include <iostream>
30 #include <iomanip>
31 #include "vector_ref.h"
32 #include "Common.h"
33 #include "Exceptions.h"
34 #include "FixedHash.h"
35 
36 namespace dev
37 {
38 
39 class RLP;
40 using RLPs = std::vector<RLP>;
41 
42 template <class _T> struct intTraits { static const unsigned maxSize = sizeof(_T); };
43 template <> struct intTraits<u160> { static const unsigned maxSize = 20; };
44 template <> struct intTraits<u256> { static const unsigned maxSize = 32; };
45 template <> struct intTraits<bigint> { static const unsigned maxSize = ~(unsigned)0; };
46 
47 static const byte c_rlpMaxLengthBytes = 8;
48 static const byte c_rlpDataImmLenStart = 0x80;
49 static const byte c_rlpListStart = 0xc0;
50 
51 static const byte c_rlpDataImmLenCount = c_rlpListStart - c_rlpDataImmLenStart - c_rlpMaxLengthBytes;
52 static const byte c_rlpDataIndLenZero = c_rlpDataImmLenStart + c_rlpDataImmLenCount - 1;
53 static const byte c_rlpListImmLenCount = 256 - c_rlpListStart - c_rlpMaxLengthBytes;
54 static const byte c_rlpListIndLenZero = c_rlpListStart + c_rlpListImmLenCount - 1;
55 
56 template <class T> struct Converter { static T convert(RLP const&, int) { BOOST_THROW_EXCEPTION(BadCast()); } };
57 
64 class RLP
65 {
66 public:
68  enum
69  {
70  AllowNonCanon = 1,
71  ThrowOnFail = 4,
72  FailIfTooBig = 8,
73  FailIfTooSmall = 16,
74  Strict = ThrowOnFail | FailIfTooBig,
75  VeryStrict = ThrowOnFail | FailIfTooBig | FailIfTooSmall,
76  LaissezFaire = AllowNonCanon
77  };
78 
79  using Strictness = int;
80 
82  RLP() {}
83 
85  explicit RLP(bytesConstRef _d, Strictness _s = VeryStrict);
86 
88  explicit RLP(bytes const& _d, Strictness _s = VeryStrict): RLP(&_d, _s) {}
89 
91  RLP(byte const* _b, unsigned _s, Strictness _st = VeryStrict): RLP(bytesConstRef(_b, _s), _st) {}
92 
94  explicit RLP(std::string const& _s, Strictness _st = VeryStrict): RLP(bytesConstRef((byte const*)_s.data(), _s.size()), _st) {}
95 
97  bytesConstRef data() const { return m_data; }
98 
100  explicit operator bool() const { return !isNull(); }
101 
103  bool isNull() const { return m_data.size() == 0; }
104 
106  bool isEmpty() const { return !isNull() && (m_data[0] == c_rlpDataImmLenStart || m_data[0] == c_rlpListStart); }
107 
109  bool isData() const { return !isNull() && m_data[0] < c_rlpListStart; }
110 
112  bool isList() const { return !isNull() && m_data[0] >= c_rlpListStart; }
113 
115  bool isInt() const;
116 
118  size_t itemCount() const { return isList() ? items() : 0; }
119  size_t itemCountStrict() const { if (!isList()) BOOST_THROW_EXCEPTION(BadCast()); return items(); }
120 
122  size_t size() const { return isData() ? length() : 0; }
123  size_t sizeStrict() const { if (!isData()) BOOST_THROW_EXCEPTION(BadCast()); return length(); }
124 
126  bool operator==(char const* _s) const { return isData() && toString() == _s; }
127  bool operator!=(char const* _s) const { return isData() && toString() != _s; }
128  bool operator==(std::string const& _s) const { return isData() && toString() == _s; }
129  bool operator!=(std::string const& _s) const { return isData() && toString() != _s; }
130  template <unsigned _N> bool operator==(FixedHash<_N> const& _h) const { return isData() && toHash<_N>() == _h; }
131  template <unsigned _N> bool operator!=(FixedHash<_N> const& _s) const { return isData() && toHash<_N>() != _s; }
132  bool operator==(unsigned const& _i) const { return isInt() && toInt<unsigned>() == _i; }
133  bool operator!=(unsigned const& _i) const { return isInt() && toInt<unsigned>() != _i; }
134  bool operator==(u256 const& _i) const { return isInt() && toInt<u256>() == _i; }
135  bool operator!=(u256 const& _i) const { return isInt() && toInt<u256>() != _i; }
136  bool operator==(bigint const& _i) const { return isInt() && toInt<bigint>() == _i; }
137  bool operator!=(bigint const& _i) const { return isInt() && toInt<bigint>() != _i; }
138 
142  RLP operator[](size_t _i) const;
143 
144  using element_type = RLP;
145 
147  class iterator
148  {
149  friend class RLP;
150 
151  public:
152  using value_type = RLP;
153  using element_type = RLP;
154 
155  iterator& operator++();
156  iterator operator++(int) { auto ret = *this; operator++(); return ret; }
157  RLP operator*() const { return RLP(m_currentItem); }
158  bool operator==(iterator const& _cmp) const { return m_currentItem == _cmp.m_currentItem; }
159  bool operator!=(iterator const& _cmp) const { return !operator==(_cmp); }
160 
161  private:
162  iterator() {}
163  iterator(RLP const& _parent, bool _begin);
164 
165  size_t m_remaining = 0;
167  };
168 
170  iterator begin() const { return iterator(*this, true); }
171 
173  iterator end() const { return iterator(*this, false); }
174 
175  template <class T> inline T convert(int _flags) const;
176 
178  explicit operator std::string() const { return toString(); }
179  explicit operator bytes() const { return toBytes(); }
180  explicit operator RLPs() const { return toList(); }
181  explicit operator uint8_t() const { return toInt<uint8_t>(); }
182  explicit operator uint16_t() const { return toInt<uint16_t>(); }
183  explicit operator uint32_t() const { return toInt<uint32_t>(); }
184  explicit operator uint64_t() const { return toInt<uint64_t>(); }
185  explicit operator u160() const { return toInt<u160>(); }
186  explicit operator u256() const { return toInt<u256>(); }
187  explicit operator bigint() const { return toInt<bigint>(); }
188  template <unsigned N> explicit operator FixedHash<N>() const { return toHash<FixedHash<N>>(); }
189  template <class T, class U> explicit operator std::pair<T, U>() const { return toPair<T, U>(); }
190  template <class T> explicit operator std::vector<T>() const { return toVector<T>(); }
191  template <class T> explicit operator std::set<T>() const { return toSet<T>(); }
192  template <class T, size_t N> explicit operator std::array<T, N>() const { return toArray<T, N>(); }
193 
195  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()); }
197  bytesConstRef toBytesConstRef(int _flags = LaissezFaire) const { if (!isData()) { if (_flags & ThrowOnFail) BOOST_THROW_EXCEPTION(BadCast()); else return bytesConstRef(); } return payload().cropped(0, length()); }
199  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(); }
201  std::string toStringStrict() const { return toString(Strict); }
202 
203  template <class T>
204  std::vector<T> toVector(int _flags = LaissezFaire) const
205  {
206  std::vector<T> ret;
207  if (isList())
208  {
209  ret.reserve(itemCount());
210  for (auto const& i: *this)
211  ret.push_back(i.convert<T>(_flags));
212  }
213  else if (_flags & ThrowOnFail)
214  BOOST_THROW_EXCEPTION(BadCast());
215  return ret;
216  }
217 
218  template <class T>
219  std::set<T> toSet(int _flags = LaissezFaire) const
220  {
221  std::set<T> ret;
222  if (isList())
223  for (auto const& i: *this)
224  ret.insert(i.convert<T>(_flags));
225  else if (_flags & ThrowOnFail)
226  BOOST_THROW_EXCEPTION(BadCast());
227  return ret;
228  }
229 
230  template <class T>
231  std::unordered_set<T> toUnorderedSet(int _flags = LaissezFaire) const
232  {
233  std::unordered_set<T> ret;
234  if (isList())
235  for (auto const& i: *this)
236  ret.insert(i.convert<T>(_flags));
237  else if (_flags & ThrowOnFail)
238  BOOST_THROW_EXCEPTION(BadCast());
239  return ret;
240  }
241 
242  template <class T, class U>
243  std::pair<T, U> toPair(int _flags = Strict) const
244  {
245  std::pair<T, U> ret;
246  if (itemCountStrict() != 2)
247  {
248  if (_flags & ThrowOnFail)
249  BOOST_THROW_EXCEPTION(BadCast());
250  else
251  return ret;
252  }
253  ret.first = (*this)[0].convert<T>(_flags);
254  ret.second = (*this)[1].convert<U>(_flags);
255  return ret;
256  }
257 
258  template <class T, size_t N>
259  std::array<T, N> toArray(int _flags = LaissezFaire) const
260  {
261  if (itemCountStrict() != N)
262  {
263  if (_flags & ThrowOnFail)
264  BOOST_THROW_EXCEPTION(BadCast());
265  else
266  return std::array<T, N>();
267  }
268  std::array<T, N> ret;
269  for (size_t i = 0; i < N; ++i)
270  ret[i] = operator[](i).convert<T>(_flags);
271  return ret;
272  }
273 
275  template <class _T = unsigned> _T toInt(int _flags = Strict) const
276  {
277  requireGood();
278  if ((!isInt() && !(_flags & AllowNonCanon)) || isList() || isNull())
279  {
280  if (_flags & ThrowOnFail)
281  BOOST_THROW_EXCEPTION(BadCast());
282  else
283  return 0;
284  }
285 
286  auto p = payload();
287  if (p.size() > intTraits<_T>::maxSize && (_flags & FailIfTooBig))
288  {
289  if (_flags & ThrowOnFail)
290  BOOST_THROW_EXCEPTION(BadCast());
291  else
292  return 0;
293  }
294 
295  return fromBigEndian<_T>(p);
296  }
297 
298  template <class _N> _N toHash(int _flags = Strict) const
299  {
300  requireGood();
301  auto p = payload();
302  auto l = p.size();
303  if (!isData() || (l > _N::size && (_flags & FailIfTooBig)) || (l < _N::size && (_flags & FailIfTooSmall)))
304  {
305  if (_flags & ThrowOnFail)
306  BOOST_THROW_EXCEPTION(BadCast());
307  else
308  return _N();
309  }
310 
311  _N ret;
312  size_t s = std::min<size_t>(_N::size, l);
313  memcpy(ret.data() + _N::size - s, p.data(), s);
314  return ret;
315  }
316 
318  RLPs toList(int _flags = Strict) const;
319 
321  bytesConstRef payload() const { auto l = length(); if (l > m_data.size()) BOOST_THROW_EXCEPTION(BadRLP()); return m_data.cropped(payloadOffset(), l); }
322 
325  size_t actualSize() const;
326 
327 private:
329  explicit RLP(bytes const&&) {}
330 
332  void requireGood() const;
333 
335  bool isSingleByte() const { return !isNull() && m_data[0] < c_rlpDataImmLenStart; }
336 
338  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; }
339 
341  size_t length() const;
342 
344  size_t payloadOffset() const { return isSingleByte() ? 0 : (1 + lengthSize()); }
345 
347  size_t items() const;
348 
350  static size_t sizeAsEncoded(bytesConstRef _data) { return RLP(_data, ThrowOnFail | FailIfTooSmall).actualSize(); }
351 
354 
356  mutable size_t m_lastIndex = (size_t)-1;
357  mutable size_t m_lastEnd = 0;
359 };
360 
361 template <> struct Converter<std::string> { static std::string convert(RLP const& _r, int _flags) { return _r.toString(_flags); } };
362 template <> struct Converter<bytes> { static bytes convert(RLP const& _r, int _flags) { return _r.toBytes(_flags); } };
363 template <> struct Converter<RLPs> { static RLPs convert(RLP const& _r, int _flags) { return _r.toList(_flags); } };
364 template <> struct Converter<uint8_t> { static uint8_t convert(RLP const& _r, int _flags) { return _r.toInt<uint8_t>(_flags); } };
365 template <> struct Converter<uint16_t> { static uint16_t convert(RLP const& _r, int _flags) { return _r.toInt<uint16_t>(_flags); } };
366 template <> struct Converter<uint32_t> { static uint32_t convert(RLP const& _r, int _flags) { return _r.toInt<uint32_t>(_flags); } };
367 template <> struct Converter<uint64_t> { static uint64_t convert(RLP const& _r, int _flags) { return _r.toInt<uint64_t>(_flags); } };
368 template <> struct Converter<u160> { static u160 convert(RLP const& _r, int _flags) { return _r.toInt<u160>(_flags); } };
369 template <> struct Converter<u256> { static u256 convert(RLP const& _r, int _flags) { return _r.toInt<u256>(_flags); } };
370 template <> struct Converter<bigint> { static bigint convert(RLP const& _r, int _flags) { return _r.toInt<bigint>(_flags); } };
371 template <unsigned N> struct Converter<FixedHash<N>> { static FixedHash<N> convert(RLP const& _r, int _flags) { return _r.toHash<FixedHash<N>>(_flags); } };
372 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); } };
373 template <class T> struct Converter<std::vector<T>> { static std::vector<T> convert(RLP const& _r, int _flags) { return _r.toVector<T>(_flags); } };
374 template <class T> struct Converter<std::set<T>> { static std::set<T> convert(RLP const& _r, int _flags) { return _r.toSet<T>(_flags); } };
375 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); } };
376 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); } };
377 
378 template <class T> inline T RLP::convert(int _flags) const { return Converter<T>::convert(*this, _flags); }
379 
384 {
385 public:
388 
390  explicit RLPStream(size_t _listItems) { appendList(_listItems); }
391 
393 
395  RLPStream& append(unsigned _s) { return append(bigint(_s)); }
396  RLPStream& append(u160 _s) { return append(bigint(_s)); }
397  RLPStream& append(u256 _s) { return append(bigint(_s)); }
398  RLPStream& append(bigint _s);
399  RLPStream& append(bytesConstRef _s, bool _compact = false);
400  RLPStream& append(bytes const& _s) { return append(bytesConstRef(&_s)); }
401  RLPStream& append(std::string const& _s) { return append(bytesConstRef(_s)); }
402  RLPStream& append(char const* _s) { return append(std::string(_s)); }
403  template <unsigned N> RLPStream& append(FixedHash<N> _s, bool _compact = false, bool _allOrNothing = false) { return _allOrNothing && !_s ? append(bytesConstRef()) : append(_s.ref(), _compact); }
404 
406  RLPStream& append(RLP const& _rlp, size_t _itemCount = 1) { return appendRaw(_rlp.data(), _itemCount); }
407 
409  template <class _T> RLPStream& append(std::vector<_T> const& _s) { return appendVector(_s); }
410  template <class _T> RLPStream& appendVector(std::vector<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
411  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; }
412  template <class _T> RLPStream& append(std::set<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
413  template <class _T> RLPStream& append(std::unordered_set<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
414  template <class T, class U> RLPStream& append(std::pair<T, U> const& _s) { appendList(2); append(_s.first); append(_s.second); return *this; }
415 
417  RLPStream& appendList(size_t _items);
418  RLPStream& appendList(bytesConstRef _rlp);
419  RLPStream& appendList(bytes const& _rlp) { return appendList(&_rlp); }
420  RLPStream& appendList(RLPStream const& _s) { return appendList(&_s.out()); }
421 
423  RLPStream& appendRaw(bytesConstRef _rlp, size_t _itemCount = 1);
424  RLPStream& appendRaw(bytes const& _rlp, size_t _itemCount = 1) { return appendRaw(&_rlp, _itemCount); }
425 
427  template <class T> RLPStream& operator<<(T _data) { return append(_data); }
428 
430  void clear() { m_out.clear(); m_listStack.clear(); }
431 
433  bytes const& out() const { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); return m_out; }
434 
436  bytes&& invalidate() { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); return std::move(m_out); }
437 
439  void swapOut(bytes& _dest) { if(!m_listStack.empty()) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("listStack is not empty")); swap(m_out, _dest); }
440 
441 private:
442  void noteAppended(size_t _itemCount = 1);
443 
446  void pushCount(size_t _count, byte _offset);
447 
449  template <class _T> void pushInt(_T _i, size_t _br)
450  {
451  m_out.resize(m_out.size() + _br);
452  byte* b = &m_out.back();
453  for (; _i; _i >>= 8)
454  *(b--) = toUint8(_i);
455  }
456 
459 
460  std::vector<std::pair<size_t, size_t>> m_listStack;
461 };
462 
463 template <class _T> void rlpListAux(RLPStream& _out, _T _t) { _out << _t; }
464 template <class _T, class ... _Ts> void rlpListAux(RLPStream& _out, _T _t, _Ts ... _ts) { rlpListAux(_out << _t, _ts...); }
465 
467 template <class _T> bytes rlp(_T _t) { return (RLPStream() << _t).out(); }
468 
470 inline bytes rlpList() { return RLPStream(0).out(); }
471 template <class ... _Ts> bytes rlpList(_Ts ... _ts)
472 {
473  RLPStream out(sizeof ...(_Ts));
474  rlpListAux(out, _ts...);
475  return out.out();
476 }
477 
479 extern bytes RLPNull;
480 
482 extern bytes RLPEmptyList;
483 
485 std::ostream& operator<<(std::ostream& _out, dev::RLP const& _d);
486 
487 }
std::vector< std::pair< size_t, size_t > > m_listStack
Definition: RLP.h:460
bool operator!=(u256 const &_i) const
Definition: RLP.h:135
RLPStream & append(std::array< _T, S > const &_s)
Definition: RLP.h:411
RLPStream & append(std::string const &_s)
Definition: RLP.h:401
bool operator!=(unsigned const &_i) const
Definition: RLP.h:133
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::array< T, N > toArray(int _flags=LaissezFaire) const
Definition: RLP.h:259
std::set< T > toSet(int _flags=LaissezFaire) const
Definition: RLP.h:219
RLP(std::string const &_s, Strictness _st=VeryStrict)
Construct a node to read RLP data in the string.
Definition: RLP.h:94
static std::array< T, N > convert(RLP const &_r, int _flags)
Definition: RLP.h:376
bool isNull() const
No value.
Definition: RLP.h:103
static uint64_t convert(RLP const &_r, int _flags)
Definition: RLP.h:367
uint8_t byte
Definition: Common.h:57
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
Definition: Interface.h:284
bool isList() const
List value.
Definition: RLP.h:112
static u256 convert(RLP const &_r, int _flags)
Definition: RLP.h:369
static uint8_t convert(RLP const &_r, int _flags)
Definition: RLP.h:364
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
Definition: RLP.h:467
bytesConstRef data() const
The bare data of the RLP.
Definition: RLP.h:97
RLPStream & append(char const *_s)
Definition: RLP.h:402
bool operator!=(FixedHash< _N > const &_s) const
Definition: RLP.h:131
size_t itemCount() const
Definition: RLP.h:118
std::vector< T > toVector(int _flags=LaissezFaire) const
Definition: RLP.h:204
#define T(i, x)
RLPStream & append(unsigned _s)
Append given datum to the byte stream.
Definition: RLP.h:395
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
Definition: Common.h:121
bytes const & out() const
Read the byte stream.
Definition: RLP.h:433
static bigint convert(RLP const &_r, int _flags)
Definition: RLP.h:370
bytes m_out
Our output byte stream.
Definition: RLP.h:458
std::pair< T, U > toPair(int _flags=Strict) const
Definition: RLP.h:243
static bytes convert(RLP const &_r, int _flags)
Definition: RLP.h:362
static std::string convert(RLP const &_r, int _flags)
Definition: RLP.h:361
static FixedHash< N > convert(RLP const &_r, int _flags)
Definition: RLP.h:371
std::hash for asio::adress
Definition: Common.h:323
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Definition: CommonData.cpp:141
bool isData() const
String value.
Definition: RLP.h:109
RLP()
Construct a null node.
Definition: RLP.h:82
std::string toStringStrict() const
Converts to string.
Definition: RLP.h:201
static uint32_t convert(RLP const &_r, int _flags)
Definition: RLP.h:366
RLPStream & operator<<(T _data)
Shift operators for appending data items.
Definition: RLP.h:427
bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
Definition: asn.h:558
bool operator==(unsigned const &_i) const
Definition: RLP.h:132
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 160, 160, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u160
Definition: Common.h:127
static size_t sizeAsEncoded(bytesConstRef _data)
Definition: RLP.h:350
RLPStream & append(std::unordered_set< _T > const &_s)
Definition: RLP.h:413
bytesConstRef m_currentItem
Definition: RLP.h:166
RLPStream & appendList(RLPStream const &_s)
Definition: RLP.h:420
bytes RLPNull
The empty string in RLP format.
Definition: RLP.cpp:26
RLPStream & appendVector(std::vector< _T > const &_s)
Definition: RLP.h:410
RLPStream & append(std::set< _T > const &_s)
Definition: RLP.h:412
T convert(int _flags) const
Definition: RLP.h:378
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:406
~RLPStream()
Definition: RLP.h:392
RLPStream & append(u160 _s)
Definition: RLP.h:396
unsigned lengthSize() const
Definition: RLP.h:338
RLP operator*() const
Definition: RLP.h:157
_N toHash(int _flags=Strict) const
Definition: RLP.h:298
static std::pair< T, U > convert(RLP const &_r, int _flags)
Definition: RLP.h:372
bool operator!=(char const *_s) const
Definition: RLP.h:127
size_t itemCountStrict() const
Definition: RLP.h:119
bool operator==(u256 const &_i) const
Definition: RLP.h:134
bytesRef ref()
Definition: FixedHash.h:133
bool operator==(char const *_s) const
Equality operators; does best-effort conversion and checks for equality.
Definition: RLP.h:126
bool operator==(FixedHash< _N > const &_h) const
Definition: RLP.h:130
bytesConstRef payload() const
Definition: RLP.h:321
std::vector< byte > bytes
Definition: Common.h:75
RLPStream(size_t _listItems)
Initializes the RLPStream as a list of _listItems items.
Definition: RLP.h:390
vector_ref< byte const > bytesConstRef
Definition: Common.h:77
bytes && invalidate()
Invalidate the object and steal the output byte stream.
Definition: RLP.h:436
static u160 convert(RLP const &_r, int _flags)
Definition: RLP.h:368
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
std::unordered_set< T > toUnorderedSet(int _flags=LaissezFaire) const
Definition: RLP.h:231
RLPStream & appendList(bytes const &_rlp)
Definition: RLP.h:419
RLPStream & appendRaw(bytes const &_rlp, size_t _itemCount=1)
Definition: RLP.h:424
static RLPs convert(RLP const &_r, int _flags)
Definition: RLP.h:363
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
bytesConstRef m_data
Our byte data.
Definition: RLP.h:353
bool operator==(iterator const &_cmp) const
Definition: RLP.h:158
#define b(i, j)
RLPStream & append(u256 _s)
Definition: RLP.h:397
RLPs toList(int _flags=Strict) const
Converts to RLPs collection object. Useful if you need random access to sub items or will iterate ove...
Definition: RLP.cpp:93
bytes rlpList()
Export a list of items in RLP format, returning a byte array.
Definition: RLP.h:470
std::ostream & operator<<(std::ostream &_out, bytes const &_e)
Definition: CommonIO.h:80
bool operator==(bigint const &_i) const
Definition: RLP.h:136
bool operator==(std::string const &_s) const
Definition: RLP.h:128
void clear()
Clear the output stream so far.
Definition: RLP.h:430
bytesConstRef m_lastItem
Definition: RLP.h:358
RLPStream & append(std::vector< _T > const &_s)
Appends a sequence of data to the stream as a list.
Definition: RLP.h:409
size_t sizeStrict() const
Definition: RLP.h:123
static const unsigned maxSize
Definition: RLP.h:42
uint8_t const size_t const size
Definition: sha3.h:20
bool isSingleByte() const
Single-byte data payload.
Definition: RLP.h:335
RLPStream & append(FixedHash< N > _s, bool _compact=false, bool _allOrNothing=false)
Definition: RLP.h:403
void * memcpy(void *a, const void *b, size_t c)
Base class for all RLP exceptions.
Definition: Exceptions.h:51
size_t actualSize() const
Definition: RLP.cpp:108
bytesConstRef toBytesConstRef(int _flags=LaissezFaire) const
Converts to bytearray.
Definition: RLP.h:197
RLP(bytes const &_d, Strictness _s=VeryStrict)
Construct a node of value given in the bytes.
Definition: RLP.h:88
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition: Assertions.h:78
static std::set< T > convert(RLP const &_r, int _flags)
Definition: RLP.h:374
Iterator class for iterating through items of RLP list.
Definition: RLP.h:147
std::string toString(int _flags=LaissezFaire) const
Converts to string.
Definition: RLP.h:199
RLP(byte const *_b, unsigned _s, Strictness _st=VeryStrict)
Construct a node to read RLP data in the bytes given.
Definition: RLP.h:91
RLP(bytes const &&)
Disable construction from rvalue.
Definition: RLP.h:329
static std::vector< T > convert(RLP const &_r, int _flags)
Definition: RLP.h:373
void pushInt(_T _i, size_t _br)
Push an integer as a raw big-endian byte-stream.
Definition: RLP.h:449
static T convert(RLP const &, int)
Definition: RLP.h:56
bool operator!=(iterator const &_cmp) const
Definition: RLP.h:159
iterator end() const
Iterator into end of sub-item list (valid only if we are a list).
Definition: RLP.h:173
size_t payloadOffset() const
Definition: RLP.h:344
void swapOut(bytes &_dest)
Swap the contents of the output stream out for some other byte array.
Definition: RLP.h:439
static uint16_t convert(RLP const &_r, int _flags)
Definition: RLP.h:365
uint8_t toUint8(T _u)
Definition: Common.h:205
RLPStream & append(bytes const &_s)
Definition: RLP.h:400
bool operator!=(std::string const &_s) const
Definition: RLP.h:129
iterator begin() const
Iterator into beginning of sub-item list (valid only if we are a list).
Definition: RLP.h:170
bool isEmpty() const
Contains a zero-length string or zero-length list.
Definition: RLP.h:106
RLPStream & append(std::pair< T, U > const &_s)
Definition: RLP.h:414
_T toInt(int _flags=Strict) const
Converts to int of type given; if isString(), decodes as big-endian bytestream.
Definition: RLP.h:275
Class for writing to an RLP bytestream.
Definition: RLP.h:383
iterator operator++(int)
Definition: RLP.h:156
RLPStream()
Initializes empty RLPStream.
Definition: RLP.h:387
uint8_t const * data
Definition: sha3.h:19
std::vector< RLP > RLPs
Definition: RLP.h:40
Class for interpreting Recursive Linear-Prefix Data.
Definition: RLP.h:64
int Strictness
Definition: RLP.h:79
bytes toBytes(int _flags=LaissezFaire) const
Converts to bytearray.
Definition: RLP.h:195
static std::unordered_set< T > convert(RLP const &_r, int _flags)
Definition: RLP.h:375
size_t size() const
Definition: RLP.h:122
void rlpListAux(RLPStream &_out, _T _t)
Definition: RLP.h:463
bool operator!=(bigint const &_i) const
Definition: RLP.h:137
bytes RLPEmptyList
The empty list in RLP format.
Definition: RLP.cpp:27