Add a helper to efficiently copy a flatbuffer from Context
FlatbufferVector is a memcpy, instead of a reflection based copy or
hand-rolling the same operation. Put it in Context.
Change-Id: Ie26db53ad039f10b569138c1ff9c819ba32b9248
diff --git a/aos/events/event_loop.h b/aos/events/event_loop.h
index 1ad5c90..fa78953 100644
--- a/aos/events/event_loop.h
+++ b/aos/events/event_loop.h
@@ -58,6 +58,16 @@
size_t size;
// Pointer to the data.
const void *data;
+
+ // Efficiently coppies the flatbuffer into a FlatbufferVector, allocating
+ // memory in the process. It is vital that T matches the type of the
+ // underlying flatbuffer.
+ template <typename T>
+ FlatbufferVector<T> CopyFlatBuffer() const {
+ return FlatbufferVector<T>(
+ std::vector<uint8_t>(reinterpret_cast<const uint8_t *>(data),
+ reinterpret_cast<const uint8_t *>(data) + size));
+ }
};
// Raw version of fetcher. Contains a local variable that the fetcher will