Adding protobuf for SyncState
diff --git a/src/sync-log.cc b/src/sync-log.cc
index 99b652c..3e49c69 100644
--- a/src/sync-log.cc
+++ b/src/sync-log.cc
@@ -149,13 +149,13 @@
sqlite3_finalize (stmt);
}
-void
+SyncStateMsgPtr
SyncLog::FindStateDifferences (const std::string &oldHash, const std::string &newHash)
{
- FindStateDifferences (*Hash::FromString (oldHash), *Hash::FromString (newHash));
+ return FindStateDifferences (*Hash::FromString (oldHash), *Hash::FromString (newHash));
}
-void
+SyncStateMsgPtr
SyncLog::FindStateDifferences (const Hash &oldHash, const Hash &newHash)
{
sqlite3_stmt *stmt;
@@ -208,12 +208,29 @@
res += sqlite3_bind_blob (stmt, 1, oldHash.GetHash (), oldHash.GetHashBytes (), SQLITE_STATIC);
res += sqlite3_bind_blob (stmt, 2, newHash.GetHash (), newHash.GetHashBytes (), SQLITE_STATIC);
+ SyncStateMsgPtr msg = make_shared<SyncStateMsg> ();
+
while (sqlite3_step (stmt) == SQLITE_ROW)
{
- std::cout << sqlite3_column_text (stmt, 0) <<
- ": from " << sqlite3_column_int64 (stmt, 1) <<
- " to " << sqlite3_column_int64 (stmt, 2) <<
- std::endl;
+ SyncState *state = msg->add_state ();
+
+ state->set_name (reinterpret_cast<const char*> (sqlite3_column_text (stmt, 0)));
+
+ sqlite3_int64 newSeqNo = sqlite3_column_int64 (stmt, 2);
+ if (newSeqNo > 0)
+ {
+ state->set_type (SyncState::UPDATE);
+ state->set_seq (newSeqNo);
+ }
+ else
+ state->set_type (SyncState::DELETE);
+
+ // std::cout << sqlite3_column_text (stmt, 0) <<
+ // ": from " << sqlite3_column_int64 (stmt, 1) <<
+ // " to " << sqlite3_column_int64 (stmt, 2) <<
+ // std::endl;
}
- sqlite3_finalize (stmt);
+ sqlite3_finalize (stmt);
+
+ return msg;
}
diff --git a/src/sync-log.h b/src/sync-log.h
index a597888..5705e45 100644
--- a/src/sync-log.h
+++ b/src/sync-log.h
@@ -23,6 +23,9 @@
#define SYNC_LOG_H
#include "db-helper.h"
+#include <sync-state.pb.h>
+
+typedef boost::shared_ptr<SyncStateMsg> SyncStateMsgPtr;
class SyncLog : public DbHelper
{
@@ -58,10 +61,10 @@
LookupSyncLog (const Hash &stateHash);
// How difference is exposed will be determined later by the actual protocol
- void
+ SyncStateMsgPtr
FindStateDifferences (const std::string &oldHash, const std::string &newHash);
- void
+ SyncStateMsgPtr
FindStateDifferences (const Hash &oldHash, const Hash &newHash);
};
diff --git a/src/sync-state.proto b/src/sync-state.proto
new file mode 100644
index 0000000..9ef5e33
--- /dev/null
+++ b/src/sync-state.proto
@@ -0,0 +1,24 @@
+// message Name
+// {
+// repeated bytes comp = 1;
+// }
+
+message SyncState
+{
+ // required Name name = 1;
+ required string name = 1;
+
+ enum ActionType
+ {
+ UPDATE = 0;
+ DELETE = 1;
+ }
+ required ActionType type = 2;
+
+ optional uint64 seq = 3;
+}
+
+message SyncStateMsg
+{
+ repeated SyncState state = 1;
+}