diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index c78583cad..07b7cadec 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -1151,6 +1151,17 @@ template const T *GetRoot(const void *buf) { return GetMutableRoot(const_cast(buf)); } +/// Helpers to get a typed pointer to objects that are currently beeing built. +/// @warning Creating new objects will lead to reallocations and invalidates the pointer! +template T *GetMutableObject(FlatBufferBuilder &fbb, Offset offset) { + return reinterpret_cast(fbb.GetCurrentBufferPointer() + + fbb.GetSize() - offset.o); +} + +template const T *GetObject(FlatBufferBuilder &fbb, Offset offset) { + return GetMutableObject(fbb, offset); +} + // Helper to see if the identifier in a buffer has the expected value. inline bool BufferHasIdentifier(const void *buf, const char *identifier) { return strncmp(reinterpret_cast(buf) + sizeof(uoffset_t),