how to delete an element from a sequence in the buffer without an temporary container?

34 views
Skip to first unread message

Binshuo Hu

unread,
Apr 16, 2015, 3:54:01 AM4/16/15
to flatb...@googlegroups.com
Suppose I have a schema like this:

struct Person
{
name :string;
age: uint;
}

table Crowd
{
people: [Person];
}


I retrieve a binary sequence from a database and decode it into crowd, and then I want to delete a certain person from the buffer and encode it then store the buffer back to the database. Is the only way to achieve this is to copy the 'people' in the 'Crowd' to an std::vector ( or some other container), delete the person from the container, then encode the container back to a buffer and send it?

I wish there were an interface that can allow me to delete the 'person' in place of the buffer without ever using an temporary container, but I haven't seen any interface in the library like this. Am I doing it the wrong way?

Binshuo Hu

unread,
Apr 16, 2015, 3:56:25 AM4/16/15
to flatb...@googlegroups.com
Or in other word, is there any 'push_back' functionality in the flatbuffers::Vector?

Wouter van Oortmerssen

unread,
Apr 20, 2015, 5:46:46 PM4/20/15
to Binshuo Hu, flatb...@googlegroups.com
Remember that FlatBuffers are single binary buffers, so a "push_back" would be a complicated operation, having to increase the buffer size, move all objects after the insertion point (not just the ones inside the vector), adjust their offsets etc.

So yes, currently FlatBuffers is read-only, you construct entirely new ones when something changes.

We do have plans for being able to "patch" existing flatbuffers for these kinds of use cases, but no promise when that may appear.

--
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.

Reply all
Reply to author
Forward
0 new messages