flex buffer or flatBufferBuilder

82 views
Skip to first unread message

Simoncl

unread,
Mar 22, 2018, 12:08:01 AM3/22/18
to FlatBuffers
Hi.

I had a quick question. In the reflection example in Test.cpp you do the following.

// Here we just create a buffer that contains a single string, but this
//could also be any complex set of tables and other values.
flatbuffers::FlatBufferBuilder stringfbb;
stringfbb.Finish(stringfbb.CreateString("hank"));


Why or when would I use 
fbb.Int(13);
fbb.Finish();

If you can just build up a flat buffer like this  with the flatBufferBuilder why would I use the schema less version (flexbuffers)?
Could I not just use flatBufferBuilder without a schema like the above?

Cheers

Simon


mikkelfj

unread,
Mar 22, 2018, 3:16:18 AM3/22/18
to FlatBuffers
That FlatBuffer format does not store information about insertion order or type. It "knows" where to store things based on a schema.
Similar to having knives in the top kitchen drawer and utensils in the second drawer - no need to label the drawers.
You can also use JSON to create an initially loose format and later convert it to a FlatBuffer via a suitable schema for fast read access.

Wouter van Oortmerssen

unread,
Mar 22, 2018, 2:13:14 PM3/22/18
to mikkelfj, FlatBuffers
Yes, FlatBuffers is not self-describing, so you cannot find out from just a buffer what the root is. FlexBuffers contain type information interleaved with the values.

Also, the root of a FlatBuffer has to be a table (to work with schemas and generated code). The example you quote is from a specialized test using reflection to add a string to an existing buffer, and not a general technique.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages