3 #include <kafka/Project.h>
5 #include <librdkafka/rdkafka.h>
15 namespace KAFKA_API {
namespace utility {
20 inline std::string getLocalTimeString(
const std::chrono::system_clock::time_point& timePoint)
22 auto time = std::chrono::system_clock::to_time_t(timePoint);
26 localtime_r(&time, &tmBuf);
28 localtime_s(&tmBuf, &time);
31 std::ostringstream oss;
32 oss << std::put_time(&tmBuf,
"%F %T") <<
"." << std::setfill(
'0') << std::setw(6)
33 << std::chrono::duration_cast<std::chrono::microseconds>(timePoint.time_since_epoch()).count() % 1000000;
41 inline std::string getCurrentTime()
43 return getLocalTimeString(std::chrono::system_clock::now());
49 inline std::string getRandomString()
51 using namespace std::chrono;
53 const std::uint32_t timestamp =
static_cast<std::uint32_t
>(duration_cast<nanoseconds>(system_clock::now().time_since_epoch()).count());
56 std::default_random_engine e(r());
57 std::uniform_int_distribution<std::uint64_t> uniform_dist(0, 0xFFFFFFFF);
58 const std::uint64_t rand = uniform_dist(e);
60 std::ostringstream oss;
61 oss << std::setfill(
'0') << std::setw(
sizeof(std::uint32_t) * 2) << std::hex << timestamp <<
"-" << rand;
68 inline std::string getLibRdKafkaVersion()
70 return rd_kafka_version_str();
76 inline int getLibRdKafkaThreadCount()
78 return rd_kafka_thread_cnt();