Add generalized dynamic array encoding to ExecutionFramework.

This commit is contained in:
Daniel Kirchner 2019-03-05 12:01:44 +01:00
parent f7c6eda2c3
commit f9dc30c3d1

View File

@ -202,6 +202,31 @@ public:
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:
template <class CppFunction, class... Args>
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)