summaryrefslogtreecommitdiffstats
path: root/common/storage
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage')
-rw-r--r--common/storage/entitystore.cpp73
-rw-r--r--common/storage/entitystore.h1
-rw-r--r--common/storage/key.cpp156
-rw-r--r--common/storage/key.h100
4 files changed, 307 insertions, 23 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp
index dd6bbf0..3addf94 100644
--- a/common/storage/entitystore.cpp
+++ b/common/storage/entitystore.cpp
@@ -237,8 +237,10 @@ bool EntityStore::add(const QByteArray &type, ApplicationDomainType entity, bool
237 flatbuffers::FlatBufferBuilder fbb; 237 flatbuffers::FlatBufferBuilder fbb;
238 d->resourceContext.adaptorFactory(type).createBuffer(entity, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize()); 238 d->resourceContext.adaptorFactory(type).createBuffer(entity, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize());
239 239
240 const auto key = Key(Identifier::fromDisplayByteArray(entity.identifier()), newRevision);
241
240 DataStore::mainDatabase(d->transaction, type) 242 DataStore::mainDatabase(d->transaction, type)
241 .write(DataStore::assembleKey(entity.identifier(), newRevision), BufferUtils::extractBuffer(fbb), 243 .write(key.toInternalByteArray(), BufferUtils::extractBuffer(fbb),
242 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << entity.identifier() << newRevision; }); 244 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << entity.identifier() << newRevision; });
243 DataStore::setMaxRevision(d->transaction, newRevision); 245 DataStore::setMaxRevision(d->transaction, newRevision);
244 DataStore::recordRevision(d->transaction, newRevision, entity.identifier(), type); 246 DataStore::recordRevision(d->transaction, newRevision, entity.identifier(), type);
@@ -311,8 +313,10 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomainType &cu
311 flatbuffers::FlatBufferBuilder fbb; 313 flatbuffers::FlatBufferBuilder fbb;
312 d->resourceContext.adaptorFactory(type).createBuffer(newEntity, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize()); 314 d->resourceContext.adaptorFactory(type).createBuffer(newEntity, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize());
313 315
316 const auto key = Key(Identifier::fromDisplayByteArray(newEntity.identifier()), newRevision);
317
314 DataStore::mainDatabase(d->transaction, type) 318 DataStore::mainDatabase(d->transaction, type)
315 .write(DataStore::assembleKey(newEntity.identifier(), newRevision), BufferUtils::extractBuffer(fbb), 319 .write(key.toInternalByteArray(), BufferUtils::extractBuffer(fbb),
316 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << newEntity.identifier() << newRevision; }); 320 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << newEntity.identifier() << newRevision; });
317 DataStore::setMaxRevision(d->transaction, newRevision); 321 DataStore::setMaxRevision(d->transaction, newRevision);
318 DataStore::recordRevision(d->transaction, newRevision, newEntity.identifier(), type); 322 DataStore::recordRevision(d->transaction, newRevision, newEntity.identifier(), type);
@@ -346,8 +350,10 @@ bool EntityStore::remove(const QByteArray &type, const ApplicationDomainType &cu
346 flatbuffers::FlatBufferBuilder fbb; 350 flatbuffers::FlatBufferBuilder fbb;
347 EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), 0, 0, 0, 0); 351 EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), 0, 0, 0, 0);
348 352
353 const auto key = Key(Identifier::fromDisplayByteArray(uid), newRevision);
354
349 DataStore::mainDatabase(d->transaction, type) 355 DataStore::mainDatabase(d->transaction, type)
350 .write(DataStore::assembleKey(uid, newRevision), BufferUtils::extractBuffer(fbb), 356 .write(key.toInternalByteArray(), BufferUtils::extractBuffer(fbb),
351 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << uid << newRevision; }); 357 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << uid << newRevision; });
352 DataStore::setMaxRevision(d->transaction, newRevision); 358 DataStore::setMaxRevision(d->transaction, newRevision);
353 DataStore::recordRevision(d->transaction, newRevision, uid, type); 359 DataStore::recordRevision(d->transaction, newRevision, uid, type);
@@ -365,8 +371,9 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision)
365 return; 371 return;
366 } 372 }
367 SinkTraceCtx(d->logCtx) << "Cleaning up revision " << revision << uid << bufferType; 373 SinkTraceCtx(d->logCtx) << "Cleaning up revision " << revision << uid << bufferType;
374 const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray();
368 DataStore::mainDatabase(d->transaction, bufferType) 375 DataStore::mainDatabase(d->transaction, bufferType)
369 .scan(uid, 376 .scan(internalUid,
370 [&](const QByteArray &key, const QByteArray &data) -> bool { 377 [&](const QByteArray &key, const QByteArray &data) -> bool {
371 EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); 378 EntityBuffer buffer(const_cast<const char *>(data.data()), data.size());
372 if (!buffer.isValid()) { 379 if (!buffer.isValid()) {
@@ -428,7 +435,7 @@ QVector<QByteArray> EntityStore::fullScan(const QByteArray &type)
428 DataStore::mainDatabase(d->getTransaction(), type) 435 DataStore::mainDatabase(d->getTransaction(), type)
429 .scan(QByteArray(), 436 .scan(QByteArray(),
430 [&](const QByteArray &key, const QByteArray &value) -> bool { 437 [&](const QByteArray &key, const QByteArray &value) -> bool {
431 const auto uid = DataStore::uidFromKey(key); 438 const auto uid = Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray();
432 if (keys.contains(uid)) { 439 if (keys.contains(uid)) {
433 //Not something that should persist if the replay works, so we keep a message for now. 440 //Not something that should persist if the replay works, so we keep a message for now.
434 SinkTraceCtx(d->logCtx) << "Multiple revisions for key: " << key; 441 SinkTraceCtx(d->logCtx) << "Multiple revisions for key: " << key;
@@ -479,16 +486,26 @@ void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property
479 /* }); */ 486 /* }); */
480} 487}
481 488
482void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) 489void EntityStore::readLatest(const QByteArray &type, const QByteArray &key, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback)
483{ 490{
484 Q_ASSERT(d); 491 Q_ASSERT(d);
485 Q_ASSERT(!uid.isEmpty()); 492 Q_ASSERT(!key.isEmpty());
493 // TODO: we shouldn't pass whole keys to this function
494 // check the testSingle test from querytest
495 const auto internalKey = [&key]() {
496 if(key.size() == Identifier::DISPLAY_REPR_SIZE) {
497 return Identifier::fromDisplayByteArray(key).toInternalByteArray();
498 } else {
499 return Key::fromDisplayByteArray(key).toInternalByteArray();
500 }
501 }();
486 auto db = DataStore::mainDatabase(d->getTransaction(), type); 502 auto db = DataStore::mainDatabase(d->getTransaction(), type);
487 db.findLatest(uid, 503 db.findLatest(internalKey,
488 [=](const QByteArray &key, const QByteArray &value) { 504 [=](const QByteArray &key, const QByteArray &value) {
489 callback(DataStore::uidFromKey(key), Sink::EntityBuffer(value.data(), value.size())); 505 const auto uid = Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray();
506 callback(uid, Sink::EntityBuffer(value.data(), value.size()));
490 }, 507 },
491 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Error during readLatest query: " << error.message << uid; }); 508 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Error during readLatest query: " << error.message << key; });
492} 509}
493 510
494void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomainType &)> callback) 511void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomainType &)> callback)
@@ -516,12 +533,14 @@ ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArra
516 return dt; 533 return dt;
517} 534}
518 535
519void EntityStore::readEntity(const QByteArray &type, const QByteArray &key, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) 536void EntityStore::readEntity(const QByteArray &type, const QByteArray &displayKey, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback)
520{ 537{
538 const auto key = Key::fromDisplayByteArray(displayKey);
521 auto db = DataStore::mainDatabase(d->getTransaction(), type); 539 auto db = DataStore::mainDatabase(d->getTransaction(), type);
522 db.scan(key, 540 db.scan(key.toInternalByteArray(),
523 [=](const QByteArray &key, const QByteArray &value) -> bool { 541 [=](const QByteArray &key, const QByteArray &value) -> bool {
524 callback(DataStore::uidFromKey(key), Sink::EntityBuffer(value.data(), value.size())); 542 const auto uid = Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray();
543 callback(uid, Sink::EntityBuffer(value.data(), value.size()));
525 return false; 544 return false;
526 }, 545 },
527 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Error during readEntity query: " << error.message << key; }); 546 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Error during readEntity query: " << error.message << key; });
@@ -567,9 +586,10 @@ void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedT
567 revisionCounter++; 586 revisionCounter++;
568 continue; 587 continue;
569 } 588 }
570 const auto key = DataStore::assembleKey(uid, revisionCounter); 589 const auto key = Key(Identifier::fromDisplayByteArray(uid), revisionCounter);
590
571 revisionCounter++; 591 revisionCounter++;
572 callback(key); 592 callback(key.toDisplayByteArray());
573 } 593 }
574} 594}
575 595
@@ -577,16 +597,18 @@ void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qi
577{ 597{
578 auto db = DataStore::mainDatabase(d->getTransaction(), type); 598 auto db = DataStore::mainDatabase(d->getTransaction(), type);
579 qint64 latestRevision = 0; 599 qint64 latestRevision = 0;
580 db.scan(uid, 600 const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray();
601 db.scan(internalUid,
581 [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { 602 [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool {
582 const auto foundRevision = DataStore::revisionFromKey(key); 603 const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64();
583 if (foundRevision < revision && foundRevision > latestRevision) { 604 if (foundRevision < revision && foundRevision > latestRevision) {
584 latestRevision = foundRevision; 605 latestRevision = foundRevision;
585 } 606 }
586 return true; 607 return true;
587 }, 608 },
588 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true); 609 [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true);
589 readEntity(type, DataStore::assembleKey(uid, latestRevision), callback); 610 const auto key = Key(Identifier::fromDisplayByteArray(uid), latestRevision);
611 readEntity(type, key.toDisplayByteArray(), callback);
590} 612}
591 613
592void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomainType &)> callback) 614void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomainType &)> callback)
@@ -612,15 +634,18 @@ void EntityStore::readAllUids(const QByteArray &type, const std::function<void(c
612 634
613bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) 635bool EntityStore::contains(const QByteArray &type, const QByteArray &uid)
614{ 636{
615 return DataStore::mainDatabase(d->getTransaction(), type).contains(uid); 637 Q_ASSERT(!uid.isEmpty());
638 const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray();
639 return DataStore::mainDatabase(d->getTransaction(), type).contains(internalUid);
616} 640}
617 641
618bool EntityStore::exists(const QByteArray &type, const QByteArray &uid) 642bool EntityStore::exists(const QByteArray &type, const QByteArray &uid)
619{ 643{
620 bool found = false; 644 bool found = false;
621 bool alreadyRemoved = false; 645 bool alreadyRemoved = false;
646 const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray();
622 DataStore::mainDatabase(d->transaction, type) 647 DataStore::mainDatabase(d->transaction, type)
623 .findLatest(uid, 648 .findLatest(internalUid,
624 [&found, &alreadyRemoved](const QByteArray &key, const QByteArray &data) { 649 [&found, &alreadyRemoved](const QByteArray &key, const QByteArray &data) {
625 auto entity = GetEntity(data.data()); 650 auto entity = GetEntity(data.data());
626 if (entity && entity->metadata()) { 651 if (entity && entity->metadata()) {
@@ -647,12 +672,14 @@ void EntityStore::readRevisions(const QByteArray &type, const QByteArray &uid, q
647{ 672{
648 Q_ASSERT(d); 673 Q_ASSERT(d);
649 Q_ASSERT(!uid.isEmpty()); 674 Q_ASSERT(!uid.isEmpty());
675 const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray();
650 DataStore::mainDatabase(d->transaction, type) 676 DataStore::mainDatabase(d->transaction, type)
651 .scan(uid, 677 .scan(internalUid,
652 [&](const QByteArray &key, const QByteArray &value) -> bool { 678 [&](const QByteArray &key, const QByteArray &value) -> bool {
653 const auto revision = DataStore::revisionFromKey(key); 679 const auto parsedKey = Key::fromInternalByteArray(key);
680 const auto revision = parsedKey.revision().toQint64();
654 if (revision >= startingRevision) { 681 if (revision >= startingRevision) {
655 callback(DataStore::uidFromKey(key), revision, Sink::EntityBuffer(value.data(), value.size())); 682 callback(parsedKey.identifier().toDisplayByteArray(), revision, Sink::EntityBuffer(value.data(), value.size()));
656 } 683 }
657 return true; 684 return true;
658 }, 685 },
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h
index 69de76c..1dcd285 100644
--- a/common/storage/entitystore.h
+++ b/common/storage/entitystore.h
@@ -25,6 +25,7 @@
25#include "domaintypeadaptorfactoryinterface.h" 25#include "domaintypeadaptorfactoryinterface.h"
26#include "query.h" 26#include "query.h"
27#include "storage.h" 27#include "storage.h"
28#include "key.h"
28#include "resourcecontext.h" 29#include "resourcecontext.h"
29#include "metadata_generated.h" 30#include "metadata_generated.h"
30 31
diff --git a/common/storage/key.cpp b/common/storage/key.cpp
new file mode 100644
index 0000000..01a3e3a
--- /dev/null
+++ b/common/storage/key.cpp
@@ -0,0 +1,156 @@
1/*
2 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm>
3 * Copyright (C) 2018 Rémi Nicole <minijackson@riseup.net>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) version 3, or any
9 * later version accepted by the membership of KDE e.V. (or its
10 * successor approved by the membership of KDE e.V.), which shall
11 * act as a proxy defined in Section 6 of version 3 of the license.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "key.h"
23#include "utils.h"
24
25using Sink::Storage::Identifier;
26using Sink::Storage::Key;
27using Sink::Storage::Revision;
28
29QDebug &operator<<(QDebug &dbg, const Identifier &id)
30{
31 dbg << id.toDisplayString();
32 return dbg;
33}
34
35QDebug &operator<<(QDebug &dbg, const Revision &rev)
36{
37 dbg << rev.toDisplayString();
38 return dbg;
39}
40
41QDebug &operator<<(QDebug &dbg, const Key &key)
42{
43 dbg << key.toDisplayString();
44 return dbg;
45}
46
47// Identifier
48
49QByteArray Identifier::toInternalByteArray() const
50{
51 return uid.toRfc4122();
52}
53
54Identifier Identifier::fromInternalByteArray(const QByteArray &bytes)
55{
56 Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE);
57 return Identifier(QUuid::fromRfc4122(bytes));
58}
59
60QString Identifier::toDisplayString() const
61{
62 return uid.toString();
63}
64
65QByteArray Identifier::toDisplayByteArray() const
66{
67 return uid.toByteArray();
68}
69
70Identifier Identifier::fromDisplayByteArray(const QByteArray &bytes)
71{
72 Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE);
73 return Identifier(QUuid(bytes));
74}
75
76// Revision
77
78QByteArray Revision::toInternalByteArray() const
79{
80 return padNumber(rev);
81}
82
83Revision Revision::fromInternalByteArray(const QByteArray &bytes)
84{
85 Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE);
86 return Revision(bytes.toLongLong());
87}
88
89QString Revision::toDisplayString() const
90{
91 return QString::fromUtf8(toInternalByteArray());
92}
93
94QByteArray Revision::toDisplayByteArray() const
95{
96 return toInternalByteArray();
97}
98
99Revision Revision::fromDisplayByteArray(const QByteArray &bytes)
100{
101 Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE);
102 return fromInternalByteArray(bytes);
103}
104
105qint64 Revision::toQint64() const
106{
107 return rev;
108}
109
110// Key
111
112QByteArray Key::toInternalByteArray() const
113{
114 return id.toInternalByteArray() + rev.toInternalByteArray();
115}
116
117Key Key::fromInternalByteArray(const QByteArray &bytes)
118{
119 Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE);
120 auto idBytes = bytes.mid(0, Identifier::INTERNAL_REPR_SIZE);
121 auto revBytes = bytes.mid(Identifier::INTERNAL_REPR_SIZE);
122 return Key(Identifier::fromInternalByteArray(idBytes), Revision::fromInternalByteArray(revBytes));
123}
124
125QString Key::toDisplayString() const
126{
127 return id.toDisplayString() + rev.toDisplayString();
128}
129
130QByteArray Key::toDisplayByteArray() const
131{
132 return id.toDisplayByteArray() + rev.toDisplayByteArray();
133}
134
135Key Key::fromDisplayByteArray(const QByteArray &bytes)
136{
137 Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE);
138 auto idBytes = bytes.mid(0, Identifier::DISPLAY_REPR_SIZE);
139 auto revBytes = bytes.mid(Identifier::DISPLAY_REPR_SIZE);
140 return Key(Identifier::fromDisplayByteArray(idBytes), Revision::fromDisplayByteArray(revBytes));
141}
142
143const Identifier &Key::identifier() const
144{
145 return id;
146}
147
148const Revision &Key::revision() const
149{
150 return rev;
151}
152
153void Key::setRevision(const Revision &newRev)
154{
155 rev = newRev;
156}
diff --git a/common/storage/key.h b/common/storage/key.h
new file mode 100644
index 0000000..76dbd13
--- /dev/null
+++ b/common/storage/key.h
@@ -0,0 +1,100 @@
1/*
2 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm>
3 * Copyright (C) 2018 Rémi Nicole <minijackson@riseup.net>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) version 3, or any
9 * later version accepted by the membership of KDE e.V. (or its
10 * successor approved by the membership of KDE e.V.), which shall
11 * act as a proxy defined in Section 6 of version 3 of the license.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "sink_export.h"
25
26#include <QByteArray>
27#include <QDebug>
28#include <QUuid>
29
30namespace Sink {
31namespace Storage {
32
33class Identifier
34{
35public:
36 // RFC 4122 Section 4.1.2 says 128 bits -> 16 bytes
37 static const constexpr size_t INTERNAL_REPR_SIZE = 16;
38 static const constexpr size_t DISPLAY_REPR_SIZE = 38;
39
40 Identifier() : uid(QUuid::createUuid()){};
41
42 QByteArray toInternalByteArray() const;
43 static Identifier fromInternalByteArray(const QByteArray &bytes);
44 QString toDisplayString() const;
45 QByteArray toDisplayByteArray() const;
46 static Identifier fromDisplayByteArray(const QByteArray &bytes);
47
48private:
49 explicit Identifier(const QUuid &uid) : uid(uid) {}
50 QUuid uid;
51};
52
53class Revision
54{
55public:
56 // qint64 has a 19 digit decimal representation
57 static const constexpr size_t INTERNAL_REPR_SIZE = 19;
58 static const constexpr size_t DISPLAY_REPR_SIZE = 19;
59
60 Revision(qint64 rev) : rev(rev) {}
61
62 QByteArray toInternalByteArray() const;
63 static Revision fromInternalByteArray(const QByteArray &bytes);
64 QString toDisplayString() const;
65 QByteArray toDisplayByteArray() const;
66 static Revision fromDisplayByteArray(const QByteArray &bytes);
67 qint64 toQint64() const;
68
69private:
70 qint64 rev;
71};
72
73class Key
74{
75public:
76 static const constexpr size_t INTERNAL_REPR_SIZE = Identifier::INTERNAL_REPR_SIZE + Revision::INTERNAL_REPR_SIZE;
77 static const constexpr size_t DISPLAY_REPR_SIZE = Identifier::DISPLAY_REPR_SIZE + Revision::DISPLAY_REPR_SIZE;
78
79 Key(const Identifier &id, const Revision &rev) : id(id), rev(rev) {}
80
81 QByteArray toInternalByteArray() const;
82 static Key fromInternalByteArray(const QByteArray &bytes);
83 QString toDisplayString() const;
84 QByteArray toDisplayByteArray() const;
85 static Key fromDisplayByteArray(const QByteArray &bytes);
86 const Identifier &identifier() const;
87 const Revision &revision() const;
88 void setRevision(const Revision &newRev);
89
90private:
91 Identifier id;
92 Revision rev;
93};
94
95} // namespace Storage
96} // namespace Sink
97
98SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Identifier &);
99SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Revision &);
100SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Key &);