diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/entitybuffer.cpp | 27 | ||||
-rw-r--r-- | common/entitybuffer.h | 7 |
2 files changed, 24 insertions, 10 deletions
diff --git a/common/entitybuffer.cpp b/common/entitybuffer.cpp index 5ba4afe..b555ac3 100644 --- a/common/entitybuffer.cpp +++ b/common/entitybuffer.cpp | |||
@@ -56,17 +56,24 @@ void EntityBuffer::extractResourceBuffer(void *dataValue, int dataSize, const st | |||
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | void EntityBuffer::assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, void const *metadataData, size_t metadataSize, void const *resourceData, size_t resourceSize, void const *localData, size_t localSize) | 59 | flatbuffers::Offset<flatbuffers::Vector<uint8_t> > EntityBuffer::appendAsVector(flatbuffers::FlatBufferBuilder &fbb, void const *data, size_t size) |
60 | { | 60 | { |
61 | auto metadata = fbb.CreateVector<uint8_t>(static_cast<uint8_t const*>(metadataData), metadataSize); | 61 | //Since we do memcpy trickery, this will only work on little endian |
62 | auto resource = fbb.CreateVector<uint8_t>(static_cast<uint8_t const*>(resourceData), resourceSize); | 62 | assert(FLATBUFFERS_LITTLEENDIAN); |
63 | auto local = fbb.CreateVector<uint8_t>(static_cast<uint8_t const*>(localData), localSize); | 63 | auto metadata = fbb.CreateUninitializedVector<uint8_t>(size); |
64 | auto builder = Akonadi2::EntityBuilder(fbb); | 64 | { |
65 | builder.add_metadata(metadata); | 65 | auto ptr = reinterpret_cast<flatbuffers::Vector<uint8_t> *>(fbb.GetBufferPointer())->Data(); |
66 | builder.add_resource(resource); | 66 | std::memcpy((void*)ptr, data, size); |
67 | builder.add_local(local); | 67 | } |
68 | return metadata; | ||
69 | } | ||
68 | 70 | ||
69 | auto buffer = builder.Finish(); | 71 | void EntityBuffer::assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, void const *metadataData, size_t metadataSize, void const *resourceData, size_t resourceSize, void const *localData, size_t localSize) |
70 | Akonadi2::FinishEntityBuffer(fbb, buffer); | 72 | { |
73 | auto metadata = appendAsVector(fbb, metadataData, metadataSize); | ||
74 | auto resource = appendAsVector(fbb, resourceData, resourceSize); | ||
75 | auto local = appendAsVector(fbb, localData, localSize); | ||
76 | auto entity = Akonadi2::CreateEntity(fbb, metadata, resource, local); | ||
77 | Akonadi2::FinishEntityBuffer(fbb, entity); | ||
71 | } | 78 | } |
72 | 79 | ||
diff --git a/common/entitybuffer.h b/common/entitybuffer.h index 097b450..f22c84e 100644 --- a/common/entitybuffer.h +++ b/common/entitybuffer.h | |||
@@ -15,7 +15,14 @@ public: | |||
15 | const Entity &entity(); | 15 | const Entity &entity(); |
16 | 16 | ||
17 | static void extractResourceBuffer(void *dataValue, int dataSize, const std::function<void(const uint8_t *, size_t size)> &handler); | 17 | static void extractResourceBuffer(void *dataValue, int dataSize, const std::function<void(const uint8_t *, size_t size)> &handler); |
18 | /* | ||
19 | * TODO: Ideally we would be passing references to vectors in the same bufferbuilder, to avoid needlessly copying data. | ||
20 | * Unfortunately I couldn't find a way to cast a table to a vector<uint8_t> reference. | ||
21 | * We can't use union's either (which would allow to have a field that stores a selection of tables), as we don't want to modify | ||
22 | * the entity schema for each resource's buffers. | ||
23 | */ | ||
18 | static void assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, void const *metadataData, size_t metadataSize, void const *resourceData, size_t resourceSize, void const *localData, size_t localSize); | 24 | static void assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, void const *metadataData, size_t metadataSize, void const *resourceData, size_t resourceSize, void const *localData, size_t localSize); |
25 | static flatbuffers::Offset<flatbuffers::Vector<uint8_t> > appendAsVector(flatbuffers::FlatBufferBuilder &fbb, void const *data, size_t size); | ||
19 | 26 | ||
20 | private: | 27 | private: |
21 | const Entity *mEntity; | 28 | const Entity *mEntity; |