summaryrefslogtreecommitdiffstats
path: root/common/entitybuffer.h
blob: f22c84ee136cf671a5b365763d44866c33c55ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once

#include <functional>
#include <flatbuffers/flatbuffers.h>

namespace Akonadi2 {
class Entity;

class EntityBuffer {
public:
    EntityBuffer(void *dataValue, int size);
    const uint8_t *resourceBuffer();
    const uint8_t *metadataBuffer();
    const uint8_t *localBuffer();
    const Entity &entity();

    static void extractResourceBuffer(void *dataValue, int dataSize, const std::function<void(const uint8_t *, size_t size)> &handler);
    /*
     * TODO: Ideally we would be passing references to vectors in the same bufferbuilder, to avoid needlessly copying data.
     * Unfortunately I couldn't find a way to cast a table to a vector<uint8_t> reference.
     * 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
     * the entity schema for each resource's buffers.
     */
    static void assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, void const *metadataData, size_t metadataSize, void const *resourceData, size_t resourceSize, void const *localData, size_t localSize);
    static flatbuffers::Offset<flatbuffers::Vector<uint8_t> > appendAsVector(flatbuffers::FlatBufferBuilder &fbb, void const *data, size_t size);

private:
    const Entity *mEntity;
};

}