summaryrefslogtreecommitdiffstats
path: root/common/storage_common.cpp
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2018-06-26 11:44:11 +0200
committerMinijackson <minijackson@riseup.net>2018-07-04 15:37:14 +0200
commit922e0979e2c27ff8dbc765ae151d17c7815b98a0 (patch)
treecb031c5d3ccc31ea576f66b4f718c17f5bb0775c /common/storage_common.cpp
parent06f30d0f0d0051df97d4c34cd1a80b14857c9e9c (diff)
downloadsink-922e0979e2c27ff8dbc765ae151d17c7815b98a0.tar.gz
sink-922e0979e2c27ff8dbc765ae151d17c7815b98a0.zip
[Storage] Implement Key API
Diffstat (limited to 'common/storage_common.cpp')
-rw-r--r--common/storage_common.cpp29
1 files changed, 27 insertions, 2 deletions
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 @@
24#include "log.h" 24#include "log.h"
25#include "utils.h" 25#include "utils.h"
26 26
27#include <QUuid>
28
27QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error) 29QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error)
28{ 30{
29 dbg << error.message << "Code: " << error.code << "Db: " << error.store; 31 dbg << error.message << "Code: " << error.code << "Db: " << error.store;
30 return dbg; 32 return dbg;
31} 33}
32 34
35QDebug& operator<<(QDebug &dbg, const Sink::Storage::Identifier &id)
36{
37 dbg << id.toDisplayString();
38 return dbg;
39}
40
41QDebug& operator<<(QDebug &dbg, const Sink::Storage::Revision &rev)
42{
43 dbg << rev.toDisplayString();
44 return dbg;
45}
46
47QDebug& operator<<(QDebug &dbg, const Sink::Storage::Key &key)
48{
49 dbg << key.toDisplayString();
50 return dbg;
51}
52
33namespace Sink { 53namespace Sink {
34namespace Storage { 54namespace Storage {
35 55
36static const char *s_internalPrefix = "__internal"; 56static const char *s_internalPrefix = "__internal";
37static const int s_internalPrefixSize = strlen(s_internalPrefix); 57static const int s_internalPrefixSize = strlen(s_internalPrefix);
38static const int s_lengthOfUid = 38; 58static const int s_lengthOfUid = 38;
59// RFC 4122 Section 4.1.2 says 128 bits -> 16 bytes
60//static const int s_lengthOfUid = 16;
39 61
40DbLayout::DbLayout() 62DbLayout::DbLayout()
41{ 63{
@@ -194,6 +216,7 @@ bool DataStore::isInternalKey(const QByteArray &key)
194 return key.startsWith(s_internalPrefix); 216 return key.startsWith(s_internalPrefix);
195} 217}
196 218
219/*
197QByteArray DataStore::assembleKey(const QByteArray &key, qint64 revision) 220QByteArray DataStore::assembleKey(const QByteArray &key, qint64 revision)
198{ 221{
199 Q_ASSERT(revision <= 9223372036854775807); 222 Q_ASSERT(revision <= 9223372036854775807);
@@ -201,15 +224,17 @@ QByteArray DataStore::assembleKey(const QByteArray &key, qint64 revision)
201 return key + QByteArray::number(revision).rightJustified(19, '0', false); 224 return key + QByteArray::number(revision).rightJustified(19, '0', false);
202} 225}
203 226
204QByteArray DataStore::uidFromKey(const QByteArray &key) 227//QByteArray DataStore::uidFromKey(const QByteArray &key)
228Identifier DataStore::uidFromKey(const QByteArray &key)
205{ 229{
206 return key.mid(0, s_lengthOfUid); 230 return Identifier::fromByteArray(key.mid(0, s_lengthOfUid));
207} 231}
208 232
209qint64 DataStore::revisionFromKey(const QByteArray &key) 233qint64 DataStore::revisionFromKey(const QByteArray &key)
210{ 234{
211 return key.mid(s_lengthOfUid + 1).toLongLong(); 235 return key.mid(s_lengthOfUid + 1).toLongLong();
212} 236}
237*/
213 238
214QByteArray DataStore::generateUid() 239QByteArray DataStore::generateUid()
215{ 240{