/// Converts a templated integer value to the big-endian byte-stream represented on a templated collection.
/// The size of the collection object will be unchanged. If it is too small, it will not represent the
/// value properly, if too big then the additional elements will be zeroed out.
/// @a Out will typically be either std::string or bytes.
/// @a T will typically by unsigned, u160, u256 or bigint.
template<classT,classOut>
inlinevoidtoBigEndian(T_val,Out&o_out)
{
static_assert(std::is_same<bigint,T>::value||!std::numeric_limits<T>::is_signed,"only unsigned types or bigint supported");//bigint does not carry sign bit on shift
for(autoi=o_out.size();i!=0;_val>>=8,i--)
{
Tv=_val&(T)0xff;
o_out[i-1]=(typenameOut::value_type)(uint8_t)v;
}
}
/// Converts a big-endian byte-stream represented on a templated collection to a templated integer value.
/// @a In will typically be either std::string or bytes.
/// @a T will typically by unsigned, u256 or bigint.
static_assert(std::is_same<bigint,T>::value||!std::numeric_limits<T>::is_signed,"only unsigned types or bigint supported");//bigint does not carry sign bit on shift
unsignedi=0;
for(Tv=_val;v;++i,v>>=8){}
bytesret(std::max<unsigned>(_min,i),0);
toBigEndian(_val,ret);
returnret;
}
/// Convenience function for conversion of a u256 to hex
// Algorithms for string and string-like collections.
/// Determine bytes required to encode the given integer value. @returns 0 if @a _i is zero.
template<classT>
inlineunsignednumberEncodingSize(T_i)
{
static_assert(std::is_same<bigint,T>::value||!std::numeric_limits<T>::is_signed,"only unsigned types or bigint supported");//bigint does not carry sign bit on shift