mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-01 19:18:04 +00:00
Added time_point overloads for creating timestamps. (#128)
* Added time_point overloads for creating timestamps. * aliased std::chrono types
This commit is contained in:
committed by
Matias Fontanini
parent
ad9a1e4a49
commit
57268e666c
@@ -240,12 +240,19 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a timestamp object
|
||||
* Constructs a timestamp object using a 'duration'.
|
||||
*/
|
||||
MessageTimestamp(std::chrono::milliseconds timestamp, TimestampType type);
|
||||
|
||||
/**
|
||||
* Constructs a timestamp object using a 'time_point'.
|
||||
*/
|
||||
template <typename Clock, typename Duration = typename Clock::duration>
|
||||
MessageTimestamp(std::chrono::time_point<Clock, Duration> timestamp, TimestampType type);
|
||||
|
||||
/**
|
||||
* Gets the timestamp value
|
||||
* Gets the timestamp value. If the timestamp was created with a 'time_point',
|
||||
* the duration represents the number of milliseconds since epoch.
|
||||
*/
|
||||
std::chrono::milliseconds get_timestamp() const;
|
||||
|
||||
|
||||
@@ -128,11 +128,19 @@ public:
|
||||
Concrete& payload(BufferType&& value);
|
||||
|
||||
/**
|
||||
* Sets the message's timestamp
|
||||
* Sets the message's timestamp with a 'duration'
|
||||
*
|
||||
* \param value The timestamp to be used
|
||||
*/
|
||||
Concrete& timestamp(std::chrono::milliseconds value);
|
||||
|
||||
/**
|
||||
* Sets the message's timestamp with a 'time_point'.
|
||||
*
|
||||
* \param value The timestamp to be used
|
||||
*/
|
||||
template <typename Clock, typename Duration = typename Clock::duration>
|
||||
Concrete& timestamp(std::chrono::time_point<Clock, Duration> value);
|
||||
|
||||
/**
|
||||
* Sets the message's user data pointer
|
||||
@@ -184,7 +192,8 @@ public:
|
||||
BufferType& payload();
|
||||
|
||||
/**
|
||||
* Gets the message's timestamp
|
||||
* Gets the message's timestamp as a duration. If the timestamp was created with a 'time_point',
|
||||
* the duration represents the number of milliseconds since epoch.
|
||||
*/
|
||||
std::chrono::milliseconds timestamp() const;
|
||||
|
||||
@@ -295,6 +304,14 @@ C& BasicMessageBuilder<T, C>::timestamp(std::chrono::milliseconds value) {
|
||||
return get_concrete();
|
||||
}
|
||||
|
||||
template <typename T, typename C>
|
||||
template <typename Clock, typename Duration>
|
||||
C& BasicMessageBuilder<T, C>::timestamp(std::chrono::time_point<Clock, Duration> value)
|
||||
{
|
||||
timestamp_ = std::chrono::duration_cast<std::chrono::milliseconds>(value.time_since_epoch());
|
||||
return get_concrete();
|
||||
}
|
||||
|
||||
template <typename T, typename C>
|
||||
C& BasicMessageBuilder<T, C>::user_data(void* value) {
|
||||
user_data_ = value;
|
||||
|
||||
Reference in New Issue
Block a user