FlatBuffers
Efficient cross-platform serialization library that reads data directly from buffers without parsing or unpacking.
Official Documentation ↗v24. Check the official docs for the latest API surface.Installation
npm install flatbufferspnpm add flatbuffersMethods
No methods match this filter.
Overview
FlatBuffers is an efficient cross-platform serialization library whose readers access fields directly in the buffer without a parsing step. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
new flatbuffers.Builder— Creates a builder that allocates the buffer used to write table and vector offsets.builder.createString— Allocates a string in the buffer and returns the offset to reference it.new flatbuffers.ByteBuffer— Wraps serialized bytes so generated accessors can read fields in place.
Example
const flatbuffers = require('flatbuffers');
const builder = new flatbuffers.Builder(1024);
const name = builder.createString('alice');
builder.finish(name);
const bytes = builder.asUint8Array();
Notes
You must build child offsets before the parent table and finish from the root. Reading requires generated accessors or a schema-aware reader.
Verification
Serialize bytes, wrap them in a ByteBuffer, and confirm the position and a known field value read back correctly.
API reference evidence
Fetched from official sources on 2026-11-08T17:51:00.000Z via WebFetch https://flatbuffers.dev/tutorial/.
new flatbuffers.Builder→ signature from https://flatbuffers.dev/tutorial/; official text: “// Construct a Builder with 1024 byte backing array. let builder = new flatbuffers.Builder(1024);”builder.createString→ signature from https://flatbuffers.dev/tutorial/; official text: “var weaponOne = builder.createString(‘Sword’);”new flatbuffers.ByteBuffer→ signature from https://flatbuffers.dev/languages/typescript/; official text: “import * as flatbuffers from ‘flatbuffers’; import { MyGame } from ‘./monster_generated’; let data = new Uint8Array(fs.readFileSync(‘monster.dat’)); let buf = new flatbuffers.ByteBuffer(data);”
FAQ
- Why is FlatBuffers faster than parsing formats?
- It stores data in a layout the reader can access directly, so there is no parse step and no intermediate object graph.
- How are tables written in JavaScript?
- Build child strings and vectors first, call startObject, push each field with addField helpers, then finishObject and finish.
- Can the buffer be shared across processes?
- Yes. The serialized bytes are a stable layout you can persist or send over the wire, and readers need only the matching schema.
Report a problem with this API docOpens a pre-filled issue on GitHub.