75 lines
1.3 KiB
C++
75 lines
1.3 KiB
C++
#include "memory/dl_buffer.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include "memory/dl_code_cvt.h"
|
|
|
|
namespace dl
|
|
{
|
|
std::string CreateString(BufferView buf)
|
|
// }
|
|
// return ret;
|
|
//}
|
|
//
|
|
//mk::Buffer createBuffer(unsigned char* p, size_t size)
|
|
//{
|
|
// Buffer ret;
|
|
// ret.resize(size);
|
|
// memcpy(ret.data(), p, size);
|
|
// return ret;
|
|
//}
|
|
//
|
|
//mk::Buffer createBuffer(std::vector<char>& vec)
|
|
//{
|
|
// Buffer ret;
|
|
// ret.resize(vec.size());
|
|
// memcpy(ret.data(), vec.data(), vec.size());
|
|
// return ret;
|
|
//}
|
|
//
|
|
//Buffer createBuffer(const std::string& path_name)
|
|
//{
|
|
// std::ifstream ifs{ path_name, std::ios::binary };
|
|
// if (!ifs.is_open())
|
|
// return {};
|
|
//
|
|
// Buffer ret;
|
|
//
|
|
// ifs.seekg(0, std::ios::end);
|
|
// ret.resize((size_t)ifs.tellg());
|
|
//
|
|
{
|
|
std::string ret = { (char*)buf.data(), buf.size() };
|
|
assert(CodeCvt::Utf8::Check(ret));
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
//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;
|
|
//}
|
|
|
|
}
|
|
|
|
|