diff options
Diffstat (limited to 'common/bufferutils.h')
-rw-r--r-- | common/bufferutils.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/common/bufferutils.h b/common/bufferutils.h new file mode 100644 index 0000000..b0fb75a --- /dev/null +++ b/common/bufferutils.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <flatbuffers/flatbuffers.h> | ||
4 | #include <QByteArray> | ||
5 | |||
6 | namespace Akonadi2 { | ||
7 | namespace BufferUtils { | ||
8 | template<typename T> | ||
9 | static QByteArray extractBuffer(const T *data) | ||
10 | { | ||
11 | return QByteArray::fromRawData(reinterpret_cast<char const *>(data->Data()), data->size()); | ||
12 | } | ||
13 | |||
14 | template<typename T> | ||
15 | static QByteArray extractBufferCopy(const T *data) | ||
16 | { | ||
17 | return QByteArray(reinterpret_cast<char const *>(data->Data()), data->size()); | ||
18 | } | ||
19 | |||
20 | static QByteArray extractBuffer(const flatbuffers::FlatBufferBuilder &fbb) | ||
21 | { | ||
22 | return QByteArray::fromRawData(reinterpret_cast<char const *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
23 | } | ||
24 | } | ||
25 | } | ||
26 | |||