56 lines
1004 B
C++
56 lines
1004 B
C++
#include "memory/dl_buffer.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include "memory/dl_code_cvt.h"
|
|
#include "base/dl_string.h"
|
|
|
|
namespace dl
|
|
{
|
|
BufferPool g_bufferPool;
|
|
//std::string toString(const Buffer& buf, bool add_tag /*= false*/)
|
|
//{
|
|
// if (buf.empty())
|
|
// return "";
|
|
// std::string ret;
|
|
// if (add_tag)
|
|
// ret += "0x";
|
|
//
|
|
// for (size_t i = 0; i < buf.size(); ++i)
|
|
// {
|
|
//#ifndef MK_OTHER_PROJECT
|
|
// ret += fmt::format("{:0<2x}", buf.data()[i]);
|
|
//#else
|
|
// ret += format("{:0<2x}", buf.data()[i]);
|
|
//#endif
|
|
//
|
|
// ifs.seekg(0);
|
|
// ifs.read((char*)ret.data(), ret.size());
|
|
// return ret;
|
|
//}
|
|
|
|
dl::Buffer CreateBufferHex(std::string_view str)
|
|
{
|
|
Buffer ret;
|
|
ret.resize((str.size() + 1) / 2);
|
|
for (size_t i = 0; i < str.size(); i += 2)
|
|
{
|
|
std::string_view s = { str.begin() + i, str.begin() + i + 2 };
|
|
|
|
std::byte v;
|
|
if (!String::getByte(s, v))
|
|
{
|
|
log_err("无效的16进制字符串:{}", str);
|
|
return {};
|
|
}
|
|
ret[i / 2] = v;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
}
|
|
|
|
|