diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-12-28 14:44:50 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-12-28 14:44:50 +0100 |
commit | 9b2257d680a5e4fa2fda8cf3302f25054a06710e (patch) | |
tree | 9abaf141018eb83d26ce07f5bd0e9436003ce732 /common/entitybuffer.cpp | |
parent | c83c2ef64b5a1e4b1dc0102df36687caebb96ff0 (diff) | |
download | sink-9b2257d680a5e4fa2fda8cf3302f25054a06710e.tar.gz sink-9b2257d680a5e4fa2fda8cf3302f25054a06710e.zip |
Buffers wrapped into entity buffer, async command progress tracking.
Diffstat (limited to 'common/entitybuffer.cpp')
-rw-r--r-- | common/entitybuffer.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/common/entitybuffer.cpp b/common/entitybuffer.cpp new file mode 100644 index 0000000..a78e91d --- /dev/null +++ b/common/entitybuffer.cpp | |||
@@ -0,0 +1,53 @@ | |||
1 | #include "entitybuffer.h" | ||
2 | |||
3 | #include "entity_generated.h" | ||
4 | #include "metadata_generated.h" | ||
5 | #include <QDebug> | ||
6 | |||
7 | using namespace Akonadi2; | ||
8 | |||
9 | EntityBuffer::EntityBuffer(void *dataValue, int dataSize) | ||
10 | : mEntity(nullptr) | ||
11 | { | ||
12 | flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(dataValue), dataSize); | ||
13 | // Q_ASSERT(Akonadi2::VerifyEntity(verifyer)); | ||
14 | if (!Akonadi2::VerifyEntityBuffer(verifyer)) { | ||
15 | qWarning() << "invalid buffer"; | ||
16 | } else { | ||
17 | mEntity = Akonadi2::GetEntity(dataValue); | ||
18 | } | ||
19 | } | ||
20 | |||
21 | const flatbuffers::Vector<uint8_t>* EntityBuffer::resourceBuffer() | ||
22 | { | ||
23 | if (!mEntity) { | ||
24 | qDebug() << "no buffer"; | ||
25 | return nullptr; | ||
26 | } | ||
27 | return mEntity->resource(); | ||
28 | } | ||
29 | |||
30 | const flatbuffers::Vector<uint8_t>* EntityBuffer::metadataBuffer() | ||
31 | { | ||
32 | if (!mEntity) { | ||
33 | return nullptr; | ||
34 | } | ||
35 | return mEntity->metadata(); | ||
36 | } | ||
37 | |||
38 | const flatbuffers::Vector<uint8_t>* EntityBuffer::localBuffer() | ||
39 | { | ||
40 | if (!mEntity) { | ||
41 | return nullptr; | ||
42 | } | ||
43 | return mEntity->local(); | ||
44 | } | ||
45 | |||
46 | void EntityBuffer::extractResourceBuffer(void *dataValue, int dataSize, const std::function<void(const flatbuffers::Vector<uint8_t> *)> &handler) | ||
47 | { | ||
48 | Akonadi2::EntityBuffer buffer(dataValue, dataSize); | ||
49 | if (auto resourceData = buffer.resourceBuffer()) { | ||
50 | handler(resourceData); | ||
51 | } | ||
52 | } | ||
53 | |||