diff options
Diffstat (limited to 'sinksh/syntax_modules')
-rw-r--r-- | sinksh/syntax_modules/sink_inspect.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 7a41ef0..f9cc50a 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp | |||
@@ -41,6 +41,20 @@ | |||
41 | namespace SinkInspect | 41 | namespace SinkInspect |
42 | { | 42 | { |
43 | 43 | ||
44 | using Sink::Storage::Key; | ||
45 | using Sink::Storage::Identifier; | ||
46 | |||
47 | QString parse(const QByteArray &bytes) | ||
48 | { | ||
49 | if (Key::isValidInternal(bytes)) { | ||
50 | return Key::fromInternalByteArray(bytes).toDisplayString(); | ||
51 | } else if (Identifier::isValidInternal(bytes)) { | ||
52 | return Identifier::fromInternalByteArray(bytes).toDisplayString(); | ||
53 | } else { | ||
54 | return QString::fromUtf8(bytes); | ||
55 | } | ||
56 | } | ||
57 | |||
44 | bool inspect(const QStringList &args, State &state) | 58 | bool inspect(const QStringList &args, State &state) |
45 | { | 59 | { |
46 | if (args.isEmpty()) { | 60 | if (args.isEmpty()) { |
@@ -90,7 +104,7 @@ bool inspect(const QStringList &args, State &state) | |||
90 | 104 | ||
91 | QSet<QByteArray> uids; | 105 | QSet<QByteArray> uids; |
92 | db.scan("", [&] (const QByteArray &key, const QByteArray &data) { | 106 | db.scan("", [&] (const QByteArray &key, const QByteArray &data) { |
93 | uids.insert(Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); | 107 | uids.insert(Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); |
94 | return true; | 108 | return true; |
95 | }, | 109 | }, |
96 | [&](const Sink::Storage::DataStore::Error &e) { | 110 | [&](const Sink::Storage::DataStore::Error &e) { |
@@ -187,13 +201,16 @@ bool inspect(const QStringList &args, State &state) | |||
187 | auto count = db.scan(filter, [&] (const QByteArray &key, const QByteArray &data) { | 201 | auto count = db.scan(filter, [&] (const QByteArray &key, const QByteArray &data) { |
188 | keySizeTotal += key.size(); | 202 | keySizeTotal += key.size(); |
189 | valueSizeTotal += data.size(); | 203 | valueSizeTotal += data.size(); |
204 | |||
205 | const auto parsedKey = parse(key); | ||
206 | |||
190 | if (isMainDb) { | 207 | if (isMainDb) { |
191 | Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); | 208 | Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); |
192 | if (!buffer.isValid()) { | 209 | if (!buffer.isValid()) { |
193 | state.printError("Read invalid buffer from disk: " + key); | 210 | state.printError("Read invalid buffer from disk: " + parsedKey); |
194 | } else { | 211 | } else { |
195 | const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); | 212 | const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); |
196 | state.printLine("Key: " + key | 213 | state.printLine("Key: " + parsedKey |
197 | + " Operation: " + QString::number(metadata->operation()) | 214 | + " Operation: " + QString::number(metadata->operation()) |
198 | + " Replay: " + (metadata->replayToSource() ? "true" : "false") | 215 | + " Replay: " + (metadata->replayToSource() ? "true" : "false") |
199 | + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" [" + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(", ")) + "]": "") | 216 | + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" [" + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(", ")) + "]": "") |
@@ -201,7 +218,7 @@ bool inspect(const QStringList &args, State &state) | |||
201 | ); | 218 | ); |
202 | } | 219 | } |
203 | } else { | 220 | } else { |
204 | state.printLine("Key: " + key + "\tValue: " + QString::fromUtf8(data)); | 221 | state.printLine("Key: " + parsedKey + "\tValue: " + parse(data)); |
205 | } | 222 | } |
206 | return true; | 223 | return true; |
207 | }, | 224 | }, |