It is fairly simple to do StreamBuffers in flatcc
For FlatBuffers:
when an object is emitted, a reference is returned. This reference is a negative offset from the end of buffer and is computed as the
last emitted negative offset - the new size (incl padding).
The user gets to hold this reference and at the same time the emitted segment as sent to the emitter as the negative offset and
one or more iovec_t buffer pointers that populates the range between the previously emitted data and the new data.
When the reference is stored in another table or a vector, the builder makes a translation pass to convert it from an absolute
negative reference to an offset. This is offset is trivially given as the distance between the two negative references.
The negative references are a purely virtual construct. The emitter uses it to move data into the circular buffer.
There is also support for adding positive references - meaning adding data at the other end of the circular buffer - this is currently only
used for clustering vtables together.
Moving to StreamBuffers would be nearly the same thing, excepting mirrored:
Instead of negative offsets, the offsets would be positive and the emitter would append in the other direction - it already knows how
to do that. vtables would not be clustered because they can't be placed before the start. Tables are constructed on a stack, so when they
are ready to be emitted, it is just a blob send to the emitter, so also no change here.
The main difficulty is probably in handling padding and alignment because computations would be slightly different - and these computations
are very easy to get wrong - but, overall, front to back computations are simpler than the current back to front.
The translation from references to offsets would be unchanged because the subtraction of of two references gives the same result - only
with a different sign due to the order, which is exactly what we want.
There is no material change on order of output - except the detail about vtable clustering, but vtable clustering can already be disabled today
and has to be for nested buffers because the too don't have a logical place to store clustered vtables.
There is also going to be zero difference in performance assuming no runtime decisions are being made between buffer types.
Benchmarks show that FlatCC is very similar to C++ timings for FlatBuffers.