How to compare (with equality) two non-root Table/Struct instances of the same type?

257 views
Skip to first unread message

Tiago Cogumbreiro

unread,
Aug 21, 2015, 11:24:18 PM8/21/15
to FlatBuffers
Hello everyone,

I'm evaluating Flatbuffers for C++ and would like to thank you for this great software! I am using the current dev version from the git repo.

I am trying to compare two Records (and eventually two Tables) that are not the root objects, but cannot find any way to do it. I looked into the generated code and in flatbuffers.h.

Is even possible to compare two records? What about two tables? Am I missing something? Can I only compare root objects by strcmp their data?

Thanks,

Tiago

Wouter van Oortmerssen

unread,
Aug 24, 2015, 2:51:24 PM8/24/15
to Tiago Cogumbreiro, FlatBuffers
What do you mean by "record" ?

If by record you mean struct, you should be able to compare them using memcmp() (and sizeof(Type)).

Tables cannot be compared at a binary level, since two tables with the same data may have been stored quite differently, especially if you take into account non-inline data, like strings. So the only way to compare them is on a field by field basis. There's no automatic way to do this at the moment.

It would not be hard to do this generically using either code generation or the reflection functionality.

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

Tiago Cogumbreiro

unread,
Aug 24, 2015, 4:56:24 PM8/24/15
to Wouter van Oortmerssen, FlatBuffers
On Mon, Aug 24, 2015 at 1:51 PM, Wouter van Oortmerssen <w...@google.com> wrote:
What do you mean by "record" ?

If by record you mean struct, you should be able to compare them using memcmp() (and sizeof(Type)).

Sorry about the confusion, I did meant Struct.

Ah, cool. Thanks for the tip. I will submit a feature request then.
 
Tables cannot be compared at a binary level, since two tables with the same data may have been stored quite differently, especially if you take into account non-inline data, like strings. So the only way to compare them is on a field by field basis. There's no automatic way to do this at the moment.

It would not be hard to do this generically using either code generation or the reflection functionality.

Great. I will do a feature request.

Thanks  for the help!

Reply all
Reply to author
Forward
0 new messages