Search code examples
flatbuffers

flatBuffers builder does read/write in DOM or does I/O on file


I had some doubt on the way flatBuffers files are written.

We create a builder object and use the apis in the schema generated interface to read /write fields in flatBuffers.

  1. Are we doing this operations directly in file? (i.e. Multiple I/O operations?) Or we are doing this in a temperory DOM created from file.

  2. In case we are doing it in DOM then please explain if there is a way to have a SAX like implementation as my data file is going to be huge.

  3. And if we are doing it directly in file then please explain how can I add an external compress/ decompress to this data file.

An example to show the point where we actually do an I/O with flatBuffers builder will be really helpful.


Solution

    1. Neither. The operations are on an array of bytes in memory.
    2. Terms like DOM and SAX don't really apply. It is a bit like SAX in the sense that it allows you to read the data without constructing objects, but it is also like a DOM in that the way you read it looks like reading an object tree (even though that tree only exists in the array of bytes).
    3. It is in memory. You can optionally compress the array of bytes when you write to file if you wish, but that is not part of the FlatBuffer functionality (it doesn't do any I/O or compression itself).