node-flatbuffers
v0.0.1
Published
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](.github/CONTRIBUTING.md)
Downloads
6
Maintainers
Readme
node-flatbuffers
node-flatbuffers is simple flatbuffers wrapper
Install
npm i node-flatbuffers
Usage example
const fb = require('node-flatbuffers')
const flatbuffers = require('flatbuffers').flatbuffers
const fs = require('fs')
const Game = require('../samples/monster_generated.js').MyGame
const fbs = fs.readFileSync(__dirname + '/../samples/monster.fbs').toString()
const assert = require('assert')
const monster = { name: 'hello', hp: 3, mana: 23 }
const bin = fb.serialize(monster, fbs)
const buf = new flatbuffers.ByteBuffer(new Uint8Array(bin))
const res = Game.Sample.Monster.getRootAsMonster(buf)
assert(monster.name === res.name())
assert(monster.hp === res.hp())
assert(monster.mana === res.mana())