Add getTruncatedBytesString() to utils.

This commit is contained in:
jakcron 2021-09-29 18:28:49 +08:00
parent 0e39d48214
commit 0f16231638
2 changed files with 20 additions and 0 deletions

View file

@ -97,4 +97,22 @@ void nstool::writeStreamToStream(const std::shared_ptr<tc::io::IStream>& in_stre
remaining_data -= int64_t(cache_read_len);
}
}
std::string nstool::getTruncatedBytesString(const byte_t* data, size_t len, bool do_not_truncate)
{
if (data == nullptr) { return fmt::format(""); }
std::string str = "";
if (len <= 8 || do_not_truncate)
{
str = tc::cli::FormatUtil::formatBytesAsString(data, len, true, "");
}
else
{
str = fmt::format("{:02X}{:02X}{:02X}{:02X}...{:02X}{:02X}{:02X}{:02X}", data[0], data[1], data[2], data[3], data[len-4], data[len-3], data[len-2], data[len-1]);
}
return str;
}

View file

@ -10,4 +10,6 @@ void writeSubStreamToFile(const std::shared_ptr<tc::io::IStream>& in_stream, int
void writeStreamToFile(const std::shared_ptr<tc::io::IStream>& in_stream, const tc::io::Path& out_path, size_t cache_size = 0x10000);
void writeStreamToStream(const std::shared_ptr<tc::io::IStream>& in_stream, const std::shared_ptr<tc::io::IStream>& out_stream, size_t cache_size = 0x10000);
std::string getTruncatedBytesString(const byte_t* data, size_t len, bool do_not_truncate);
}