-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added time_point overloads for creating timestamps. #128
Conversation
aba9ca6
to
60f07a6
Compare
Note2 we could get rid of the template parameters and just force the time point to be |
Thanks for the PR. Regarding your system clock comment I was thinking about that and I have my doubts but I think letting the user provide a time point from any clock makes sense. I don't know why someone would want a time point from a steady clock but if that's what they want, then let them be. |
They could use high_precision_clock also...however having the template params allows you to do |
Yeah, I was using steady clock as an example of a clock that makes no sense out of the computer it was generated on, but any other will do. |
@@ -181,7 +183,7 @@ TEST_CASE("simple production", "[producer]") { | |||
CHECK(message.get_partition() == partition); | |||
CHECK(!!message.get_error() == false); | |||
REQUIRE(!!message.get_timestamp() == true); | |||
CHECK(message.get_timestamp()->get_timestamp() == timestamp); | |||
CHECK(message.get_timestamp()->get_timestamp() == duration_cast<milliseconds>(timestamp.time_since_epoch())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test does not exercise the new constructor. If it did, you would notice that the definition is not available, and will produce a link error
* 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not clear to me why it makes sense to have this template constructor be public, since its definition is only available in the .cpp file, and there's no explicit instantiation of it. In fact, I don't see any instantiations of this constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the definition should be on the header. It would never work the way it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, true, why is this constructor even here? Nothing uses it and nothing can construct a timestamp besides cppkafka itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put up #129 to fix this. I don't think we need that overload at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move the def from the .cpp file. I initially did it w/o templates, and then after you said it was ok to templetize based on the clock type I just added the templates but forgot to move it to the header file. My bad.
@mfontanini see my note in the first comment I made. The idea was that since the other constructor is public (should have been private) and |
Changes to
BasicMessageBuilder
andMessageTimestamp
classes to allowstd::chrono::time_point
overloads.Note that
MessageTimestamp
is created internally by theMessage
object, however since it's constructor was public, I figured others could use this class to store timestamps outside of theMessage
implementation.Fixes #15