added an additional param to BinToHex so as to limit the size of the output

This commit is contained in:
csoler 2017-07-15 22:15:51 +02:00
parent 5ffb54929c
commit 9c391cb015
2 changed files with 9 additions and 3 deletions

View File

@ -54,8 +54,11 @@ std::string RsUtil::BinToHex(const std::string &bin)
return BinToHex(bin.c_str(), bin.length());
}
std::string RsUtil::BinToHex(const unsigned char *arr, const uint32_t len)
std::string RsUtil::BinToHex(const unsigned char *arr, const uint32_t len,uint32_t max_len)
{
if(max_len > 0)
return BinToHex((char*)arr,std::min(max_len,len)) + ((len > max_len)?"...":"") ;
else
return BinToHex((char*)arr,len) ;
}
std::string RsUtil::BinToHex(const char *arr, const uint32_t len)

View File

@ -36,7 +36,10 @@ namespace RsUtil {
std::string BinToHex(const std::string &bin);
std::string BinToHex(const char *arr, const uint32_t len);
std::string BinToHex(const unsigned char *arr, const uint32_t len);
// proxy function. When max_len>0 and len>max_len, only the first "max_len" bytes are writen to the string and "..." is happened.
std::string BinToHex(const unsigned char *arr, const uint32_t len, uint32_t max_len=0);
std::string NumberToString(uint64_t n, bool hex=false);
std::string HashId(const std::string &id, bool reverse = false);
std::vector<uint8_t> BinToSha256(const std::vector<uint8_t> &in);