Split //aos/common:queues into queues and messages.

These were already distinct concepts; probably makes more sense for them
to be separate. Also it makes it easier for teams to pick and choose
what parts of aos they want to use.

Change-Id: I3e6af61c8e4c1e337714f44b4e7f74a3b8f88060
diff --git a/aos/common/message.cc b/aos/common/message.cc
new file mode 100644
index 0000000..818c945
--- /dev/null
+++ b/aos/common/message.cc
@@ -0,0 +1,47 @@
+#include "aos/common/message.h"
+
+#include <inttypes.h>
+#include <chrono>
+
+#include "aos/common/byteorder.h"
+
+namespace aos {
+
+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 = 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 =
+      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 {
+  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