FlatBuffers

Zero-Copy Access with FlatBuffers

Wouter van Oortmerssen created FlatBuffers at Google in 2014 for games. Each table starts with an offset to a vtable of field offsets, so a reader jumps straight to a field with no parse step and no allocation: in flat_demo.py, Order.GetRootAs(buf) just wraps the bytes and order.TotalCents() reads one value.

flat.sh: building a FlatBuffer and reading it in placeShell
flatc --python --gen-object-api order.fbs      # booknest/Order.py, Item.py, Channel.py
python flat_demo.py                            # build order 1, then read fields in place
Output
144 bytes; read in place: total_cents=4020, items=2, first book=3

Random access costs size: 144 bytes against protobuf 59,573 's 52, as offsets, vtables and padding replace varints. FlatBuffers suits large, read-mostly buffers that are memory-mapped or passed between processes; Apache Arrow 129 uses it for its IPC metadata (Arrow IPC and Feather Files).