Upgraded the rest of Time.
Change-Id: I0ee083837e51d8f74a798b7ba14a3b6bb3859f35
diff --git a/aos/common/queue.cc b/aos/common/queue.cc
index 893e62b..ba85a72 100644
--- a/aos/common/queue.cc
+++ b/aos/common/queue.cc
@@ -1,37 +1,47 @@
#include "aos/common/queue.h"
-#include "aos/common/byteorder.h"
#include <inttypes.h>
+#include <chrono>
+
+#include "aos/common/byteorder.h"
namespace aos {
-void Message::Zero() {
- sent_time.set_sec(0);
- sent_time.set_nsec(0);
-}
+namespace chrono = ::std::chrono;
+
+void Message::Zero() { sent_time = monotonic_clock::min_time; }
size_t Message::Deserialize(const char *buffer) {
int32_t sec;
int32_t nsec;
to_host(&buffer[0], &sec);
to_host(&buffer[4], &nsec);
- sent_time.set_sec(sec);
- sent_time.set_nsec(nsec);
+ sent_time = monotonic_clock::time_point(chrono::seconds(sec) +
+ chrono::nanoseconds(nsec));
return Size();
}
// Serializes the common fields into the buffer.
size_t Message::Serialize(char *buffer) const {
// TODO(aschuh): to_network shouldn't need a pointer.
- int32_t sec = sent_time.sec();
- int32_t nsec = sent_time.nsec();
+ int32_t sec =
+ chrono::duration_cast<chrono::seconds>(sent_time.time_since_epoch())
+ .count();
+ int32_t nsec = chrono::duration_cast<chrono::nanoseconds>(
+ sent_time.time_since_epoch() - chrono::seconds(sec))
+ .count();
to_network(&sec, &buffer[0]);
to_network(&nsec, &buffer[4]);
return Size();
}
size_t Message::Print(char *buffer, int length) const {
- return snprintf(buffer, length, "%" PRId32 ".%09" PRId32 "s",
- sent_time.sec(), sent_time.nsec());
+ int32_t sec =
+ chrono::duration_cast<chrono::seconds>(sent_time.time_since_epoch())
+ .count();
+ int32_t nsec = chrono::duration_cast<chrono::nanoseconds>(
+ sent_time.time_since_epoch() - chrono::seconds(sec))
+ .count();
+ return snprintf(buffer, length, "%" PRId32 ".%09" PRId32 "s", sec, nsec);
}
} // namespace aos