I'm new to flatbuffer
and I want to know if it's possible to get full (not const*) access to data in flatbuffers::Vector
. Looking at the example below, I want to steal the ownership of img2::mem::data
to store it in an Img-struct
and process it in any way I want. Is this somehow possible, without memcopy-ing?
struct Img
{
int iXCount;
int iYCount;
int iXOffset;
unsigned char *mem;
};
int _tmain(int argc, _TCHAR* argv[])
{
Img img;
//init img;
flatbuffers::FlatBufferBuilder fbb;
auto mem = fbb.CreateVector(img.mem, img.iXOffset * img.iYCount);
auto mloc = CreateImage(fbb, img.iXCount, img.iYCount, img.iXOffset, mem);
fbb.Finish(mloc);
//unpack
auto img2 = flatbuffers::GetRoot<Image>(fbb.GetBufferPointer());
const std::uint8_t*pMem = img2->mem()->data(); //unfortunately only const*
return 0;
}