Deserialize vector of table/struct

184 views
Skip to first unread message

icsym

unread,
Mar 27, 2018, 7:48:20 AM3/27/18
to FlatBuffers
Hi there,
I'm trying to serialize then deserialize a vector of tables.

Serialization of vector is ok but when I try to deserialize the vector like in this github issue :
const flatbuffers::Vector<playerBase> *vecStructFbPlayerBase = flatbuffers::GetRoot<flatbuffers::Vector<playerBase>>(m_receive_buffer);
vector<playerBase> deserialized;
 
for (flatbuffers::uoffset_t i = 0; i < vecStructFbPlayerBase->size(); i++)
deserialized.push_back(vecStructFbPlayerBase->Get(i));

I have a C2280 error by Visual Studio 2017 : "WarGame::fb::playerBase::playerBase(const WarGame::fb::playerBase &) : attempting to reference a deleted function"

When I use a vector of uint8_t like in example it's all okay :
const flatbuffers::Vector<uint8_t> *vecUint8_t = flatbuffers::GetRoot<flatbuffers::Vector<uint8_t>>(m_receive_buffer);

 I tried mutiple ways to access vecStructFbPlayerBase like vecStructFbPlayerBase[i], *vecStructFbPlayerBase->Get(i), &vecStructFbPlayerBase->Get(i), but still not working

Do you have any clue to deserialize a vector of tables ?
You'll find my schema in attachment.

Thanks in advance,
Bertrand
wargame.fbs

Wouter van Oortmerssen

unread,
Apr 2, 2018, 12:17:03 PM4/2/18
to icsym, FlatBuffers
It be better to make the root a table, like is still required by a lot of FlatBuffers code. The issue you are referencing is trying to do something non-standard, in most cases there is no gain from not having a root table containing the vector (costs just a few bytes more).


--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

icsym

unread,
Apr 5, 2018, 7:41:23 AM4/5/18
to FlatBuffers
It be better to make the root a table, like is still required by a lot of FlatBuffers code. The issue you are referencing is trying to do something non-standard, in most cases there is no gain from not having a root table containing the vector (costs just a few bytes more).

Thanks Wouter, I used a different table with a vector in it.

Quick question by the way: in order to detect message type (for example : table Monster, table Weapon) when I receive it, I need to use verifier right ?

Wouter van Oortmerssen

unread,
Apr 5, 2018, 1:02:52 PM4/5/18
to icsym, FlatBuffers
No, the verifier's main function is to protect C++ code from accessing out of bounds in the case that corrupted wire format is a problem.

By default, you're supposed to know the kind of message you're receiving. If you don't, you could use file_identifier declaration in the schema (in the case where you want to be able to receive unknown/unrelated schemas), or you can put a union in your root table (in the case where all possible message variants are known).


--
Reply all
Reply to author
Forward
0 new messages