npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flatbuffers-addon

v1.0.4

Published

Node flatbuffers addon

Downloads

5

Readme

flatbuffers-addon

Generate flatbuffers directly from node.

Generate binary

const flatc = require("flatbuffers-addon");
const buffer = flatc.binary(options);

options.schema

type: String|Buffer

if schema is a String and schema_contents is null or undefined, schema will be treated as schema_contents. otherwise, it will be treated as the schema file path.

options.schema_contents

type: String|Buffer

The schema contents. If the schema_contents is a schema binary, the schema file path must end with .bfbs.

options.schema_binary

type: bool default: false

Serialize schemas instead of JSON

options.json

type: String|Buffer|Object

if json is a String and json_contents is null or undefined, json will be treated as json_contents. if json is a Buffer or an Object, json will be treated as json_contents. otherwise json must be a String and will be treated as the path to the JSON.

options.json_contents

type: String|Buffer|Object

The JSON to serialize

options.include_directories

type: [String]

Include directories for schemas

options.conform

type: String|Buffer

Specify a schema the following schema should be an evolution of.

if conform is a String and conform_contents is null or undefined, conform will be treated as conform_contents.

options.conform_contents

type: String|Buffer

Conform schema contents.

options.conform_include_directories

type: [String]

Include directories for conform schemas

options.strict_json

NOT TESTED

type: bool default: false

field names must be / will be quoted, no trailing commas in tables/vectors.

options.ignore_null_scalar

type: bool default: false

Allow scalar fields to be null

options.allow_non_utf8

NOT TESTED

type: bool default: false

Pass non-UTF-8 input through parser

options.skip_unexpected_fields_in_json

type: bool default: false

Allow fields in JSON that are not defined in the schema. These fields will be discared when generating binaries.

options.size_prefixed

NOT TESTED

type: bool default: false

Input binaries are size prefixed buffers.

options.proto_mode

NOT TESTED

type: bool default: false

Input is a .proto, translate to .fbs.

options.proto_oneof_union

NOT TESTED

type: bool default: false

Translate .proto oneofs to flatbuffer unions.

options.binary_schema_comments

NOT TESTED

type: bool default: false

Add doc comments to the binary schema files.

options.binary_schema_builtins

NOT TESTED

type: bool default: false

Add builtin attributes to the binary schema files.

options.force_defaults

type: bool default: false

If false, don't serialize values equal to the default, therefore reducing size of the binary output.

Generate js

const flatc = require("flatbuffers-addon");
const code = flatc.js(options);

options.schema

type: String|Buffer

if schema is a String and schema_contents is null or undefined, schema will be treated as schema_contents. otherwise, it will be treated as the schema file path.

options.schema_contents

type: String|Buffer

The schema contents. If the schema_contents is a schema binary, the schema file path must end with .bfbs.

options.include_directories

type: [String]

Include directories for schemas

options.conform

type: String|Buffer

Specify a schema the following schema should be an evolution of.

if conform is a String and conform_contents is null or undefined, conform will be treated as conform_contents.

options.conform_contents

type: String|Buffer

Conform schema contents.

options.conform_include_directories

type: [String]

Include directories for conform schemas

options.type

NOT TESTED

type: String

ts to generate TypeScript code.

options.allow_non_utf8

NOT TESTED

type: bool default: false

Pass non-UTF-8 input through parser

options.mutable_buffer

type: bool default: false

Generate accessors that can mutate buffers in-place.

options.generate_all

NOT TESTED

type: bool default: false

Generate not just code for the current schema files, but for all files it includes as well. If the language uses a single file for output (by default the case for C++ and JS), all code will end up in this one file.

options.skip_js_exports

type: bool default: false

Removes Node.js style export lines in JS.

options.use_goog_js_export_format

NOT TESTED

type: bool default: false

Uses goog.exports* for closure compiler exporting in JS.

options.use_ES6_js_export_format

NOT TESTED

type: bool default: false

Uses ECMAScript 6 export style lines in JS.

options.keep_include_path

NOT TESTED

type: bool default: false

Keep original prefix of schema include statement.

options.skip_flatbuffers_import

NOT TESTED

type: bool default: false

Don't include flatbuffers import statement for TypeScript.

options.reexport_ts_modules

NOT TESTED

type: bool default: true

re-export imported dependencies for TypeScript

options.js_ts_short_names

NOT TESTED

type: bool default: true

Use short function names for JS and TypeScript.

Examples

const { flatbuffers } = require("flatbuffers");
const flatc = require("flatbuffers-addon");

const schema = `
    namespace some.nested.namespace;

    file_extension "dat";

    table Book {
        id:string (id: 0);
        title:string (id: 1);
        authors:[string] (id: 2);
        release:ulong (id: 3);
        genres: [ulong] (id: 4);
    }

    table Library {
        name:string (id: 0);
        books: [Book] (id: 1);
    }

    root_type Library;
`;

const js = flatc.js({
    schema
});

const library = {
    name: "BookShop 0",
    books: [{
        id: "book-0",
        title: "Book 0",
        authors: ["Author 0"]
    }]
};


const buffer = flatc.binary({
    schema,
    json: library
});

const deserialized = ((code, binary) => {
    // Evalute generated js code
    const sandbox = {};
    (new Function(code)).call(sandbox);

    // @see https://google.github.io/flatbuffers/flatbuffers_guide_use_javascript.html
    const bytes = new Uint8Array(binary);
    const buf = new flatbuffers.ByteBuffer(bytes);

    // Deserialized flatbuffers binary data
    const Library = sandbox.some.nested.namespace.Library;
    return Library.getRootAsLibrary(buf);

})(js, buffer);

console.log(deserialized.name() === "BookShop 0");
console.log(deserialized.books(0).title() === "Book 0");