diff options
Diffstat (limited to 'common/entitybuffer.h')
-rw-r--r-- | common/entitybuffer.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/common/entitybuffer.h b/common/entitybuffer.h index 097b450..82152c9 100644 --- a/common/entitybuffer.h +++ b/common/entitybuffer.h | |||
@@ -15,7 +15,33 @@ 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); | ||
26 | template<typename T> | ||
27 | static const T *readBuffer(const uint8_t *data, int size) | ||
28 | { | ||
29 | flatbuffers::Verifier verifier(data, size); | ||
30 | if (verifier.VerifyBuffer<T>()) { | ||
31 | return flatbuffers::GetRoot<T>(data); | ||
32 | } | ||
33 | return nullptr; | ||
34 | } | ||
35 | |||
36 | template<typename T> | ||
37 | static const T *readBuffer(const flatbuffers::Vector<uint8_t> *data) | ||
38 | { | ||
39 | if (data) { | ||
40 | return readBuffer<T>(data->Data(), data->size()); | ||
41 | } | ||
42 | return nullptr; | ||
43 | } | ||
44 | |||
19 | 45 | ||
20 | private: | 46 | private: |
21 | const Entity *mEntity; | 47 | const Entity *mEntity; |