3 #include <kafka/Project.h>
5 #include <librdkafka/rdkafka.h>
22 using Value = std::int64_t;
24 enum class Type { NotAvailable, CreateTime, LogAppendTime };
39 static Type convertType(rd_kafka_timestamp_type_t tstype)
41 return (tstype == RD_KAFKA_TIMESTAMP_CREATE_TIME) ? Type::CreateTime :
42 (tstype == RD_KAFKA_TIMESTAMP_LOG_APPEND_TIME ? Type::LogAppendTime : Type::NotAvailable);
45 operator std::chrono::time_point<std::chrono::system_clock>() const
47 return std::chrono::time_point<std::chrono::system_clock>(std::chrono::milliseconds(
msSinceEpoch));
54 case Type::CreateTime:
56 case Type::LogAppendTime:
57 return "LogAppendTime";
59 assert(t == Type::NotAvailable);
66 auto ms = std::chrono::milliseconds(v);
67 auto timepoint = std::chrono::time_point<std::chrono::system_clock>(ms);
68 const std::time_t time = std::chrono::system_clock::to_time_t(timepoint);
69 std::ostringstream oss;
72 oss << std::put_time(localtime_r(&time, &tmBuf),
"%F %T") <<
"." << std::setfill(
'0') << std::setw(3) << (v % 1000);
74 localtime_s(&tmBuf, &time);
75 oss << std::put_time(&tmBuf,
"%F %T") <<
"." << std::setfill(
'0') << std::setw(3) << (v % 1000);
87 return typeString.empty() ? timeString : (typeString +
"[" + timeString +
"]");
The time point together with the type.
Definition: Timestamp.h:21
Type type
The type shows what the msSinceEpoch means (CreateTime or LogAppendTime).
Definition: Timestamp.h:34
std::string toString() const
Obtains explanatory string.
Definition: Timestamp.h:83
Value msSinceEpoch
The milliseconds since epoch.
Definition: Timestamp.h:29