20template <
typename... Params>
25 encoding.append(target);
34inline auto rlp(
RLPEncoderRef encoding, T
const& target) ->
decltype(target.rlp(encoding), void()) {
42template <
typename Param>
45 rlp(encoding, *target);
47 encoding.
append(
unsigned(0));
51template <
typename Param>
54 rlp(encoding, *target);
56 encoding.
append(
unsigned(0));
60template <
typename T1,
typename T2>
62 rlp_tuple(encoding, target.first, target.second);
65template <
typename Sequence>
66auto rlp(
RLPEncoderRef encoding, Sequence
const& target) ->
decltype(target.size(), target.begin(), target.end(),
68 encoding.appendList(target.size());
69 for (
auto const& v : target) {
74template <
typename Param,
typename... Params>
76 rlp(encoding, target);
77 if constexpr (
sizeof...(rest) != 0) {
82template <
typename... Params>
84 constexpr auto num_elements =
sizeof...(args);
85 static_assert(0 < num_elements);
90template <
typename... Params>
91void rlp_tuple(RLPDecoderRef encoding, Params&... args);
94auto rlp(
RLPDecoderRef encoding, T& target) ->
decltype(encoding.value.toInt<T>(),
void()) {
95 target = encoding.value.toInt<T>(encoding.strictness);
107template <
typename Param>
110 target = std::nullopt;
112 rlp(encoding, target.emplace());
116template <
typename Param>
121 target = std::make_shared<Param>();
122 rlp(encoding, *target);
126template <
typename Sequence>
127auto rlp(
RLPDecoderRef encoding, Sequence& target) ->
decltype(target.emplace_back(), void()) {
128 for (
auto i : encoding.value) {
135inline auto rlp(RLPDecoderRef encoding, T& target) ->
decltype(target.rlp(encoding), void()) {
136 target.rlp(encoding);
139template <
typename Map>
140auto rlp(
RLPDecoderRef encoding, Map& target) ->
decltype(target[target.begin()->first], void()) {
141 using key_type = std::remove_cv_t<
decltype(target.begin()->first)>;
142 for (
auto i : encoding.value) {
143 auto entry_i = i.begin();
150template <
typename Param,
typename... Params>
159 if constexpr (
sizeof...(rest) > 0) {
172template <
typename... Params>
174 constexpr auto num_elements =
sizeof...(args);
175 static_assert(0 < num_elements);
194 encoder_to_reuse.
clear();
195 rlp(encoder_to_reuse, obj);
196 return encoder_to_reuse.
out();
208#define HAS_RLP_FIELDS \
209 void rlp(::taraxa::util::RLPDecoderRef encoding); \
210 void rlp(::taraxa::util::RLPEncoderRef encoding) const;
212#define RLP_FIELDS_DEFINE(_class_, ...) \
213 void _class_::rlp(::taraxa::util::RLPDecoderRef encoding) { ::taraxa::util::rlp_tuple(encoding, __VA_ARGS__); } \
214 void _class_::rlp(::taraxa::util::RLPEncoderRef encoding) const { ::taraxa::util::rlp_tuple(encoding, __VA_ARGS__); }
216#define RLP_FIELDS_DEFINE_INPLACE(...) \
217 void rlp(::taraxa::util::RLPDecoderRef encoding) { ::taraxa::util::rlp_tuple(encoding, __VA_ARGS__); } \
218 void rlp(::taraxa::util::RLPEncoderRef encoding) const { ::taraxa::util::rlp_tuple(encoding, __VA_ARGS__); }
Definition FixedHash.h:35
Iterator class for iterating through items of RLP list.
Definition RLP.h:148
_N toHash(int _flags=Strict) const
Definition RLP.h:344
iterator begin() const
Iterator into beginning of sub-item list (valid only if we are a list).
Definition RLP.h:175
size_t itemCount() const
Definition RLP.h:106
iterator end() const
Iterator into end of sub-item list (valid only if we are a list).
Definition RLP.h:178
std::enable_if_t< is_integer< _T >(Signedness::any), _T > toInt(int _flags=Strict) const
Definition RLP.h:309
bool isNull() const
No value.
Definition RLP.h:91
int Strictness
Definition RLP.h:69
bool isEmpty() const
Contains a zero-length string or zero-length list.
Definition RLP.h:94
bytes toBytes(int _flags=LaissezFaire) const
Converts to bytearray.
Definition RLP.h:215
std::string toString(int _flags=LaissezFaire) const
Converts to string.
Definition RLP.h:235
Class for writing to an RLP bytestream.
Definition RLP.h:484
void clear()
Clear the output stream so far.
Definition RLP.h:608
std::enable_if_t< is_integer< N >(Signedness::signed_only), RLPStream & > append(N const &_i)
Definition RLP.h:498
bytes const & out() const
Read the byte stream.
Definition RLP.h:614
bytes && invalidate()
Invalidate the object and steal the output byte stream.
Definition RLP.h:620
RLPStream & appendList(size_t _items)
Appends a list.
Definition RLP.cpp:207
boost::tuple< errinfo_required, errinfo_got > RequirementError
Definition Exceptions.h:62
std::vector<::byte > bytes
Definition Common.h:46
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition Assertions.h:50
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<> > bigint
Definition Common.h:92
Definition default_construct_copyable_movable.hpp:10
void rlp_tuple(RLPEncoderRef encoding, Params const &... args)
Definition encoding_rlp.hpp:83
dev::bytes const & rlp_enc(RLPEncoderRef encoder_to_reuse, T const &obj)
Definition encoding_rlp.hpp:193
T rlp_dec(RLPDecoderRef encoding)
Definition encoding_rlp.hpp:186
auto rlp(RLPEncoderRef encoding, T const &target) -> decltype(RLP().toInt< T >(), void())
Definition encoding_rlp.hpp:24
dev::RLPStream & RLPEncoderRef
Definition encoding_rlp.hpp:10
void __enc_rlp_tuple_body__(RLPEncoderRef encoding, Param const &target, Params const &... rest)
Definition encoding_rlp.hpp:75
void __dec_rlp_tuple_body__(RLP::iterator &i, RLP::iterator const &end, RLP::Strictness strictness, Param &target, Params &... rest)
Definition encoding_rlp.hpp:151
Base class for all RLP exceptions.
Definition Exceptions.h:29
Definition encoding_rlp.hpp:164
dev::bigint actual
Definition encoding_rlp.hpp:165
dev::bigint expected
Definition encoding_rlp.hpp:165
InvalidEncodingSize(uint e, uint a)
Definition encoding_rlp.hpp:167
Definition encoding_rlp.hpp:11
RLPDecoderRef(RLP const &value, bool strict=false)
Definition encoding_rlp.hpp:16
RLPDecoderRef(RLP const &value, RLP::Strictness strictness)
Definition encoding_rlp.hpp:15
RLP const & value
Definition encoding_rlp.hpp:12
RLP::Strictness strictness
Definition encoding_rlp.hpp:13