evanw / Node Flatbuffers
Licence: other
An implementation of FlatBuffers in pure JavaScript
Stars: ✭ 39
Programming Languages
javascript
184084 projects - #8 most used programming language
FlatBuffers in JavaScript
This is an implementation of FlatBuffers in pure JavaScript. Unlike the official compiler, this implementation generates JavaScript code to convert between JavaScript objects and FlatBuffers at run time using the JIT. It currently requires binary schemas compiled with the flatc
compiler, which is written in C++ and has to be built (see the build instructions).
Example Usage
-
Create a schema called
example.fbs
:table Example { x: float; y: float; } root_type Example;
-
Generate the binary schema called
example.bfbs
:flatc --binary --schema example.fbs
-
Install this library:
npm install flatbuffers
-
Use the library:
var flatbuffers = require('flatbuffers'); var fs = require('fs'); var example = flatbuffers.compileSchema(fs.readFileSync('example.bfbs')); var generated = example.generate({ x: 1, y: 2 }); var parsed = example.parse(generated); console.log('generated:', Array.from(generated)); console.log('parsed:', parsed);
Running that code should print this:
generated: [ 12, 0, 0, 0, 8, 0, 12, 0, 8, 0, 4, 0, 8, 0, 0, 0, 0, 0, 0, 64, 0, 0, 128, 63 ]
parsed: { x: 1, y: 2 }
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].