From 922e0979e2c27ff8dbc765ae151d17c7815b98a0 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 26 Jun 2018 11:44:11 +0200 Subject: [Storage] Implement Key API --- common/storage_common.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'common/storage_common.cpp') diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 057dce4..b36ffcb 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp @@ -24,18 +24,40 @@ #include "log.h" #include "utils.h" +#include + QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error) { dbg << error.message << "Code: " << error.code << "Db: " << error.store; return dbg; } +QDebug& operator<<(QDebug &dbg, const Sink::Storage::Identifier &id) +{ + dbg << id.toDisplayString(); + return dbg; +} + +QDebug& operator<<(QDebug &dbg, const Sink::Storage::Revision &rev) +{ + dbg << rev.toDisplayString(); + return dbg; +} + +QDebug& operator<<(QDebug &dbg, const Sink::Storage::Key &key) +{ + dbg << key.toDisplayString(); + return dbg; +} + namespace Sink { namespace Storage { static const char *s_internalPrefix = "__internal"; static const int s_internalPrefixSize = strlen(s_internalPrefix); static const int s_lengthOfUid = 38; +// RFC 4122 Section 4.1.2 says 128 bits -> 16 bytes +//static const int s_lengthOfUid = 16; DbLayout::DbLayout() { @@ -194,6 +216,7 @@ bool DataStore::isInternalKey(const QByteArray &key) return key.startsWith(s_internalPrefix); } +/* QByteArray DataStore::assembleKey(const QByteArray &key, qint64 revision) { Q_ASSERT(revision <= 9223372036854775807); @@ -201,15 +224,17 @@ QByteArray DataStore::assembleKey(const QByteArray &key, qint64 revision) return key + QByteArray::number(revision).rightJustified(19, '0', false); } -QByteArray DataStore::uidFromKey(const QByteArray &key) +//QByteArray DataStore::uidFromKey(const QByteArray &key) +Identifier DataStore::uidFromKey(const QByteArray &key) { - return key.mid(0, s_lengthOfUid); + return Identifier::fromByteArray(key.mid(0, s_lengthOfUid)); } qint64 DataStore::revisionFromKey(const QByteArray &key) { return key.mid(s_lengthOfUid + 1).toLongLong(); } +*/ QByteArray DataStore::generateUid() { -- cgit v1.2.3