Format:FlatBuffers
| Vendor | |
|---|---|
| Magic | optional 4-char identifier at offset 4 (e.g. TFL3) |
| Endianness | little-endian |
| License | Apache-2.0 |
| Website | https://flatbuffers.dev |
| On this wiki | Facts · Code · Notes · Topics |
Google's schema-based binary serialization: little-endian, starts with a uint32 offset to the root table, optional 4-character file identifier at offset 4, tables addressed through vtables of uint16 offsets.
Layout
All scalars are little-endian and aligned to their own size. Offsets (uoffset_t) are uint32 and point forward. The buffer starts with a uoffset_t to the root table; if the schema declares a file_identifier, exactly 4 bytes of it follow at offset 4 (flatc adds it automatically). A size-prefixed buffer puts a uint32 length first and then the identifier moves to offset 8.
Tables and vtables
A table starts with an soffset_t (int32) to its vtable; the vtable address is table_start minus that value, so the vtable may lie before or after the table. The vtable is an array of uint16 (voffset_t): [0] vtable size in bytes, [1] size of the table object in bytes, then one entry per field slot in schema order, each the offset of the field from the table start, or 0 if absent (default value). Slot i is at vtable byte offset 4 + 2*i. A field id beyond the vtable size means absent. Identical vtables are shared. Field order inside the table is free.
Other kinds
- Struct: fixed layout, inline in parent, no vtable.
- String: uint32 length, bytes, a NUL terminator (not counted).
- Vector: uint32 element count then elements; vectors of tables/strings hold uoffsets relative to each element position.
- Union: two fields, a uint8 type (0 = NONE) and the offset to the value.
Reading a buffer without its schema
- Read u32 at 0 as root offset r; root table at r. 2. Read i32 at r, vtable = r - value. 3. Read vtable size and object size; field count = (vtable size - 4) / 2. 4. For each nonzero slot, the field is at r + slot offset; guess its type: a value that, as uint32, is a small forward offset landing on a plausible length is a string/vector/table. 5. Check offset 4 for a printable identifier to find which schema (e.g. Format:TensorFlow Lite model uses TFL3). Field names are lost; recover them from the schema (.fbs) or the library's generated code, or a binary schema (.bfbs) when shipped.
Tools
flatc compiles .fbs into code, and can dump a binary to JSON with the schema (flatc --json) and generate a .bfbs reflection schema. flatc decodes a buffer to JSON only with its schema: the documented command is flatc --json myschema.fbs -- mydata.bin, and a buffer without a file_identifier also needs --raw-binary (docs/source/flatc.md in google/flatbuffers b8431fbcd7); with no .fbs or .bfbs available use the manual walk above.
Sources
https://github.com/google/flatbuffers docs/source/internals.md (offsets, vtables, strings, unions), docs/source/schema.md (file_identifier exactly 4 characters), include/flatbuffers/buffer.h (BufferHasIdentifier reads after the root offset; size-prefixed buffers skip 2 uoffsets).
Code & repositories
- https://github.com/google/flatbuffers @
b8431fbcd7a5c71817f314e18b332c0648554efa· license: Apache-2.0
FlatBuffers compiler, docs (internals.md) and headers
Tested on: source read, not run: read docs and buffer.h · checked 2026-10-18; last activity 2026-09-14; Note: the latest release ships binaries; the wiki links only the source, never the binaries