From 489d5c7c1cdeb61515dd8930c01ab98750744e11 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Thu, 3 Jan 2019 13:32:37 -0500 Subject: [PATCH] Fixed network messages to include an id so they are both 1) indexable and 2) do not cache in the network buffer --- Message.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Message.cpp b/Message.cpp index 40b5272..171399b 100644 --- a/Message.cpp +++ b/Message.cpp @@ -19,6 +19,18 @@ **/ #include "Message.h" +#include "DriftingDateTime.h" + +const quint32 EPOCH = 1499299200000; // July 6, 2017 + +#if USE_SNOWFLAKE +quint64 snowflake(quint64 epoch, quint16 machine, quint16 sequence){ + quint64 value = (DriftingDateTime::currentMSecsSinceEpoch() - epoch) << 22; + value |= machine & 0x3FF << 12; + value |= sequence & 0xFFF; + return value; +} +#endif Message::Message() { @@ -28,6 +40,7 @@ Message::Message(QString const &type, QString const &value): type_{ type }, value_{ value } { + params_["_ID"] = QString::number(DriftingDateTime::currentMSecsSinceEpoch()-EPOCH); } Message::Message(QString const &type, QString const &value, QMap const ¶ms): @@ -35,6 +48,7 @@ Message::Message(QString const &type, QString const &value, QMap