Added toHexString()
This commit is contained in:
@ -32,6 +32,7 @@ set(dependencies
|
|||||||
esp_system
|
esp_system
|
||||||
# esp_http_client
|
# esp_http_client
|
||||||
esp_websocket_client
|
esp_websocket_client
|
||||||
|
libsodium
|
||||||
tcp_transport
|
tcp_transport
|
||||||
|
|
||||||
cpputils
|
cpputils
|
||||||
|
@ -3,8 +3,11 @@
|
|||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#define LOG_LOCAL_LEVEL CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL
|
#define LOG_LOCAL_LEVEL CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
#include <sodium/utils.h>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
@ -58,4 +61,18 @@ std::string toString(esp_log_level_t val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string toHexString(std::basic_string_view<unsigned char> buf)
|
||||||
|
{
|
||||||
|
std::string hex(buf.size() * 2 + 1, {});
|
||||||
|
assert(hex.size() == buf.size() * 2 + 1);
|
||||||
|
|
||||||
|
const char *ptr = sodium_bin2hex(hex.data(), hex.size(), buf.data(), buf.size());
|
||||||
|
|
||||||
|
hex.resize(hex.size() - 1);
|
||||||
|
assert(hex.size() == buf.size() * 2);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "sodium=%p end=%p", ptr, &*std::end(hex));
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace espcpputils
|
} // namespace espcpputils
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
// system includes
|
// system includes
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_sntp.h>
|
#include <esp_sntp.h>
|
||||||
@ -13,4 +14,10 @@ std::string toString(sntp_sync_mode_t val);
|
|||||||
std::string toString(sntp_sync_status_t val);
|
std::string toString(sntp_sync_status_t val);
|
||||||
std::string toString(esp_log_level_t val);
|
std::string toString(esp_log_level_t val);
|
||||||
|
|
||||||
|
std::string toHexString(std::basic_string_view<unsigned char> buf);
|
||||||
|
inline std::string toHexString(std::string_view str)
|
||||||
|
{
|
||||||
|
return toHexString(std::basic_string_view<unsigned char>{reinterpret_cast<const unsigned char *>(str.data()), str.size()});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace espcpputils
|
} // namespace espcpputils
|
||||||
|
Reference in New Issue
Block a user