From 6c5d7a65899f3b322184628c2be68fd3f3fdd5da Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 26 Jul 2018 17:00:03 +0200 Subject: Parse Keys in SinkSH inspect --- common/storage/key.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++- common/storage/key.h | 18 ++++++++++-- 2 files changed, 90 insertions(+), 4 deletions(-) (limited to 'common/storage') diff --git a/common/storage/key.cpp b/common/storage/key.cpp index cfeb016..215e155 100644 --- a/common/storage/key.cpp +++ b/common/storage/key.cpp @@ -84,6 +84,27 @@ bool Identifier::isNull() const return uid.isNull(); } +bool Identifier::isValidInternal(const QByteArray &bytes) +{ + return !QUuid::fromRfc4122(bytes).isNull(); +} + +bool Identifier::isValidDisplay(const QByteArray &bytes) +{ + return !QUuid(bytes).isNull(); +} + +bool Identifier::isValid(const QByteArray &bytes) +{ + switch (bytes.size()) { + case Identifier::INTERNAL_REPR_SIZE: + return isValidInternal(bytes); + case Identifier::DISPLAY_REPR_SIZE: + return isValidDisplay(bytes); + } + return false; +} + bool Identifier::operator==(const Identifier &other) const { return uid == other.uid; @@ -128,6 +149,27 @@ qint64 Revision::toQint64() const return rev; } +bool Revision::isValidInternal(const QByteArray &bytes) +{ + if (bytes.size() != Revision::INTERNAL_REPR_SIZE) { + return false; + } + + bool ok; + bytes.toLongLong(&ok); + return ok; +} + +bool Revision::isValidDisplay(const QByteArray &bytes) +{ + isValidInternal(bytes); +} + +bool Revision::isValid(const QByteArray &bytes) +{ + isValidInternal(bytes); +} + bool Revision::operator==(const Revision &other) const { return rev == other.rev; @@ -191,6 +233,39 @@ bool Key::isNull() const return id.isNull(); } +bool Key::isValidInternal(const QByteArray &bytes) +{ + if (bytes.size() != Key::INTERNAL_REPR_SIZE) { + return false; + } + + auto idBytes = bytes.mid(0, Identifier::INTERNAL_REPR_SIZE); + auto revBytes = bytes.mid(Identifier::INTERNAL_REPR_SIZE); + return Identifier::isValidInternal(idBytes) && Revision::isValidInternal(revBytes); +} + +bool Key::isValidDisplay(const QByteArray &bytes) +{ + if (bytes.size() != Key::DISPLAY_REPR_SIZE) { + return false; + } + + auto idBytes = bytes.mid(0, Identifier::DISPLAY_REPR_SIZE); + auto revBytes = bytes.mid(Identifier::DISPLAY_REPR_SIZE); + return Key::isValidDisplay(idBytes) && Revision::isValidDisplay(revBytes); +} + +bool Key::isValid(const QByteArray &bytes) +{ + switch (bytes.size()) { + case Key::INTERNAL_REPR_SIZE: + return isValidInternal(bytes); + case Key::DISPLAY_REPR_SIZE: + return isValidDisplay(bytes); + } + return false; +} + bool Key::operator==(const Key &other) const { return (id == other.id) && (rev == other.rev); @@ -200,4 +275,3 @@ bool Key::operator!=(const Key &other) const { return !(*this == other); } - diff --git a/common/storage/key.h b/common/storage/key.h index a5b92bb..211aea7 100644 --- a/common/storage/key.h +++ b/common/storage/key.h @@ -48,6 +48,10 @@ public: bool isNull() const; + static bool isValidInternal(const QByteArray &); + static bool isValidDisplay(const QByteArray &); + static bool isValid(const QByteArray &); + bool operator==(const Identifier &other) const; bool operator!=(const Identifier &other) const; @@ -72,6 +76,10 @@ public: static Revision fromDisplayByteArray(const QByteArray &bytes); qint64 toQint64() const; + static bool isValidInternal(const QByteArray &); + static bool isValidDisplay(const QByteArray &); + static bool isValid(const QByteArray &); + bool operator==(const Revision &other) const; bool operator!=(const Revision &other) const; @@ -99,6 +107,10 @@ public: bool isNull() const; + static bool isValidInternal(const QByteArray &); + static bool isValidDisplay(const QByteArray &); + static bool isValid(const QByteArray &); + bool operator==(const Key &other) const; bool operator!=(const Key &other) const; @@ -110,6 +122,6 @@ private: } // namespace Storage } // namespace Sink -SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Identifier &); -SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Revision &); -SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Key &); +SINK_EXPORT QDebug &operator<<(QDebug &dbg, const Sink::Storage::Identifier &); +SINK_EXPORT QDebug &operator<<(QDebug &dbg, const Sink::Storage::Revision &); +SINK_EXPORT QDebug &operator<<(QDebug &dbg, const Sink::Storage::Key &); -- cgit v1.2.3