mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add generalized dynamic array encoding to ExecutionFramework.
This commit is contained in:
parent
f7c6eda2c3
commit
f9dc30c3d1
@ -202,6 +202,31 @@ public:
|
|||||||
return m_blockNumber;
|
return m_blockNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Range>
|
||||||
|
bytes encodeArray(bool _dynamicallySized, bool _dynamicallyEncoded, Range const& _elements)
|
||||||
|
{
|
||||||
|
bytes result;
|
||||||
|
if (_dynamicallySized)
|
||||||
|
result += encode(u256(_elements.size()));
|
||||||
|
if (_dynamicallyEncoded)
|
||||||
|
{
|
||||||
|
u256 offset = u256(_elements.size()) * 32;
|
||||||
|
std::vector<bytes> subEncodings;
|
||||||
|
for (auto const& element: _elements)
|
||||||
|
{
|
||||||
|
result += encode(offset);
|
||||||
|
subEncodings.emplace_back(encode(element));
|
||||||
|
offset += subEncodings.back().size();
|
||||||
|
}
|
||||||
|
for (auto const& subEncoding: subEncodings)
|
||||||
|
result += subEncoding;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (auto const& element: _elements)
|
||||||
|
result += encode(element);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <class CppFunction, class... Args>
|
template <class CppFunction, class... Args>
|
||||||
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)
|
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)
|
||||||
|
Loading…
Reference in New Issue
Block a user