mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Merge pull request #6351
81c5943
Remove temporary std::string creation in some hex->bin calls (vtnerd)5fcc23a
Move hex->bin conversion to monero copyright files and with less includes (vtnerd)3387f0e
Reduce template bloat in hex->bin for ZMQ json (vtnerd)
This commit is contained in:
commit
cfc0f4a7fa
9 changed files with 135 additions and 62 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2017-2019, The Monero Project
|
||||
// Copyright (c) 2017-2020, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
|
@ -33,6 +33,8 @@
|
|||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "storages/parserse_base_utils.h"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace
|
||||
|
@ -84,7 +86,42 @@ namespace epee
|
|||
return write_hex(out, src);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> from_hex::vector(boost::string_ref src)
|
||||
|
||||
bool from_hex::to_string(std::string& out, const boost::string_ref src)
|
||||
{
|
||||
out.resize(src.size() / 2);
|
||||
return to_buffer_unchecked(reinterpret_cast<std::uint8_t*>(&out[0]), src);
|
||||
}
|
||||
|
||||
bool from_hex::to_buffer(span<std::uint8_t> out, const boost::string_ref src) noexcept
|
||||
{
|
||||
if (src.size() / 2 != out.size())
|
||||
return false;
|
||||
return to_buffer_unchecked(out.data(), src);
|
||||
}
|
||||
|
||||
bool from_hex::to_buffer_unchecked(std::uint8_t* dst, const boost::string_ref s) noexcept
|
||||
{
|
||||
if (s.size() % 2 != 0)
|
||||
return false;
|
||||
|
||||
const unsigned char *src = (const unsigned char *)s.data();
|
||||
for(size_t i = 0; i < s.size(); i += 2)
|
||||
{
|
||||
int tmp = *src++;
|
||||
tmp = epee::misc_utils::parse::isx[tmp];
|
||||
if (tmp == 0xff) return false;
|
||||
int t2 = *src++;
|
||||
t2 = epee::misc_utils::parse::isx[t2];
|
||||
if (t2 == 0xff) return false;
|
||||
*dst++ = (tmp << 4) | t2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::vector<uint8_t> from_hex_locale::to_vector(const boost::string_ref src)
|
||||
{
|
||||
// should we include a specific character
|
||||
auto include = [](char input) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue