35 return fromHex(_s, WhenError::Throw);
39 if (_f == OnFailed::InterpretRaw)
41 else if (_f == OnFailed::Throw)
42 throw invalid_argument(
"Cannot intepret '" + _s +
"' as bytes; must be 0x-prefixed hex or decimal.");
49 while (_b.size() < _l)
50 _b.insert(_b.begin(), 0);
62 auto p =
asString(_b).find_last_not_of((
char)0);
63 _b.resize(p == string::npos ? 0 : (p + 1));
73 while (i < _b.size() && _b[i] ==
byte(0))
77 _b.erase(_b.begin(), _b.begin() + i);
85 string s((
char const*)_n.
data(), 32);
86 auto l = s.find_first_of(
'\0');
89 if (l != string::npos)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::hash for asio::adress
bytes unpadded(bytes _b)
Removing all trailing '0'. Returns empty array if input contains only '0' char.
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
string fromRaw(h256 _n)
Convert h256 into user-readable string (by directly using std::string constructor). If it can't be interpreted as an ASCII string, empty string is returned.
std::vector< byte > bytes
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string's (byte) data.
bytes paddedRight(bytes _b, unsigned _l)
Add '0' on, or remove items from, the back of _b until it is of length _l.
bytes jsToBytes(string const &_s, OnFailed _f)
bytes padded(bytes _b, unsigned _l)
Add '0' on, or remove items from, the front of _b until it is of length _l.
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
bytes unpadLeft(bytes _b)
Remove all 0 byte on the head of _s.
std::string asString(bytes const &_b)
Converts byte array to a string containing the same (binary) data.